Skip to content

Commit 96300ad

Browse files
committed
kamil test
1 parent 24d5fc6 commit 96300ad

File tree

3 files changed

+58
-15
lines changed

3 files changed

+58
-15
lines changed

update_jira/index.js

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,34 @@ const Jira = require('./../utils/jira')
55
const statusMap = {
66
'master': {
77
status: 'Deployed to Production',
8-
fields: {}
8+
fields: {
9+
// prod release timestamp
10+
customfield_11475: new Date(),
11+
customfield_11473: 'Production',
12+
}
913
},
1014
'main': {
1115
status: 'Deployed to Production',
12-
fields: {}
16+
fields: {
17+
// prod release timestamp
18+
customfield_11475: new Date(),
19+
customfield_11473: 'Production',
20+
}
1321
},
1422
'staging': {
1523
status: 'Deployed to Staging',
1624
fields: {
1725
resolution: 'Done',
26+
// staging release timestamp
27+
customfield_11474: new Date(),
28+
customfield_11473: 'Staging',
1829
}
1930
},
2031
'dev': {
2132
status: 'Deployed to Staging',
2233
fields: {
23-
resolution: 'Done'
34+
resolution: 'Done',
35+
customfield_11473: 'Development',
2436
}
2537
}
2638
}
@@ -201,12 +213,27 @@ async function handlePushEvent(branch, jiraUtil, githubRepository, githubToken)
201213

202214
// Handle special case: staging -> production bulk update
203215
if ((branch === 'master' || branch === 'main')) {
216+
if (commitMessage === 'from coursedog/staging') {
217+
218+
} else if (commitMessage.match(/#+[0-9]/)) {
219+
// direct from open PR to staging
220+
const prNumber = extractPrNumber(commitMessage)
221+
const prUrl = `${repositoryName}/pull/${prNumber}`
222+
if (!prNumber) return
223+
jiraUtil.updateByPR(prUrl, newStatus, preparedFields)
224+
}
225+
204226
console.log('Bulk updating all Staging issues to Done')
205227
const issues = await jiraUtil.updateByStatus('Deployed to Staging', newStatus, preparedFields)
206228

207229
return
208230
}
209231

232+
if (branch === 'staging') {
233+
console.log('Bulk updating all Deployed to Dev issues to Deployed to Staging')
234+
const issues = await jiraUtil.updateByStatus('Deployed to Dev', newStatus, preparedFields)
235+
}
236+
210237
// Handle PR merges (look for PR number in commit message)
211238
const prMatch = commitMessage.match(/#([0-9]+)/)
212239
if (prMatch) {

update_notion/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ async function _updateNotionStatuses (branch) {
5959
})
6060

6161
const [ githubOwner, repositoryName ] = GITHUB_REPOSITORY.split('/')
62-
62+
6363
// Get most recent commit to branch
6464
const { data } = await octokit.rest.repos.getCommit({
6565
owner: githubOwner,
@@ -103,7 +103,7 @@ async function _updateNotionStatuses (branch) {
103103
notionUtil.updateByPR(`${repositoryName}/pull/${prNumber}`, 'Completed (Staging)')
104104
}
105105
break
106-
106+
107107
default:
108108
break
109109
}

utils/jira.js

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -223,25 +223,42 @@ class Jira {
223223
}
224224

225225
/**
226-
* Search for issues with a specific status and update them
227-
* @param {string} currentStatus - Current status to search for
228-
* @param {string} newStatus - New status to transition to
229-
* @param {Object} fields - Additional fields to set during transition
226+
* Find issues with a specific status
227+
* @param {string} status - Status to search for
228+
* @param {number} maxResults - Maximum number of results to return (default: 100)
229+
* @param {Array<string>} fields - Fields to include in the response (default: ['key', 'summary', 'status'])
230+
* @returns {Promise<Array>} Array of issues matching the status
230231
*/
231-
async updateByStatus(currentStatus, newStatus, fields = {}) {
232+
async findByStatus(status, maxResults = 100, fields = ['key', 'summary', 'status']) {
232233
try {
233-
let jql = `status = "${currentStatus}"`
234+
const jql = `status = "${status}"`
234235
const response = await this.request('/search', {
235236
method: 'POST',
236237
body: JSON.stringify({
237238
jql,
238-
fields: ['key', 'summary', 'status'],
239-
maxResults: 100
239+
fields,
240+
maxResults
240241
})
241242
})
242243

243244
const data = await response.json()
244-
const issues = data.issues
245+
console.log(`Found ${data.issues.length} issues in "${status}" status`)
246+
return data.issues
247+
} catch (error) {
248+
console.error(`Error finding issues by status:`, error.message)
249+
throw error
250+
}
251+
}
252+
253+
/**
254+
* Search for issues with a specific status and update them
255+
* @param {string} currentStatus - Current status to search for
256+
* @param {string} newStatus - New status to transition to
257+
* @param {Object} fields - Additional fields to set during transition
258+
*/
259+
async updateByStatus(currentStatus, newStatus, fields = {}) {
260+
try {
261+
const issues = await this.findByStatus(currentStatus)
245262
console.log(`Found ${issues.length} issues in "${currentStatus}" status`)
246263

247264
const settledIssuePromises = await Promise.allSettled(
@@ -255,7 +272,6 @@ class Jira {
255272

256273
const rejected = settledIssuePromises.filter((result) => result.status === 'rejected')
257274
const fullfilled = settledIssuePromises.filter((result) => result.status === 'fulfilled')
258-
259275
console.log(`Sucessfully updated ${fullfilled.length} isssues.`)
260276

261277
if (rejected) {

0 commit comments

Comments
 (0)