From c33371a6cd8834a82a43be10917f9b3a48a23ad2 Mon Sep 17 00:00:00 2001 From: Curt Bonade Date: Thu, 14 Dec 2023 16:31:46 -0500 Subject: [PATCH 1/2] Add logic to reassign tickets in github when reassigned in Slack --- src/api/github/index.js | 25 +++++++++++++++++++++++++ src/logic/form-support.js | 6 +----- src/logic/index.js | 9 +++++++-- src/request-handler.js | 6 +++--- 4 files changed, 36 insertions(+), 10 deletions(-) diff --git a/src/api/github/index.js b/src/api/github/index.js index 1d898c1..39d2b01 100644 --- a/src/api/github/index.js +++ b/src/api/github/index.js @@ -42,6 +42,31 @@ module.exports = (logger) => { return response; }, + removeLabelsFromIssue: async (issue_number) => { + github.authenticate(); + + let response = await octokit.rest.issues.removeAllLabels({ + owner: process.env.GITHUB_OWNER, + repo: process.env.GITHUB_ISSUE_REPO, + issue_number: issue_number, + }) + + return response; + }, + + labelReassignedIssue: async (issue_number, label) => { + github.authenticate(); + + let response = await octokit.rest.issues.addLabels({ + owner: process.env.GITHUB_OWNER, + repo: process.env.GITHUB_ISSUE_REPO, + issue_number: issue_number, + labels: [process.env.GITHUB_SUPPORT_LABEL, label] + }) + + return response; + }, + commentOnIssue: async ( issue_number, body ) => { github.authenticate(); diff --git a/src/logic/form-support.js b/src/logic/form-support.js index 4966bbb..6de2ac5 100644 --- a/src/logic/form-support.js +++ b/src/logic/form-support.js @@ -114,6 +114,7 @@ module.exports = function (logger) { id: selectedValue, title: team.Title, display: team.Display, + githubLabel: team.GitHubLabel }; }; @@ -216,11 +217,6 @@ module.exports = function (logger) { autoResponse ) => { - console.log(responseBuilder.buildAdditionalPostResponse( - thread, - autoResponse - )) - console.log(autoResponse) const postedMessage = await client.chat.postMessage({ channel: SUPPORT_CHANNEL_ID, thread_ts: thread, diff --git a/src/logic/index.js b/src/logic/index.js index a6aa320..1a47029 100644 --- a/src/logic/index.js +++ b/src/logic/index.js @@ -308,7 +308,6 @@ module.exports = (logger) => { team = await formSupport.extractReassignFormData(view); let sheetMessage; - if (!message) return sendErrorMessageToUser(); const onSupportUsers = await routing.getOnCallUser(client, team.id); @@ -332,7 +331,13 @@ module.exports = (logger) => { value: ticketId, }, }; - + if (team.githubLabel) { + const row = await sheets.getMessageByTicketId(ticketId); + if(row && row.messageRow.GithubIssueId) { + github.removeLabelsFromIssue(row.messageRow.GithubIssueId); + github.labelReassignedIssue(row.messageRow.GithubIssueId, team.githubLabel); + }; + } await slack.updateMessageById(client, message.ts, SUPPORT_CHANNEL_ID, blocks); await client.chat.postMessage({ channel: process.env.SLACK_SUPPORT_CHANNEL, diff --git a/src/request-handler.js b/src/request-handler.js index 2cc90a0..0a68034 100644 --- a/src/request-handler.js +++ b/src/request-handler.js @@ -133,9 +133,9 @@ module.exports = function (app, logger) { }); /** - * Action: reassign_ticket - * This function gets called when the "Reassign Ticket" button - * is clicked on. It brings up a reassign ticket modal. + * Action: close_ticket + * This function gets called when the "Close Ticket" button + * is clicked on. It closes the GitHub ticket. */ app.action('close_ticket', async ({ ack, body, client, payload }) => { try { From 59d2f50ce30673ad1c1d7edaae7f40a48fb44b62 Mon Sep 17 00:00:00 2001 From: Curt Bonade Date: Thu, 4 Jan 2024 12:05:01 -0500 Subject: [PATCH 2/2] Remove local setup code --- src/api/github/index.js | 2 +- src/logic/index.js | 13 ++++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/api/github/index.js b/src/api/github/index.js index 39d2b01..2ef0256 100644 --- a/src/api/github/index.js +++ b/src/api/github/index.js @@ -61,7 +61,7 @@ module.exports = (logger) => { owner: process.env.GITHUB_OWNER, repo: process.env.GITHUB_ISSUE_REPO, issue_number: issue_number, - labels: [process.env.GITHUB_SUPPORT_LABEL, label] + labels: label ? [process.env.GITHUB_SUPPORT_LABEL, label] : [process.env.GITHUB_SUPPORT_LABEL] }) return response; diff --git a/src/logic/index.js b/src/logic/index.js index 1a47029..9a7cf7f 100644 --- a/src/logic/index.js +++ b/src/logic/index.js @@ -331,13 +331,12 @@ module.exports = (logger) => { value: ticketId, }, }; - if (team.githubLabel) { - const row = await sheets.getMessageByTicketId(ticketId); - if(row && row.messageRow.GithubIssueId) { - github.removeLabelsFromIssue(row.messageRow.GithubIssueId); - github.labelReassignedIssue(row.messageRow.GithubIssueId, team.githubLabel); - }; - } + + const row = await sheets.getMessageByTicketId(ticketId); + if(row && row.messageRow.GithubIssueId) { + github.removeLabelsFromIssue(row.messageRow.GithubIssueId); + github.labelReassignedIssue(row.messageRow.GithubIssueId, team.githubLabel); + }; await slack.updateMessageById(client, message.ts, SUPPORT_CHANNEL_ID, blocks); await client.chat.postMessage({ channel: process.env.SLACK_SUPPORT_CHANNEL,