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) + strings = webhook_url.split('/') + project = strings[-1] + fork_name = strings[-2] + + git_repo = "#{project}/#{project}" + return git_repo if check_git_repo(git_repo, webhook_url) + + git_repo = "#{project}/#{fork_name}" + return git_repo if check_git_repo(git_repo, webhook_url) + + git_repo = "#{project[0]}/#{project}/#{project}" + return git_repo if check_git_repo(git_repo, webhook_url) + end + + def handle_webhook + Thread.new do + @webhook_queue.subscribe(block: true) do |_delivery, _properties, webhook_url| + git_repo = get_git_repo(webhook_url) + do_push(git_repo) if git_repo + sleep(0.1) + end + end + end +end
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
how about raise some error message?
Thanks, Ping
- end
- def get_git_repo(webhook_url)
- strings = webhook_url.split('/')
- project = strings[-1]
- fork_name = strings[-2]
- git_repo = "#{project}/#{project}"
- return git_repo if check_git_repo(git_repo, webhook_url)
- git_repo = "#{project}/#{fork_name}"
- return git_repo if check_git_repo(git_repo, webhook_url)
- git_repo = "#{project[0]}/#{project}/#{project}"
- return git_repo if check_git_repo(git_repo, webhook_url)
- end
- def handle_webhook
- Thread.new do
@webhook_queue.subscribe(block: true) do |_delivery, _properties, webhook_url|
git_repo = get_git_repo(webhook_url)
do_push(git_repo) if git_repo
sleep(0.1)
end
- end
- end
+end
2.23.0
On Thu, Nov 05, 2020 at 03:21:42PM +0800, Li Ping 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
how about raise some error message?
ok, but not here.
Thanks, Yuanchao
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?
Thanks, Xueliang
- strings = webhook_url.split('/')
- project = strings[-1]
- fork_name = strings[-2]
- git_repo = "#{project}/#{project}"
- return git_repo if check_git_repo(git_repo, webhook_url)
- git_repo = "#{project}/#{fork_name}"
- return git_repo if check_git_repo(git_repo, webhook_url)
- git_repo = "#{project[0]}/#{project}/#{project}"
- return git_repo if check_git_repo(git_repo, webhook_url)
- end
- def handle_webhook
- Thread.new do
@webhook_queue.subscribe(block: true) do |_delivery, _properties, webhook_url|
git_repo = get_git_repo(webhook_url)
do_push(git_repo) if git_repo
sleep(0.1)
end
- end
- end
+end
2.23.0
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
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.
I don't understand the meaning of this sentence. Could you explain it?
if found, push it to queue. if not found, it maybe an illegal request, do nothing
"if found, push it to queue."
We can keep just this sentence.
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
init_connection or connection_init
Just a proposal. :)
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')
Why use 'web_hook' instead of 'webhook'?
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)
- strings = webhook_url.split('/')
- project = strings[-1]
- fork_name = strings[-2]
- git_repo = "#{project}/#{project}"
- return git_repo if check_git_repo(git_repo, webhook_url)
- git_repo = "#{project}/#{fork_name}"
- return git_repo if check_git_repo(git_repo, webhook_url)
- git_repo = "#{project[0]}/#{project}/#{project}"
- return git_repo if check_git_repo(git_repo, webhook_url)
- end
- def handle_webhook
- Thread.new do
@webhook_queue.subscribe(block: true) do |_delivery, _properties, webhook_url|
git_repo = get_git_repo(webhook_url)
do_push(git_repo) if git_repo
If git_repo is nil, would we still need to sleep?
Thanks, Zhang Yuhang
sleep(0.1)
end
- end
- end
+end
2.23.0
On Thu, Nov 05, 2020 at 03:36:41PM +0800, Zhang Yuhang 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.
I don't understand the meaning of this sentence. Could you explain it?
git_repo is made by parts of url.
For example url: https://gitee.com/theprocess/oec-hardware
the git_repo can be oec-hardware/oec-hardware if it's main line,
or oec-hardware/theprocess if it's a fork,
or o/oec-hardware/oec-hardware
if found, push it to queue. if not found, it maybe an illegal request, do nothing
"if found, push it to queue."
We can keep just this sentence.
The last sentence is just to avoid misunderstanding
Thanks, Yuanchao
On Thu, Nov 05, 2020 at 07:13:23PM +0800, Li Yuanchao wrote:
On Thu, Nov 05, 2020 at 03:36:41PM +0800, Zhang Yuhang 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.
I don't understand the meaning of this sentence. Could you explain it?
git_repo is made by parts of url.
For example url: https://gitee.com/theprocess/oec-hardware
the git_repo can be oec-hardware/oec-hardware if it's main line,
or oec-hardware/theprocess if it's a fork,
or o/oec-hardware/oec-hardware
You can describe clearly in change log.
if found, push it to queue. if not found, it maybe an illegal request, do nothing
"if found, push it to queue."
We can keep just this sentence.
The last sentence is just to avoid misunderstanding
if found do something, if not found do nothing.
The second sentence is meaningless.
Thanks, Zhang Yuhang
Thanks, Yuanchao