Skip to content

更新 GitLab 事件处理,新增多个事件类型支持并修复错误信息格式 #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/controller/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class HomeController extends Controller {
if (ctx.request.headers['x-gitlab-event']) {
gitlabEvent = ctx.request.headers['x-gitlab-event'];
if (Object.values(X_GITLAB_EVENT).indexOf(gitlabEvent) === -1) {
const errMsg = `====> x-gitlab-event "${gitlabEvent}" is not supported}`;
const errMsg = `====> x-gitlab-event "${gitlabEvent}" is not supported`;
this.logger.error(errMsg);
ctx.body = {
error: errMsg,
Expand Down
6 changes: 6 additions & 0 deletions app/imports/const.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ const EVENT_TYPE = {
const X_GITLAB_EVENT = {
push: 'Push Hook',
system: 'System Hook',
merge_request: 'Merge Request Hook',
tag_push: 'Tag Push Hook',
issue: 'Issue Hook',
note: 'Note Hook',
pipeline: 'Pipeline Hook',
wiki_page: 'Wiki Page Hook'
};

module.exports = { OBJECT_KIND, EVENT_TYPE, X_GITLAB_EVENT };
9 changes: 9 additions & 0 deletions app/service/webhook.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@ class WebhookService extends Service {
? this.pushHookHandler(content, data)
: this.systemHookHandler(content, data);
break;
case X_GITLAB_EVENT.merge_request:
case X_GITLAB_EVENT.tag_push:
case X_GITLAB_EVENT.issue:
case X_GITLAB_EVENT.note:
case X_GITLAB_EVENT.pipeline:
case X_GITLAB_EVENT.wiki_page:
// 所有通过object_kind处理的事件都使用pushHookHandler
this.pushHookHandler(content, data);
break;
default:
// controller make sure not to here
break;
Expand Down