@@ -53,38 +53,58 @@ async function run() {
53
53
}
54
54
55
55
/**
56
- * Handle PR events - draft changes, ready for review , etc.
56
+ * Handle pull request events (open, close , etc)
57
57
*/
58
- async function handlePullRequestEvent ( eventData , jiraUtil , githubRepository ) {
59
- console . log ( 'HANDLING PR EVENT' )
58
+ async function handlePullRequestEvent ( eventData , jiraUtil ) {
60
59
const { action, pull_request } = eventData
61
- const [ _ , repositoryName ] = githubRepository . split ( '/' )
62
60
63
- const prUrl = `${ repositoryName } /pull/${ pull_request . number } `
64
- let targetStatus = null
61
+ const issueKeys = extractJiraIssueKeys ( pull_request )
62
+ if ( issueKeys . length === 0 ) {
63
+ console . log ( 'No Jira issue keys found in PR' )
64
+ return
65
+ }
65
66
66
- console . log ( 'action:' , action )
67
+ console . log ( `Found Jira issues: ${ issueKeys . join ( ', ' ) } ` )
68
+
69
+ let targetStatus = null
70
+ const targetBranch = pull_request . base . ref
67
71
68
72
switch ( action ) {
73
+ case 'opened' :
74
+ case 'reopened' :
75
+ case 'ready_for_review' :
76
+ targetStatus = 'Code Review'
77
+ break
69
78
case 'converted_to_draft' :
70
79
targetStatus = 'In Development'
71
80
break
72
- case 'ready_for_review' :
73
- targetStatus = 'Code Review'
74
81
case 'synchronize' : {
75
82
if ( ! pull_request . draft ) {
76
83
targetStatus = 'Code Review'
77
84
}
78
85
break
79
86
}
87
+ case 'closed' :
88
+ if ( pull_request . merged ) {
89
+ targetStatus = statusMap [ targetBranch ] || 'Done'
90
+ } else {
91
+ console . log ( 'PR closed without merging, skipping status update' )
92
+ return
93
+ }
94
+ break
80
95
default :
81
- console . log ( ` No status update needed for PR action: ${ action } ` )
82
- return
96
+ console . log ( ' No status updates for action:' , action )
97
+ break
83
98
}
84
99
85
100
if ( targetStatus ) {
86
- console . log ( `Updating issues mentioning PR ${ prUrl } to status: ${ targetStatus } ` )
87
- await jiraUtil . updateByPR ( prUrl , targetStatus )
101
+ for ( const issueKey of issueKeys ) {
102
+ try {
103
+ await jiraUtil . transitionIssue ( issueKey , targetStatus )
104
+ } catch ( error ) {
105
+ console . error ( `Failed to update ${ issueKey } :` , error . message )
106
+ }
107
+ }
88
108
}
89
109
}
90
110
@@ -163,51 +183,3 @@ function extractJiraIssueKeys(pullRequest) {
163
183
return Array . from ( keys )
164
184
}
165
185
166
- /**
167
- * Handle PR-specific Jira updates
168
- * @param {Object } eventData - GitHub event data
169
- * @param {Jira } jiraUtil - Jira utility instance
170
- */
171
- async function handlePullRequestEvent ( eventData , jiraUtil ) {
172
- const { action, pull_request } = eventData
173
-
174
- const issueKeys = extractJiraIssueKeys ( pull_request )
175
- if ( issueKeys . length === 0 ) {
176
- console . log ( 'No Jira issue keys found in PR' )
177
- return
178
- }
179
-
180
- console . log ( `Found Jira issues: ${ issueKeys . join ( ', ' ) } ` )
181
-
182
- let targetStatus = null
183
- const targetBranch = pull_request . base . ref
184
-
185
- switch ( action ) {
186
- case 'opened' :
187
- case 'reopened' :
188
- case 'ready_for_review' :
189
- targetStatus = 'Code Review'
190
- break
191
- case 'converted_to_draft' :
192
- targetStatus = 'In Development'
193
- break
194
- case 'closed' :
195
- if ( pull_request . merged ) {
196
- targetStatus = statusMap [ targetBranch ] || 'Done'
197
- } else {
198
- console . log ( 'PR closed without merging, skipping status update' )
199
- return
200
- }
201
- break
202
- }
203
-
204
- if ( targetStatus ) {
205
- for ( const issueKey of issueKeys ) {
206
- try {
207
- await jiraUtil . transitionIssue ( issueKey , targetStatus )
208
- } catch ( error ) {
209
- console . error ( `Failed to update ${ issueKey } :` , error . message )
210
- }
211
- }
212
- }
213
- }
0 commit comments