Skip to content

Commit b8e0d6a

Browse files
committed
update jira status script
1 parent a1cf67b commit b8e0d6a

File tree

2 files changed

+5
-19
lines changed

2 files changed

+5
-19
lines changed

update_jira/index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,10 @@ async function handlePushEvent(branch, jiraUtil, githubRepository, githubToken)
9393

9494
const { commit: { message: commitMessage } } = data
9595
const statusMap = {
96-
'master': 'Done',
97-
'main': 'Done',
98-
'staging': 'Staging',
99-
'dev': 'Dev'
96+
'master': 'Deployed to Production',
97+
'main': 'Deployed to Production',
98+
'staging': 'Deployed to Staging',
99+
'dev': 'Deployed to Staging'
100100
}
101101

102102
const newStatus = statusMap[branch]
@@ -108,7 +108,7 @@ async function handlePushEvent(branch, jiraUtil, githubRepository, githubToken)
108108
// Handle special case: staging -> production bulk update
109109
if ((branch === 'master' || branch === 'main') && commitMessage.includes('from coursedog/staging')) {
110110
console.log('Bulk updating all Staging issues to Done')
111-
await jiraUtil.updateByStatus('Staging', newStatus)
111+
await jiraUtil.updateByStatus('Deployed to Staging', newStatus)
112112
return
113113
}
114114

utils/jira.js

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,13 @@ class Jira {
5656

5757
const workflow = data.values[0]
5858

59-
// Build state machine structure
6059
const stateMachine = {
6160
name: workflow.id.name,
6261
states: {},
6362
transitions: [],
6463
transitionMap: new Map() // For quick lookup: Map<fromStatusId, Map<toStatusId, transition>>
6564
}
6665

67-
// Process states
6866
if (workflow.statuses) {
6967
workflow.statuses.forEach(status => {
7068
stateMachine.states[status.id] = {
@@ -75,7 +73,6 @@ class Jira {
7573
})
7674
}
7775

78-
// Process transitions
7976
if (workflow.transitions) {
8077
workflow.transitions.forEach(transition => {
8178
const transitionInfo = {
@@ -157,7 +154,6 @@ class Jira {
157154
* @returns {Array} All possible paths
158155
*/
159156
findAllTransitionPaths(stateMachine, fromStatusName, toStatusName) {
160-
// Convert names to IDs
161157
let fromStatusId = null
162158
let toStatusId = null
163159

@@ -297,11 +293,9 @@ class Jira {
297293
*/
298294
async getWorkflowSchema(projectKey) {
299295
try {
300-
// Get project details to find issue types
301296
const project = await this.request(`/project/${projectKey}`)
302297
const projectData = await project.json()
303298

304-
// Get workflow schemes
305299
const workflowResponse = await this.request(`/workflowscheme/project?projectId=${projectData.id}`)
306300
const workflowData = await workflowResponse.json()
307301

@@ -336,7 +330,6 @@ class Jira {
336330
* @returns {Array} Shortest path of transitions
337331
*/
338332
findShortestTransitionPath(stateMachine, fromStatusName, toStatusName, excludeStates = []) {
339-
// Convert names to IDs
340333
let fromStatusId = null
341334
let toStatusId = null
342335
const excludeStatusIds = new Set()
@@ -357,7 +350,6 @@ class Jira {
357350
return [] // Already at destination
358351
}
359352

360-
// Check if target status is in excluded states
361353
if (excludeStatusIds.has(toStatusId)) {
362354
console.warn(`Target status "${toStatusName}" is in the excluded states list`)
363355
return null
@@ -379,7 +371,6 @@ class Jira {
379371
}
380372

381373
if (nextStatusId === toStatusId) {
382-
// Found the target
383374
return [...path, {
384375
id: transition.id,
385376
name: transition.name,
@@ -419,7 +410,6 @@ class Jira {
419410
*/
420411
async transitionIssue(issueKey, targetStatusName, excludeStates = ['Blocked', 'Rejected']) {
421412
try {
422-
// Get current issue status
423413
const issueResponse = await this.request(`/issue/${issueKey}?fields=status`)
424414
const issueData = await issueResponse.json()
425415
const currentStatusName = issueData.fields.status.name
@@ -449,12 +439,9 @@ class Jira {
449439
console.log(`Found shortest transition path with ${shortestPath.length} steps:`)
450440
shortestPath.forEach(t => console.log(` ${t.fromName}${t.toName} (${t.name})`))
451441

452-
// Execute transitions in sequence
453442
for (const transition of shortestPath) {
454-
// Get available transitions for current state of the issue
455443
const availableTransitions = await this.getTransitions(issueKey)
456444

457-
// Find the matching transition
458445
const actualTransition = availableTransitions.find(t =>
459446
t.id === transition.id ||
460447
(t.to.name === transition.toName && t.name === transition.name)
@@ -466,7 +453,6 @@ class Jira {
466453
return false
467454
}
468455

469-
// Execute the transition
470456
await this.request(`/issue/${issueKey}/transitions`, {
471457
method: 'POST',
472458
body: JSON.stringify({

0 commit comments

Comments
 (0)