Skip to content

Commit

Permalink
Try/catch for YT calls, find more issues, add issure-prefix flag
Browse files Browse the repository at this point in the history
  • Loading branch information
burkov committed Feb 11, 2020
1 parent c503ccc commit 2ffb0f5
Showing 1 changed file with 29 additions and 23 deletions.
52 changes: 29 additions & 23 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ const dayjs = require('dayjs');
const Ora = require('ora');

let accessToken;
program.version('1.0.0');
program.version('1.4.0');
program.name('branch-status');
program.arguments('<token>');
program.option('--skip-released', `don't show issues in Released state`, false);
program.option('--no-sort', 'do not sort', false);
program.option('--issue-prefix <prefix>', 'show only issues with given prefix', undefined);
program.action((arg) => {
accessToken = arg;
});
Expand Down Expand Up @@ -89,7 +90,8 @@ const main = async () => {

const issues = stdout
.split('\n')
.flatMap((line) => line.match(/jpf-\d{1,6}/ig) || [])
.flatMap((line) => line.match(/\w{2,4}-\d{1,6}/ig) || [])
.filter((issueId) => (program.issuePrefix === undefined) || (RegExp(program.issuePrefix, 'i').test(issueId)))
.map((x) => x.toUpperCase());

console.log(chalk.green(`Fetching YT issue statuses for ${issues.length} branches...`));
Expand All @@ -105,27 +107,31 @@ const main = async () => {

for (const [ i, id ] of issues.entries()) {
if (program.sort) ora.text = `(${i}/${issues.length}) Fetching issue ${id}`;
const {
data: {
resolved,
customFields,
summary,
},
} = await axios.get(`https://youtrack.jetbrains.com/api/issues/${id}`, {
headers: {
Authorization: `Bearer ${accessToken}`,
},
params: {
fields: 'summary,resolved,customFields(id,projectCustomField(field(name)),value(name))',
},
});
const resDate = resolved ? dayjs(resolved).format('YYYY-MM-DD') : '----------';
const state = customFields.find((e) => e.id === '123-1006').value.name;
if (state === 'Released' && program.skipReleased) continue;
const stateColorized = colorizeState(state.padEnd(20));
const formatted = `[${id.padEnd(9)}] ${resDate} ${stateColorized} ${summary}`;
if (program.noSort) console.log(formatted);
else result.push({ state, resolved, formatted });
try {
const {
data: {
resolved,
customFields,
summary,
},
} = await axios.get(`https://youtrack.jetbrains.com/api/issues/${id}`, {
headers: {
Authorization: `Bearer ${accessToken}`,
},
params: {
fields: 'summary,resolved,customFields(id,projectCustomField(field(name)),value(name))',
},
});
const resDate = resolved ? dayjs(resolved).format('YYYY-MM-DD') : '----------';
const state = customFields.find((e) => e.id === '123-1006').value.name;
if (state === 'Released' && program.skipReleased) continue;
const stateColorized = colorizeState(state.padEnd(20));
const formatted = `[${id.padEnd(9)}] ${resDate} ${stateColorized} ${summary}`;
if (program.noSort) console.log(formatted);
else result.push({ state, resolved, formatted });
} catch (e) {

}
}

if (program.sort) {
Expand Down

0 comments on commit 2ffb0f5

Please sign in to comment.