From 501c1296101d57404fcc179089e773d757e65b2c Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 16 Feb 2023 15:37:01 +0800 Subject: [PATCH 1/7] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=97=B6=E5=90=91grimoir?= =?UTF-8?q?elab=E6=8E=A8=E9=80=81=E4=BA=8B=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/issues_controller.rb | 2 + app/jobs/issue_webhook_job.rb | 181 +++++++++++++++++++++++++++ 2 files changed, 183 insertions(+) create mode 100644 app/jobs/issue_webhook_job.rb diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index ddb0facdf..efc7d3ea4 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -154,6 +154,8 @@ class IssuesController < ApplicationController Rails.logger.info "[ATME] maybe to at such users: #{@atme_receivers.pluck(:login)}" AtmeService.call(current_user, @atme_receivers, @issue) if @atme_receivers.size > 0 + # 新增时向grimoirelab推送事件 + IssueWebhookJob.set(wait: 5.seconds).perform_later(@issue.id) render json: {status: 0, message: "创建成功", id: @issue.id} else diff --git a/app/jobs/issue_webhook_job.rb b/app/jobs/issue_webhook_job.rb new file mode 100644 index 000000000..b85c7c1e0 --- /dev/null +++ b/app/jobs/issue_webhook_job.rb @@ -0,0 +1,181 @@ +class IssueWebhookJob < ApplicationJob + include ApplicationHelper + queue_as :message + + def perform(issue_id, user_id) + issue = Issue.find_by(id: issue_id) + return if issue.blank? + project = issue.project + user = issue.user + domain = "#{Rails.application.config_for(:configuration)['platform_url']}" + gitea_domain = GiteaService.gitea_config[:domain] + ssh_url = "git@#{gitea_domain.gsub("https://","")}:#{project.owner.login}/#{project.identifier}.git" + event_json = { + "action": "opened", + "number": 1, + "issue": { + "id": 888, + "url": "#{domain}/api/v1/#{project.owner.login}/#{project.identifier}/issues/#{issue.id}", + "html_url": "#{domain}/#{project.owner.login}/#{project.identifier}/issues/#{issue.id}", + "number": 1, + "user": { + "id": user.id, + "login": "#{user.login}", + "full_name": "", + "email": "#{user.mail}", + "avatar_url": "#{domain}/#{url_to_avatar(user)}", + "language": "", + "is_admin": false, + "last_login": "#{user.last_login_on}", + "created": "#{user.created_on}", + "restricted": false, + "active": false, + "prohibit_login": false, + "location": "", + "website": "", + "description": "", + "visibility": "public", + "followers_count": 0, + "following_count": 0, + "starred_repos_count": 0, + "username": "#{user.login}" + }, + "original_author": "", + "original_author_id": 0, + "title": "#{issue.subject}", + "body": "#{issue.description}", + "ref": "", + "labels": [], + "milestone": null, + "assignee": null, + "assignees": null, + "state": "open", + "is_locked": false, + "comments": 0, + "created_at": "#{issue.created_on}", + "updated_at": "#{issue.updated_on}", + "closed_at": null, + "due_date": null, + "pull_request": null, + "repository": { + "id": 11307, + "name": "#{project.identifier}", + "owner": "#{project.owner.login}", + "full_name": "#{project.owner.login}/#{project.identifier}" + } + }, + "repository": { + "id": project.id, + "owner": { + "id": project.owner.id, + "login": "#{project.owner.login}", + "full_name": "", + "email": "#{project.owner.mail}", + "avatar_url": "#{domain}/#{url_to_avatar(project.owner)}", + "language": "", + "is_admin": false, + "last_login": "#{project.owner.last_login_on}", + "created": "#{project.owner.created_on}", + "restricted": false, + "active": false, + "prohibit_login": false, + "location": "", + "website": "", + "description": "", + "visibility": "public", + "followers_count": 0, + "following_count": 0, + "starred_repos_count": 0, + "username": "#{project.owner.login}" + }, + "name": "#{project.identifier}", + "full_name": "#{project.owner.login}/#{project.identifier}", + "description": "", + "empty": false, + "private": false, + "fork": false, + "template": false, + "parent": null, + "mirror": false, + "size": 843, + "html_url": "#{domain}/#{project.owner.login}/#{project.identifier}", + "ssh_url": "#{ssh_url}", + "clone_url": "#{domain}/#{project.owner.login}/#{project.identifier}.git", + "original_url": "#{project.repository.mirror_url}", + "website": "", + "stars_count": 0, + "forks_count": 0, + "watchers_count": 1, + "open_issues_count": 1, + "open_pr_counter": 0, + "release_counter": 0, + "default_branch": "master", + "archived": false, + "created_at": "#{project.created_on}", + "updated_at": "#{project.updated_on}", + "permissions": { + "admin": true, + "push": true, + "pull": true + }, + "has_issues": true, + "internal_tracker": { + "enable_time_tracker": true, + "allow_only_contributors_to_track_time": true, + "enable_issue_dependencies": true + }, + "has_wiki": true, + "has_pull_requests": true, + "has_projects": false, + "ignore_whitespace_conflicts": false, + "allow_merge_commits": true, + "allow_rebase": true, + "allow_rebase_explicit": true, + "allow_squash_merge": true, + "default_merge_style": "merge", + "avatar_url": "", + "internal": false, + "mirror_interval": "" + }, + "sender": { + "id": user.id, + "login": "#{user.login}", + "full_name": "", + "email": "#{user.mail}", + "avatar_url": "#{domain}/#{url_to_avatar(user)}", + "language": "", + "is_admin": false, + "last_login": "#{user.last_login_on}", + "created": "#{user.created_on}", + "restricted": false, + "active": false, + "prohibit_login": false, + "location": "", + "website": "", + "description": "", + "visibility": "public", + "followers_count": 0, + "following_count": 0, + "starred_repos_count": 0, + "username": "#{user.login}" + } + } + + url = URI("http://117.50.185.50:80") + http = Net::HTTP.new(url.host, url.port) + request = Net::HTTP::Post.new(url) + request["Content-Type"] = "application/json" + uuid = SecureRandom.uuid + request['X-GitHub-Delivery'] = uuid + request['X-Gitea-Delivery'] = uuid + request['X-Gogs-Delivery'] = uuid + request['X-GitHub-Event'] = 'issues' + request['X-Gitea-Event'] = 'issues' + request['X-Gogs-Event'] = 'issues' + request.body = JSON.dump(event_json) + + response = http.request(request) + Rails.logger.info "issue webhook event======#{response.read_body}" + end + +end \ No newline at end of file From e03694021662edf7f30305d0893c9169666ceb35 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 16 Feb 2023 15:41:20 +0800 Subject: [PATCH 2/7] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=97=B6=E5=90=91grimoir?= =?UTF-8?q?elab=E6=8E=A8=E9=80=81=E4=BA=8B=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/issues_controller.rb | 2 +- app/jobs/{issue_webhook_job.rb => issue_web_hook_job.rb} | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename app/jobs/{issue_webhook_job.rb => issue_web_hook_job.rb} (99%) diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index efc7d3ea4..76aef3dc6 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -155,7 +155,7 @@ class IssuesController < ApplicationController Rails.logger.info "[ATME] maybe to at such users: #{@atme_receivers.pluck(:login)}" AtmeService.call(current_user, @atme_receivers, @issue) if @atme_receivers.size > 0 # 新增时向grimoirelab推送事件 - IssueWebhookJob.set(wait: 5.seconds).perform_later(@issue.id) + IssueWebHookJob.set(wait: 5.seconds).perform_later(@issue.id) render json: {status: 0, message: "创建成功", id: @issue.id} else diff --git a/app/jobs/issue_webhook_job.rb b/app/jobs/issue_web_hook_job.rb similarity index 99% rename from app/jobs/issue_webhook_job.rb rename to app/jobs/issue_web_hook_job.rb index b85c7c1e0..97501675f 100644 --- a/app/jobs/issue_webhook_job.rb +++ b/app/jobs/issue_web_hook_job.rb @@ -1,4 +1,4 @@ -class IssueWebhookJob < ApplicationJob +class IssueWebHookJob < ApplicationJob include ApplicationHelper queue_as :message From 578423942558aa9b1d380aa92c337b8877a2f9c3 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 16 Feb 2023 15:42:15 +0800 Subject: [PATCH 3/7] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=97=B6=E5=90=91grimoir?= =?UTF-8?q?elab=E6=8E=A8=E9=80=81=E4=BA=8B=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/issues_controller.rb | 2 +- app/jobs/{issue_web_hook_job.rb => issue_webhook_job.rb} | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename app/jobs/{issue_web_hook_job.rb => issue_webhook_job.rb} (99%) diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index 76aef3dc6..efc7d3ea4 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -155,7 +155,7 @@ class IssuesController < ApplicationController Rails.logger.info "[ATME] maybe to at such users: #{@atme_receivers.pluck(:login)}" AtmeService.call(current_user, @atme_receivers, @issue) if @atme_receivers.size > 0 # 新增时向grimoirelab推送事件 - IssueWebHookJob.set(wait: 5.seconds).perform_later(@issue.id) + IssueWebhookJob.set(wait: 5.seconds).perform_later(@issue.id) render json: {status: 0, message: "创建成功", id: @issue.id} else diff --git a/app/jobs/issue_web_hook_job.rb b/app/jobs/issue_webhook_job.rb similarity index 99% rename from app/jobs/issue_web_hook_job.rb rename to app/jobs/issue_webhook_job.rb index 97501675f..b85c7c1e0 100644 --- a/app/jobs/issue_web_hook_job.rb +++ b/app/jobs/issue_webhook_job.rb @@ -1,4 +1,4 @@ -class IssueWebHookJob < ApplicationJob +class IssueWebhookJob < ApplicationJob include ApplicationHelper queue_as :message From 382d8c430cb793d1c46b35dfacbff4698bd7f93c Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 16 Feb 2023 15:44:42 +0800 Subject: [PATCH 4/7] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=97=B6=E5=90=91grimoir?= =?UTF-8?q?elab=E6=8E=A8=E9=80=81=E4=BA=8B=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/jobs/issue_webhook_job.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/jobs/issue_webhook_job.rb b/app/jobs/issue_webhook_job.rb index b85c7c1e0..375688663 100644 --- a/app/jobs/issue_webhook_job.rb +++ b/app/jobs/issue_webhook_job.rb @@ -2,7 +2,7 @@ class IssueWebhookJob < ApplicationJob include ApplicationHelper queue_as :message - def perform(issue_id, user_id) + def perform(issue_id) issue = Issue.find_by(id: issue_id) return if issue.blank? project = issue.project From 48fe09345e3b6d774816bb9bea34da18f892a878 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 16 Feb 2023 15:46:15 +0800 Subject: [PATCH 5/7] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=97=B6=E5=90=91grimoir?= =?UTF-8?q?elab=E6=8E=A8=E9=80=81=E4=BA=8B=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/jobs/issue_webhook_job.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/app/jobs/issue_webhook_job.rb b/app/jobs/issue_webhook_job.rb index 375688663..23a4f978a 100644 --- a/app/jobs/issue_webhook_job.rb +++ b/app/jobs/issue_webhook_job.rb @@ -46,17 +46,17 @@ class IssueWebhookJob < ApplicationJob "body": "#{issue.description}", "ref": "", "labels": [], - "milestone": null, - "assignee": null, - "assignees": null, + "milestone": nil, + "assignee": nil, + "assignees": nil, "state": "open", "is_locked": false, "comments": 0, "created_at": "#{issue.created_on}", "updated_at": "#{issue.updated_on}", - "closed_at": null, - "due_date": null, - "pull_request": null, + "closed_at": nil, + "due_date": nil, + "pull_request": nil, "repository": { "id": 11307, "name": "#{project.identifier}", @@ -95,7 +95,7 @@ class IssueWebhookJob < ApplicationJob "private": false, "fork": false, "template": false, - "parent": null, + "parent": nil, "mirror": false, "size": 843, "html_url": "#{domain}/#{project.owner.login}/#{project.identifier}", From e907cae4dc61486e67a29935a9dcde1db43d1474 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 16 Feb 2023 15:51:06 +0800 Subject: [PATCH 6/7] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=97=B6=E5=90=91grimoir?= =?UTF-8?q?elab=E6=8E=A8=E9=80=81=E4=BA=8B=E4=BB=B6,=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/jobs/issue_webhook_job.rb | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/app/jobs/issue_webhook_job.rb b/app/jobs/issue_webhook_job.rb index 23a4f978a..34dcdffaa 100644 --- a/app/jobs/issue_webhook_job.rb +++ b/app/jobs/issue_webhook_job.rb @@ -9,7 +9,7 @@ class IssueWebhookJob < ApplicationJob user = issue.user domain = "#{Rails.application.config_for(:configuration)['platform_url']}" gitea_domain = GiteaService.gitea_config[:domain] - ssh_url = "git@#{gitea_domain.gsub("https://","")}:#{project.owner.login}/#{project.identifier}.git" + ssh_url = "git@#{gitea_domain.gsub("https://", "")}:#{project.owner.login}/#{project.identifier}.git" event_json = { "action": "opened", "number": 1, @@ -161,21 +161,26 @@ class IssueWebhookJob < ApplicationJob } } - url = URI("http://117.50.185.50:80") - http = Net::HTTP.new(url.host, url.port) - request = Net::HTTP::Post.new(url) - request["Content-Type"] = "application/json" - uuid = SecureRandom.uuid - request['X-GitHub-Delivery'] = uuid - request['X-Gitea-Delivery'] = uuid - request['X-Gogs-Delivery'] = uuid - request['X-GitHub-Event'] = 'issues' - request['X-Gitea-Event'] = 'issues' - request['X-Gogs-Event'] = 'issues' - request.body = JSON.dump(event_json) + begin + url = URI("http://117.50.185.50:80") + http = Net::HTTP.new(url.host, url.port) + request = Net::HTTP::Post.new(url) + request["Content-Type"] = "application/json" + uuid = SecureRandom.uuid + request['X-GitHub-Delivery'] = uuid + request['X-Gitea-Delivery'] = uuid + request['X-Gogs-Delivery'] = uuid + request['X-GitHub-Event'] = 'issues' + request['X-Gitea-Event'] = 'issues' + request['X-Gogs-Event'] = 'issues' + request.body = JSON.dump(event_json) - response = http.request(request) - Rails.logger.info "issue webhook event======#{response.read_body}" + response = http.request(request) + Rails.logger.info "issue webhook event======#{response.read_body}" + rescue Exception => e + Rails.logger.info "issue webhook event error======#{e.message}" + puts "issue webhook event error======#{e.message}" + end end end \ No newline at end of file From abef11f71c2c807644317df514f970e9cf746511 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 16 Feb 2023 15:54:43 +0800 Subject: [PATCH 7/7] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=97=B6=E5=90=91grimoir?= =?UTF-8?q?elab=E6=8E=A8=E9=80=81=E4=BA=8B=E4=BB=B6,=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/jobs/issue_webhook_job.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/jobs/issue_webhook_job.rb b/app/jobs/issue_webhook_job.rb index 34dcdffaa..445a0b02c 100644 --- a/app/jobs/issue_webhook_job.rb +++ b/app/jobs/issue_webhook_job.rb @@ -176,10 +176,10 @@ class IssueWebhookJob < ApplicationJob request.body = JSON.dump(event_json) response = http.request(request) - Rails.logger.info "issue webhook event======#{response.read_body}" + Rails.logger.info "issue #{issue_id} webhook event======#{response.read_body}" rescue Exception => e - Rails.logger.info "issue webhook event error======#{e.message}" - puts "issue webhook event error======#{e.message}" + Rails.logger.info "issue #{issue_id} webhook event error======#{e.message}" + puts "issue: #{issue_id} webhook event error======#{e.message}" end end