Skip to content

Commit

Permalink
[NE-2426] feat: assign to reporter (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
Timmatt-Lee authored Aug 23, 2020
1 parent c3d471e commit 34e4f88
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 14 deletions.
43 changes: 30 additions & 13 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -488,19 +488,33 @@ class Jira {
return result.item.accountId;
}

async isMeCreatedIssue(issue) {
try {
const {
fields: {
reporter: { accountId: _1 },
assignee: { accountId: _2 },
},
} = await this.request(`/rest/api/3/issue/${issue}`);
return _1 === _2;
} catch (e) {
// any exception means reporter and assignee are not identical
return false;
}
async getIssue(key) {
return this.request(`/rest/api/3/issue/${key}`);
}

async getIssueAssigneeId(key) {
const { fields } = await this.getIssue(key);
if (!fields.assignee) return null;

return fields.assignee.accountId;
}

async getIssueReporterId(key) {
const { fields } = await this.getIssue(key);
if (!fields.reporter) return null;

return fields.reporter.accountId;
}

async isMeCreatedIssue(key) {
const assigneeId = await this.getIssueAssigneeId(key);
const reporterId = await this.getIssueReporterId(key);
if (!assigneeId && !reporterId) return false;
return assigneeId === reporterId;
}

async putAssignIssue(key, accountId) {
return this.request(`/rest/api/3/issue/${key}/assignee`, 'put', { accountId });
}

async request(api, method = 'get', data = {}) {
Expand Down Expand Up @@ -1782,6 +1796,7 @@ async function main() {
const isOnlyTransition = core.getInput('isOnlyTransition').toLowerCase() === 'true';
let isCreateIssue = core.getInput('isCreateIssue').toLowerCase() === 'true';
const otherAssignedTransition = core.getInput('otherAssignedTransition');
const isAssignToReporter = core.getInput('isAssignToReporter').toLowerCase() === 'true';

if (isOnlyTransition) isCreateIssue = false;

Expand Down Expand Up @@ -1838,6 +1853,8 @@ async function main() {
if (!isMeCreatedIssue) transition = otherAssignedTransition;
}

if (isAssignToReporter) await jira.putAssignIssue(key, await jira.getIssueReporterId(key));

await jira.postTransitIssue(key, transition);

if (isOnlyTransition) { core.info('transit completed'); process.exit(0); }
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ async function main() {
if (!isMeCreatedIssue) transition = otherAssignedTransition;
}

if (isAssignToReporter) await jira.putAssignIssue(key, await jira.getIssueReporterId);
if (isAssignToReporter) await jira.putAssignIssue(key, await jira.getIssueReporterId(key));

await jira.postTransitIssue(key, transition);

Expand Down

0 comments on commit 34e4f88

Please sign in to comment.