Skip to content

Commit 6c2e2fe

Browse files
committed
Update the action JS
1 parent d77c91c commit 6c2e2fe

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
/README.md @orta
1+
README.md @orta

index.js

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,21 @@ const Codeowners = require('codeowners');
66

77
// Effectively the main function
88
async function run() {
9+
console.log("Starting with ", context)
10+
911
// Tell folks they can merge
10-
if (context.action === "pull_request_target") {
12+
if (context.eventName === "pull_request_target") {
1113
commentOnMergablePRs()
1214
}
1315

1416
// Merge if they say they have access
15-
if (context.action === "issue_comment") {
17+
if (context.eventName === "issue_comment") {
1618
mergeIfLGTMAndHasAccess()
1719
}
1820
}
1921

2022
async function commentOnMergablePRs() {
21-
if (context.action !== "pull_request_target") {
23+
if (context.eventName !== "pull_request_target") {
2224
throw new Error("This function can only run when the workflow specifies `pull_request_target` in the `on:`.")
2325
}
2426

@@ -28,11 +30,16 @@ async function commentOnMergablePRs() {
2830
const pr = context.payload.pull_request
2931
const thisRepo = { owner: context.repo.owner, repo: context.repo.repo }
3032

31-
core.info(`\n\nLooking at PR: ${pr.title}`)
33+
core.info(`\n\nLooking at PR: '${pr.title}' for codeowners`)
3234

3335
const changedFiles = await getPRChangedFiles(octokit, thisRepo, pr.number)
36+
console.log("changed files", changedFiles)
3437
const codeowners = findCodeOwnersForChangedFiles(changedFiles, cwd)
35-
38+
console.log("owners for PR", codeowners)
39+
40+
const co = new Codeowners(cwd);
41+
console.log(co.codeownersFilePath, co.codeownersDirectory)
42+
3643
if (!codeowners.length) {
3744
console.log("This PR does not have any code-owners")
3845
process.exit(0)
@@ -69,22 +76,23 @@ ${ourSignature}`
6976

7077

7178
async function mergeIfLGTMAndHasAccess() {
72-
if (context.action !== "issue_comment") {
79+
if (context.eventName !== "issue_comment") {
7380
throw new Error("This GH action can only run when the workflow specifies `pull_request_target` in the `on:`.")
7481
}
7582

76-
const issue = context.payload.issue
77-
if (!issue.body.toLowerCase().includes("lgtm")) {
83+
if (!context.payload.comment.body.toLowerCase().includes("lgtm")) {
7884
console.log("Comment does not include LGTM ('looks good to me') so not merging")
7985
process.exit(0)
8086
}
8187

88+
8289
// Setup
8390
const cwd = "."
8491
const octokit = getOctokit(process.env.GITHUB_TOKEN)
8592
const thisRepo = { owner: context.repo.owner, repo: context.repo.repo }
93+
const issue = context.payload.issue
8694

87-
core.info(`\n\nLooking at PR: ${issue.title}`)
95+
core.info(`\n\nLooking at PR: ${issue.title} to see if we can merge`)
8896

8997
const changedFiles = await getPRChangedFiles(octokit, thisRepo, issue.number)
9098

0 commit comments

Comments
 (0)