Skip to content

Commit

Permalink
[NE-2426] feat: assign to reporter (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
Timmatt-Lee authored Aug 23, 2020
1 parent c90dc28 commit c3d471e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 32 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ jobs:
project: ${{ secrets.JIRA_PROJECT_NAME }}
transition: ${{ secrets.JIRA_MERGE_TRANSITION_NAME }}
isOnlyTransition: true
otherAssignedTransition: ${{ secrets.JIRA_QA_TRANSITION_NAME }}
isAssignToReporter: true
otherAssignedTransition: ${{ secrets.JIRA_QA_TRANSITION_NAME }}

43 changes: 13 additions & 30 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -488,33 +488,19 @@ class Jira {
return result.item.accountId;
}

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 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 request(api, method = 'get', data = {}) {
Expand Down Expand Up @@ -1796,7 +1782,6 @@ 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');

if (isOnlyTransition) isCreateIssue = false;

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

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

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 @@ -18,7 +18,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');
const isAssignToReporter = core.getInput('isAssignToReporter').toLowerCase() === 'true';

if (isOnlyTransition) isCreateIssue = false;

Expand Down

0 comments on commit c3d471e

Please sign in to comment.