On Thu, Nov 05, 2020 at 03:28:40PM +0800, Cao Xueliang wrote:
On Thu, Nov 05, 2020 at 03:08:18PM +0800, Li Yuanchao wrote:
webhook will send a message when user push. try to find the git_repo when get url of the repository. if found, push it to queue. if not found, it maybe an illegal request, do nothing
Signed-off-by: Li Yuanchao lyc163mail@163.com
lib/git_mirror.rb | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+)
diff --git a/lib/git_mirror.rb b/lib/git_mirror.rb index 65d6940..11cf3f1 100644 --- a/lib/git_mirror.rb +++ b/lib/git_mirror.rb @@ -88,10 +88,16 @@ class MirrorMain @git_queue = Queue.new @es_client = Elasticsearch::Client.new(url: "http://#%7BES_HOST%7D:#%7BES_PORT%7D") load_fork_info
connection_init
handle_webhook
end
def connection_init connection = Bunny.new('amqp://172.17.0.1:5672') connection.start channel = connection.create_channel @message_queue = channel.queue('new_refs')
@webhook_queue = channel.queue('web_hook') end
def fork_stat_init(stat_key)
@@ -287,3 +293,35 @@ class MirrorMain es_repo_update(git_repo) end end
+# main thread +class MirrorMain
- def check_git_repo(git_repo, webhook_url)
- return @git_info.key?(git_repo) && Array(@git_info[git_repo]['url'])[0] == webhook_url
- end
- def get_git_repo(webhook_url)
Would you like add some example for the function?
fine. Thanks, Yuanchao