Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit 492ff10

Browse files
committed
Gitlab support
1 parent 3115a24 commit 492ff10

10 files changed

+256
-112
lines changed

README.md

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ set GITLAB_SECRET_TOKEN=...
7575
- go to the repository you want to watch
7676
- click: Settings -> Options(in the left panel) -> Webhooks
7777
- click: 'Add Webhook' button
78-
- fill the form:
78+
- fill the form:
7979
- Payload URL: `https://<YOUR_HOST>/webhooks/github`,
8080
for example: `https://4bb6c860.ngrok.io/webhooks/github`
8181
- Content Type: application/json
@@ -111,7 +111,6 @@ use `ngrok` to make your local deploy accessible by internet:
111111
ngrok http 3000
112112
```
113113

114-
115114
## GitHub Verification
116115

117116
- properly config and run the `receiver` app.
@@ -121,16 +120,22 @@ ngrok http 3000
121120
- create a comment on an issue, you can see the logs in `receiver` and `processor`, the `comment.created` event is generated.
122121
- update a comment on an issue, you can see the logs in `receiver` and `processor`, the `comment.updated` event is generated.
123122
- assigned a user to an issue, you can see the logs in `receiver` and `processor`, the `issue.assigned` event is generated.
124-
- assigned a user to an issue, you can see the logs in `receiver` and `processor`, the `issue.unassigned` event is generated.
125-
- add a label to an issue, you can see the logs in `receiver` and `processor`, the `issue.labeled` event is generated.
126-
- remove a label to an issue, you can see the logs in `receiver` and `processor`, the `issue.unlabeled` event is generated.
123+
- un-assigned a user to an issue, you can see the logs in `receiver` and `processor`, the `issue.unassigned` event is generated.
124+
- add/remove a label to an issue, you can see the logs in `receiver` and `processor`, the `issue.labelUpdated` event is generated.
127125
- create a pull request, you can see the logs in `receiver` and `processor`, the `pull_request.created` event is generated.
128126
- close a pull request without merge, you can see the logs in `receiver` and `processor`, the `pull_request.closed` event is generated and the `merged` property is `false`.
129127
- merge a pull request, you can see the logs in `receiver` and `processor`, the `pull_request.closed` event is generated and the `merged` property is `true`.
130128

131129
## Gitlab Verification
130+
132131
- properly config and run the `receiver` app.
133132
- properly config and run the `processor` app.
134133
- create an issue in the repo, you can see the logs in `receiver` and `processor`, the `issue.created` event is generated.
135-
136-
134+
- update an issue in the repo, you can see the logs in `receiver` and `processor`, the `issue.updated` event is generated.
135+
- create a comment on an issue, you can see the logs in `receiver` and `processor`, the `comment.created` event is generated.
136+
- assigned a user to an issue, you can see the logs in `receiver` and `processor`, the `issue.assigned` event is generated.
137+
- un-assigned a user to an issue, you can see the logs in `receiver` and `processor`, the `issue.unassigned` event is generated.
138+
- add/remove a label to an issue, you can see the logs in `receiver` and `processor`, the `issue.labelUpdated` event is generated.
139+
- create a pull request, you can see the logs in `receiver` and `processor`, the `pull_request.created` event is generated.
140+
- close a pull request without merge, you can see the logs in `receiver` and `processor`, the `pull_request.closed` event is generated and the `merged` property is `false`.
141+
- merge a pull request, you can see the logs in `receiver` and `processor`, the `pull_request.closed` event is generated and the `merged` property is `true`.

models/CommentCreatedEvent.js

100644100755
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ CommentCreatedEvent.schema = Joi.object().keys({
2121
id: Joi.number().required(),
2222
body: Joi.string().allow(''),
2323
user: Joi.object().keys({
24-
id: Joi.number().required(),
25-
name: Joi.string().required()
24+
id: Joi.number().required()
2625
}).required()
2726
}),
2827
repository: repositorySchema.required()

models/CommentUpdatedEvent.js

100644100755
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ CommentUpdatedEvent.schema = Joi.object().keys({
2121
id: Joi.number().required(),
2222
body: Joi.string().allow(''),
2323
user: Joi.object().keys({
24-
id: Joi.number().required(),
25-
name: Joi.string().required()
24+
id: Joi.number().required()
2625
}).required()
2726
}),
2827
repository: repositorySchema.required()

models/LabelUpdatedEvent.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright (c) 2018 TopCoder, Inc. All rights reserved.
3+
*/
4+
/**
5+
* This module contains the schema of the LabelUpdatedEvent.
6+
*
7+
* @author TCSCODER
8+
* @version 1.0
9+
*/
10+
'use strict';
11+
const Joi = require('joi');
12+
const {issueSchema, repositorySchema} = require('./common');
13+
14+
const LabelUpdatedEvent = {
15+
name: 'issue.labelUpdated'
16+
};
17+
18+
LabelUpdatedEvent.schema = Joi.object().keys({
19+
issue: issueSchema.required(),
20+
repository: repositorySchema.required(),
21+
labels: Joi.array().items(Joi.string()).required()
22+
});
23+
24+
module.exports = LabelUpdatedEvent;

models/UserAssignedEvent.js

100644100755
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ UserAssignedEvent.schema = Joi.object().keys({
1919
issue: issueSchema.required(),
2020
repository: repositorySchema.required(),
2121
assignee: Joi.object().keys({
22-
id: Joi.number().required(),
23-
name: Joi.string().required()
22+
id: Joi.number().required()
2423
}).required()
2524
});
2625

models/UserUnassignedEvent.js

100644100755
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,7 @@ const UserUnassignedEvent = {
1717

1818
UserUnassignedEvent.schema = Joi.object().keys({
1919
issue: issueSchema.required(),
20-
repository: repositorySchema.required(),
21-
assignee: Joi.object().keys({
22-
id: Joi.number().required(),
23-
name: Joi.string().required()
24-
}).required()
20+
repository: repositorySchema.required()
2521
});
2622

2723
module.exports = UserUnassignedEvent;

models/common.js

100644100755
Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,10 @@ const issueSchema = Joi.object().keys({
2828
body: Joi.string().allow(''),
2929
labels: Joi.array().items(Joi.string()),
3030
assignees: Joi.array().items(Joi.object().keys({
31-
id: Joi.number().required(),
32-
name: Joi.string().required()
31+
id: Joi.number().required()
3332
})),
3433
owner: Joi.object().keys({
35-
id: Joi.number().required(),
36-
name: Joi.string().required()
34+
id: Joi.number().required()
3735
}).required()
3836
});
3937

@@ -45,12 +43,10 @@ const pullRequestSchema = Joi.object().keys({
4543
body: Joi.string().allow(''),
4644
title: Joi.string().required(),
4745
user: Joi.object().keys({
48-
id: Joi.number().required(),
49-
name: Joi.string().required()
46+
id: Joi.number().required()
5047
}),
5148
assignees: Joi.array().items({
52-
id: Joi.number().required(),
53-
name: Joi.string().required()
49+
id: Joi.number().required()
5450
})
5551
});
5652

models/index.js

100644100755
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@ const CommentCreatedEvent = require('./CommentCreatedEvent');
1616
const CommentUpdatedEvent = require('./CommentUpdatedEvent');
1717
const UserAssignedEvent = require('./UserAssignedEvent');
1818
const UserUnassignedEvent = require('./UserUnassignedEvent');
19-
const LabelAssignedEvent = require('./LabelAssignedEvent');
20-
const LabelUnassignedEvent = require('./LabelUnassignedEvent');
2119
const PullRequestCreatedEvent = require('./PullRequestCreatedEvent');
2220
const PullRequestClosedEvent = require('./PullRequestClosedEvent');
21+
const LabelUpdatedEvent = require('./LabelUpdatedEvent');
2322

2423
module.exports = {
2524
IssueCreatedEvent,
@@ -28,8 +27,7 @@ module.exports = {
2827
CommentUpdatedEvent,
2928
UserAssignedEvent,
3029
UserUnassignedEvent,
31-
LabelAssignedEvent,
32-
LabelUnassignedEvent,
3330
PullRequestCreatedEvent,
34-
PullRequestClosedEvent
31+
PullRequestClosedEvent,
32+
LabelUpdatedEvent
3533
};

utils/GithubEventDetector.js

100644100755
Lines changed: 22 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,10 @@ const parseIssue = (issue) => ({
2323
title: issue.title,
2424
labels: _.map(issue.labels, 'name'),
2525
assignees: _.map(issue.assignees, (assignee) => ({
26-
id: assignee.id,
27-
name: assignee.login
26+
id: assignee.id
2827
})),
2928
owner: {
30-
id: issue.user.id,
31-
name: issue.user.login
29+
id: issue.user.id
3230
}
3331
});
3432

@@ -45,12 +43,10 @@ const parsePullRequest = (data) => ({
4543
body: data.pull_request.body,
4644
title: data.pull_request.title,
4745
user: {
48-
id: data.pull_request.user.id,
49-
name: data.pull_request.user.login
46+
id: data.pull_request.user.id
5047
},
5148
assignees: _.map(data.pull_request.assignees, (a) => ({
52-
id: a.id,
53-
name: a.login
49+
id: a.id
5450
}))
5551
});
5652

@@ -97,8 +93,7 @@ const parseComment = (data) => ({
9793
id: data.comment.id,
9894
body: data.comment.body,
9995
user: {
100-
id: data.comment.user.id,
101-
name: data.comment.user.login
96+
id: data.comment.user.id
10297
}
10398
}
10499
});
@@ -149,8 +144,7 @@ UserAssignedEvent.parse = (data) => ({
149144
issue: parseIssue(data.issue),
150145
repository: parseRepository(data.repository),
151146
assignee: {
152-
id: data.assignee.id,
153-
name: data.assignee.login
147+
id: data.assignee.id
154148
}
155149
});
156150

@@ -170,52 +164,27 @@ UserUnassignedEvent.schema = Joi.object().keys({
170164

171165
UserUnassignedEvent.parse = (data) => ({
172166
issue: parseIssue(data.issue),
173-
repository: parseRepository(data.repository),
174-
assignee: {
175-
id: data.assignee.id,
176-
name: data.assignee.login
177-
}
167+
repository: parseRepository(data.repository)
178168
});
179169

180170
// end the UserUnassignedEvent
181171

182-
// begin the LabelAssignedEvent
183-
const LabelAssignedEvent = {
184-
event: models.LabelAssignedEvent
185-
};
186-
187-
LabelAssignedEvent.schema = Joi.object().keys({
188-
action: Joi.string().valid('labeled').required(),
189-
issue: Joi.object().required(),
190-
label: Joi.object().required(),
191-
repository: Joi.object().required()
192-
});
193-
194-
LabelAssignedEvent.parse = (data) => ({
195-
issue: parseIssue(data.issue),
196-
repository: parseRepository(data.repository),
197-
label: data.label.name
198-
});
199-
// end the LabelAssignedEvent
200-
201-
// begin the LabelUnassignedEvent
202-
const LabelUnassignedEvent = {
203-
event: models.LabelUnassignedEvent
172+
// start of LabelUpdatedEvent
173+
const LabelUpdatedEvent = {
174+
event: models.LabelUpdatedEvent,
175+
schema: Joi.object().keys({
176+
action: Joi.string().valid('unlabeled', 'labeled').required(),
177+
issue: Joi.object().required(),
178+
label: Joi.object().required(),
179+
repository: Joi.object().required()
180+
}),
181+
parse: (data) => ({
182+
issue: parseIssue(data.issue),
183+
repository: parseRepository(data.repository),
184+
labels: _.map(data.issue.labels, 'name')
185+
})
204186
};
205187

206-
LabelUnassignedEvent.schema = Joi.object().keys({
207-
action: Joi.string().valid('unlabeled').required(),
208-
issue: Joi.object().required(),
209-
label: Joi.object().required(),
210-
repository: Joi.object().required()
211-
});
212-
213-
LabelUnassignedEvent.parse = (data) => ({
214-
issue: parseIssue(data.issue),
215-
repository: parseRepository(data.repository),
216-
label: data.label.name
217-
});
218-
219188
// end the LabelUnassignedEvent
220189

221190
// begin the PullRequestCreatedEvent
@@ -259,8 +228,7 @@ module.exports = new EventDetector('github', [
259228
CommentUpdatedEvent,
260229
UserAssignedEvent,
261230
UserUnassignedEvent,
262-
LabelAssignedEvent,
263-
LabelUnassignedEvent,
231+
LabelUpdatedEvent,
264232
PullRequestCreatedEvent,
265233
PullRequestClosedEvent
266234
]);

0 commit comments

Comments
 (0)