3
3
*/
4
4
5
5
/**
6
- * This module contains the EventDetector for gitlab .
6
+ * This module contains the EventDetector for azure .
7
7
*
8
8
* @author TCSCODER
9
9
* @version 1.0
@@ -17,8 +17,8 @@ const models = require('../models');
17
17
const EventDetector = require ( './EventDetector' ) ;
18
18
19
19
/**
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
22
22
* @returns {object } the parsed issue detail
23
23
*/
24
24
const parseIssue = ( data ) => {
@@ -36,8 +36,8 @@ const parseIssue = (data) => {
36
36
} ;
37
37
38
38
/**
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
41
41
* @returns {object } the parsed project detail
42
42
*/
43
43
const parseProject = ( data ) => {
@@ -56,51 +56,32 @@ const parseProject = (data) => {
56
56
} ;
57
57
58
58
/**
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
61
61
* @returns {object } the parsed comment detail
62
62
*/
63
63
const parseComment = ( data ) => ( {
64
- issue : parseIssue ( data , data . issue ) ,
65
- repository : parseProject ( data . project ) ,
64
+ issue : parseIssue ( data ) ,
65
+ repository : parseProject ( data ) ,
66
66
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' ] ,
69
69
user : {
70
- id : data . object_attributes . author_id
70
+ id : data . resource . revisedBy . id
71
71
}
72
72
}
73
73
} ) ;
74
74
75
75
/**
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
78
78
* @returns {object } the parsed issue event detail
79
79
*/
80
80
const parseIssueEventData = ( data ) => ( {
81
81
issue : parseIssue ( data ) ,
82
82
repository : parseProject ( data )
83
83
} ) ;
84
84
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
-
104
85
// definition of issue created event
105
86
const IssueCreatedEvent = {
106
87
event : models . IssueCreatedEvent ,
@@ -114,15 +95,29 @@ const IssueCreatedEvent = {
114
95
const IssueUpdatedEvent = {
115
96
event : models . IssueUpdatedEvent ,
116
97
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 ( )
126
121
} ) ,
127
122
parse : parseIssueEventData
128
123
} ;
@@ -154,11 +149,13 @@ const IssueClosedEvent = {
154
149
const CommentCreatedEvent = {
155
150
event : models . CommentCreatedEvent ,
156
151
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 ( )
162
159
} ) . required ( )
163
160
} ) ,
164
161
parse : parseComment
@@ -225,46 +222,13 @@ const LabelUpdatedEvent = {
225
222
} )
226
223
} ;
227
224
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
-
260
225
module . exports = new EventDetector ( 'azure' , [
261
226
IssueCreatedEvent ,
262
227
LabelUpdatedEvent ,
263
228
UserUnassignedEvent ,
264
229
UserAssignedEvent ,
265
230
IssueUpdatedEvent ,
231
+ IssueDescriptionUpdatedEvent ,
266
232
IssueClosedEvent ,
267
- CommentCreatedEvent ,
268
- PullRequestCreatedEvent ,
269
- PullRequestClosedEvent
233
+ CommentCreatedEvent
270
234
] ) ;
0 commit comments