From 889088510c0f6d688ca01ea1d788db5d427d484e Mon Sep 17 00:00:00 2001 From: Adam Rensel Date: Tue, 11 May 2021 13:09:22 -0400 Subject: [PATCH] Add labels --- .github/workflows/src/app/octokit.js | 22 +++++++++++++++++++++- .github/workflows/src/index.js | 8 +++++--- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/.github/workflows/src/app/octokit.js b/.github/workflows/src/app/octokit.js index a7ad7a08..67d527bd 100644 --- a/.github/workflows/src/app/octokit.js +++ b/.github/workflows/src/app/octokit.js @@ -1,6 +1,9 @@ const { Octokit, App, Action } = require("octokit") const actionEvent = require('./action-event.js'); +const MERGE_LABEL = "✅ Ready for merge" +const CLOSED_LABEL = "🎉 Previously Graduated" + class Octo { constructor() { this.octokit = new Octokit({ auth: process.env.GH_SECRET }); @@ -113,13 +116,30 @@ class Octo { } async closePR() { - await this.octokit.request('PATCH /repos/{owner}/{repo}/pulls/{pull_number}', { + return await this.octokit.request('PATCH /repos/{owner}/{repo}/pulls/{pull_number}', { owner: actionEvent.pullRepoOwner, repo: actionEvent.pullRepo.name, pull_number: actionEvent.pullNumber, state: "closed" }) } + + async addReviewLabel() { + return await this.addLabel(MERGE_LABEL) + } + + async addClosedLabel() { + return await this.addLabel(CLOSED_LABEL) + } + + async addLabel(label) { + return await octokit.request('POST /repos/{owner}/{repo}/issues/{issue_number}/labels', { + owner: actionEvent.pullRepoOwner, + repo: actionEvent.pullRepo.name, + issue_number: actionEvent.pullNumber, + labels: label + }) + } } module.exports = new Octo() diff --git a/.github/workflows/src/index.js b/.github/workflows/src/index.js index e56fb392..35eb8891 100644 --- a/.github/workflows/src/index.js +++ b/.github/workflows/src/index.js @@ -162,9 +162,10 @@ Feel free to re-request a review from me and I'll come back and take a look! ` } else { // All checks pass - feedBackMessage = "It looks like you're all set! Thanks for the graduation submission. I'll go ahead and merge this." + feedBackMessage = "It looks like you're all set! Thanks for the graduation submission." try { - await octokit.mergePR() + // await octokit.mergePR() + await octokit.addReviewLabel() } catch(err) { console.error(err) feedBackMessage += "\n\n Uh Oh! I tried to merge this PR and something went wrong!" @@ -187,7 +188,8 @@ ${ feedBackMessage } if(closePR) { try { - octokit.closePR() + await octokit.addClosedLabel() + await octokit.closePR() } catch(err) { console.log("failed to close PR") console.log(err) -- knotmirror 0.0.1