Skip to content

Commit 8d3fccd

Browse files
authored
Merge pull request #32 from saschanaz/reopen
Allow reopening by codeowners
2 parents d748ec3 + 7714286 commit 8d3fccd

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

index.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ async function run() {
2121
new Actor().mergeIfHasAccess();
2222
} else if (bodyLower.includes("@github-actions close")) {
2323
new Actor().closePROrIssueIfInCodeowners();
24+
} else if (bodyLower.includes("@github-actions reopen")) {
25+
new Actor().reopenPROrIssueIfInCodeowners();
2426
} else {
2527
console.log("Doing nothing because the body does not include a command")
2628
}
@@ -196,10 +198,10 @@ class Actor {
196198
}
197199
}
198200

199-
async closePROrIssueIfInCodeowners() {
201+
async closePROrIssueIfInCodeowners() {
200202
// Because closing a PR/issue does not mutate the repo, we can use a weaker
201203
// authentication method: basically is the person in the codeowners? Then they can close
202-
// an issue or PR.
204+
// an issue or PR.
203205
if (!githubLoginIsInCodeowners(this.sender, this.cwd)) return
204206

205207
const { octokit, thisRepo, issue, sender } = this;
@@ -208,6 +210,16 @@ class Actor {
208210
await octokit.issues.update({ ...thisRepo, issue_number: issue.number, state: "closed" });
209211
await octokit.issues.createComment({ ...thisRepo, issue_number: issue.number, body: `Closing because @${sender} is one of the code-owners of this repository.` });
210212
}
213+
214+
async reopenPROrIssueIfInCodeowners() {
215+
if (!githubLoginIsInCodeowners(this.sender, this.cwd)) return
216+
217+
const { octokit, thisRepo, issue, sender } = this;
218+
219+
core.info(`Creating comments and reopening`)
220+
await octokit.issues.update({ ...thisRepo, issue_number: issue.number, state: "open" });
221+
await octokit.issues.createComment({ ...thisRepo, issue_number: issue.number, body: `Reopening because @${sender} is one of the code-owners of this repository.` });
222+
}
211223
}
212224

213225
/**
@@ -235,7 +247,7 @@ function getFilesNotOwnedByCodeOwner(owner, files, cwd) {
235247
/**
236248
* This is a reasonable security measure for proving an account is specified in the codeowners
237249
* but _SHOULD NOT_ be used for authentication for something which mutates the repo,
238-
*
250+
*
239251
* @param {string} login
240252
* @param {string} cwd
241253
*/

0 commit comments

Comments
 (0)