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

Commit 5f926f0

Browse files
authored
Merge pull request #19 from afrisalyp/develop
Azure. Handle issue updated, unassigned, commented. Cleanup.
2 parents 343f407 + d409a7c commit 5f926f0

File tree

2 files changed

+47
-83
lines changed

2 files changed

+47
-83
lines changed

models/CommentCreatedEvent.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +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()
24+
id: Joi.alternatives().try(Joi.string(), Joi.number()).required()
2525
}).required()
2626
}),
2727
repository: repositorySchema.required()

utils/AzureEventDetector.js

Lines changed: 46 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*/
44

55
/**
6-
* This module contains the EventDetector for gitlab.
6+
* This module contains the EventDetector for azure.
77
*
88
* @author TCSCODER
99
* @version 1.0
@@ -17,8 +17,8 @@ const models = require('../models');
1717
const EventDetector = require('./EventDetector');
1818

1919
/**
20-
* parse the issues from gitlab webhook
21-
* @param {object} data the gitlab webhook payload
20+
* parse the issues from azure webhook
21+
* @param {object} data the azure webhook payload
2222
* @returns {object} the parsed issue detail
2323
*/
2424
const parseIssue = (data) => {
@@ -36,8 +36,8 @@ const parseIssue = (data) => {
3636
};
3737

3838
/**
39-
* parse the project from gitlab webhook project payload
40-
* @param {object} data the gitlab project payload
39+
* parse the project from azure webhook project payload
40+
* @param {object} data the azure project payload
4141
* @returns {object} the parsed project detail
4242
*/
4343
const parseProject = (data) => {
@@ -56,51 +56,32 @@ const parseProject = (data) => {
5656
};
5757

5858
/**
59-
* parse the comments from gitlab webhook payload
60-
* @param {object} data the gitlab webhook payload
59+
* parse the comments from azure webhook payload
60+
* @param {object} data the azure webhook payload
6161
* @returns {object} the parsed comment detail
6262
*/
6363
const parseComment = (data) => ({
64-
issue: parseIssue(data, data.issue),
65-
repository: parseProject(data.project),
64+
issue: parseIssue(data),
65+
repository: parseProject(data),
6666
comment: {
67-
id: data.object_attributes.id,
68-
body: data.object_attributes.note,
67+
id: data.resource.revision.commentVersionRef.commentId,
68+
body: data.resource.revision.fields['System.History'],
6969
user: {
70-
id: data.object_attributes.author_id
70+
id: data.resource.revisedBy.id
7171
}
7272
}
7373
});
7474

7575
/**
76-
* parse the issue event from gitlab webhook payload
77-
* @param {object} data the gitlab webhook payload
76+
* parse the issue event from azure webhook payload
77+
* @param {object} data the azure webhook payload
7878
* @returns {object} the parsed issue event detail
7979
*/
8080
const parseIssueEventData = (data) => ({
8181
issue: parseIssue(data),
8282
repository: parseProject(data)
8383
});
8484

85-
/**
86-
* parse the pull request from gitlab webhook payload
87-
* @param {object} data the gitlab webhook payload
88-
* @returns {object} the parsed pull request detail
89-
*/
90-
const parsePullRequest = (data) => ({
91-
number: data.object_attributes.iid,
92-
id: data.object_attributes.id,
93-
merged: data.object_attributes.state === 'merged',
94-
body: data.object_attributes.description,
95-
title: data.object_attributes.title,
96-
user: {
97-
id: data.object_attributes.author_id
98-
},
99-
assignees: data.object_attributes.assignee_id ? [{
100-
id: data.object_attributes.assignee_id
101-
}] : []
102-
});
103-
10485
// definition of issue created event
10586
const IssueCreatedEvent = {
10687
event: models.IssueCreatedEvent,
@@ -114,15 +95,29 @@ const IssueCreatedEvent = {
11495
const IssueUpdatedEvent = {
11596
event: models.IssueUpdatedEvent,
11697
schema: Joi.object().keys({
117-
object_kind: Joi.string().valid('issue').required(),
118-
object_attributes: Joi.object().keys({
119-
state: Joi.string().valid('opened').required(),
120-
action: Joi.string().valid('update').required()
121-
}).required(),
122-
changes: Joi.object().keys({
123-
assignees: Joi.any().forbidden()
124-
}),
125-
project: Joi.object().required()
98+
eventType: Joi.string().valid('workitem.updated').required(),
99+
resource: Joi.object().keys({
100+
fields: Joi.object().keys({
101+
'System.Title': Joi.object().keys({
102+
newValue: Joi.string().required()
103+
}).required()
104+
}).required()
105+
}).required()
106+
}),
107+
parse: parseIssueEventData
108+
};
109+
110+
const IssueDescriptionUpdatedEvent = {
111+
event: models.IssueUpdatedEvent,
112+
schema: Joi.object().keys({
113+
eventType: Joi.string().valid('workitem.updated').required(),
114+
resource: Joi.object().keys({
115+
fields: Joi.object().keys({
116+
'System.Description': Joi.object().keys({
117+
newValue: Joi.string().required()
118+
}).required()
119+
}).required()
120+
}).required()
126121
}),
127122
parse: parseIssueEventData
128123
};
@@ -154,11 +149,13 @@ const IssueClosedEvent = {
154149
const CommentCreatedEvent = {
155150
event: models.CommentCreatedEvent,
156151
schema: Joi.object().keys({
157-
object_kind: Joi.string().valid('note').required(),
158-
project: Joi.object().required(),
159-
object_attributes: Joi.object().keys({
160-
note: Joi.string().required(),
161-
noteable_type: Joi.string().valid('Issue').required()
152+
eventType: Joi.string().valid('workitem.updated').required(),
153+
resource: Joi.object().keys({
154+
fields: Joi.object().keys({
155+
'System.History': Joi.object().keys({
156+
newValue: Joi.string().required()
157+
}).required()
158+
}).required()
162159
}).required()
163160
}),
164161
parse: parseComment
@@ -225,46 +222,13 @@ const LabelUpdatedEvent = {
225222
})
226223
};
227224

228-
// definition of pull request created event
229-
const PullRequestCreatedEvent = {
230-
event: models.PullRequestCreatedEvent,
231-
schema: Joi.object().keys({
232-
object_kind: Joi.string().valid('merge_request').required(),
233-
object_attributes: Joi.object().keys({
234-
action: Joi.string().valid('open').required()
235-
}).required(),
236-
project: Joi.object().required()
237-
}),
238-
parse: (data) => ({
239-
pull_request: parsePullRequest(data),
240-
repository: parseProject(data.project)
241-
})
242-
};
243-
244-
// definition of pull request closed event
245-
const PullRequestClosedEvent = {
246-
event: models.PullRequestClosedEvent,
247-
schema: Joi.object().keys({
248-
object_kind: Joi.string().valid('merge_request').required(),
249-
object_attributes: Joi.object().keys({
250-
action: Joi.string().valid('close', 'merge').required()
251-
}).required(),
252-
project: Joi.object().required()
253-
}),
254-
parse: (data) => ({
255-
pull_request: parsePullRequest(data),
256-
repository: parseProject(data.project)
257-
})
258-
};
259-
260225
module.exports = new EventDetector('azure', [
261226
IssueCreatedEvent,
262227
LabelUpdatedEvent,
263228
UserUnassignedEvent,
264229
UserAssignedEvent,
265230
IssueUpdatedEvent,
231+
IssueDescriptionUpdatedEvent,
266232
IssueClosedEvent,
267-
CommentCreatedEvent,
268-
PullRequestCreatedEvent,
269-
PullRequestClosedEvent
233+
CommentCreatedEvent
270234
]);

0 commit comments

Comments
 (0)