Created
October 6, 2021 13:46
-
-
Save Meigyoku-Thmn/84b8e2257c29276aff21d3f7b7d04777 to your computer and use it in GitHub Desktop.
A simple script to get all the commits you need on Jira
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const axios = require('axios').default; | |
// You need an API token as a password | |
// https://support.atlassian.com/atlassian-account/docs/manage-api-tokens-for-your-atlassian-account/ | |
const jira = axios.create({ | |
baseURL: 'https://<company-name>.atlassian.net/', | |
auth: { | |
username: "<email-as-atlassian-account-name>", | |
password: "<API-tokne>", | |
} | |
}); | |
async function main() { | |
const response = await jira.post("/rest/api/latest/search", { | |
// https://support.atlassian.com/jira-service-management-cloud/docs/use-advanced-search-with-jira-query-language-jql | |
// https://support.atlassian.com/jira-service-management-cloud/docs/advanced-search-reference-jql-fields/ | |
"jql": "project = BS and 'Epic Link' = 'Bulk Edit' and status = Closed", | |
"fields": ["id", "key"], | |
}); | |
const issues = response.data.issues; | |
console.warn(`Got ${issues.length} issue(s)`) | |
const repositories = []; | |
for (const { id: issueId, key: issueKey } of issues) { | |
const response = await jira.post('/jsw/graphql', { | |
variables: { issueId }, | |
query: `query DevDetailsDialog($issueId: ID!) { | |
developmentInformation(issueId: $issueId) { | |
details { | |
instanceTypes { | |
id | |
name | |
repository { | |
name | |
commits { | |
id | |
timestamp | |
message | |
} | |
} | |
} | |
} | |
} | |
}`, | |
}); | |
const _repositories = response.data.data.developmentInformation.details.instanceTypes | |
.find(e => e.name == "GitHub") | |
?.repository ?? []; | |
repositories.push(..._repositories); | |
console.warn( | |
`- Got ${_repositories.reduce((count, e) => count + e.commits.length, 0)} commit(s) from issue ${issueKey} (${issueId})`); | |
} | |
var repoNames = ["dfn-bs-portal", "dfn-bs-portal-api"]; | |
for (const repoName of repoNames) { | |
console.log(); | |
console.log(repoName); | |
const filtereds = repositories | |
.filter(e => e.name.endsWith(repoName)) | |
.flatMap(e => e.commits) | |
.sort((a, b) => new Date(a.timestamp) < new Date(b.timestamp) ? -1 : 1); | |
if (filtereds.length === 0) | |
continue; | |
filtereds.forEach(e => console.log(` ${e.id} ${e.timestamp} ${JSON.stringify(e.message)}`)); | |
} | |
}; | |
(async () => { | |
try { | |
await main(); | |
} catch (err) { | |
console.error(err); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment