Skip to content

Commit b413cb8

Browse files
committed
Fixes the check for which users have access to merge a PR
1 parent 00cf837 commit b413cb8

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

index.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const {readFileSync} = require("fs")
77

88
// Effectively the main function
99
async function run() {
10-
core.info("Running version 1.4.0")
10+
core.info("Running version 1.4.1")
1111

1212
// Tell folks they can merge
1313
if (context.eventName === "pull_request_target") {
@@ -43,7 +43,7 @@ async function commentOnMergablePRs() {
4343
core.info(`Code-owners: \n - ${codeowners.users.join("\n - ")}`)
4444
core.info(`Labels: \n - ${codeowners.labels.join("\n - ")}`)
4545

46-
if (!codeowners.length) {
46+
if (!codeowners.users.length) {
4747
console.log("This PR does not have any code-owners")
4848
process.exit(0)
4949
}
@@ -55,7 +55,7 @@ async function commentOnMergablePRs() {
5555
if (filesWhichArentOwned.length === 0) ownersWhoHaveAccessToAllFilesInPR.push(owner)
5656
})
5757

58-
if(!ownersWhoHaveAccessToAllFilesInPR.length) {
58+
if (!ownersWhoHaveAccessToAllFilesInPR.length) {
5959
console.log("This PR does not have any code-owners who own all of the files in the PR")
6060
listFilesWithOwners(changedFiles, cwd)
6161
process.exit(0)
@@ -85,12 +85,13 @@ ${ourSignature}`
8585
}
8686

8787
async function mergeIfLGTMAndHasAccess() {
88-
if (context.eventName !== "issue_comment" && context.eventName !== "pull_request_review") {
89-
throw new Error("This GH action can only run when the workflow specifies `pull_request_target` in the `on:`.")
88+
const body = context.payload.comment ? context.payload.comment.body : context.payload.review.body
89+
if (!body) {
90+
// For debugging #8
91+
console.log(JSON.stringify(context))
9092
}
9193

92-
const body = context.payload.comment ? context.payload.comment.body : context.payload.review.body
93-
if (!body.toLowerCase().includes("lgtm")) {
94+
if (!body || !body.toLowerCase().includes("lgtm")) {
9495
console.log("Comment does not include LGTM ('looks good to me') so not merging")
9596
process.exit(0)
9697
}

0 commit comments

Comments
 (0)