Skip to content

Commit 4a75ebf

Browse files
committed
Try run less
1 parent 67d9bb6 commit 4a75ebf

File tree

3 files changed

+15
-18
lines changed

3 files changed

+15
-18
lines changed

.github/workflows/code-owners-merge.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
name: Codeowners merging
22
on:
3-
pull_request_target:
3+
pull_request_target: { types: opened }
44
issue_comment: { types: created }
5+
pull_request_review: { types: submitted }
56

67
jobs:
78
build:

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ jobs:
4343
runs-on: ubuntu-latest
4444

4545
steps:
46-
- uses: actions/checkout@v1
47-
- name: Run Codeowners merge check
48-
env:
49-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
50-
uses: orta/code-owner-self-merge@v1
46+
- uses: actions/checkout@v1
47+
- name: Run Codeowners merge check
48+
env:
49+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
50+
uses: orta/code-owner-self-merge@v1
5151
```
5252
5353
Then you should be good to go.

index.js

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ async function run() {
1414
}
1515

1616
// Merge if they say they have access
17-
if (context.eventName === "issue_comment") {
17+
if (context.eventName === "issue_comment" || context.eventName === "pull_request_review") {
1818
mergeIfLGTMAndHasAccess()
1919
}
2020
}
@@ -33,12 +33,7 @@ async function commentOnMergablePRs() {
3333
core.info(`\n\nLooking at PR: '${pr.title}' for codeowners`)
3434

3535
const changedFiles = await getPRChangedFiles(octokit, thisRepo, pr.number)
36-
console.log("changed files", changedFiles)
3736
const codeowners = findCodeOwnersForChangedFiles(changedFiles, cwd)
38-
console.log("owners for PR", codeowners)
39-
40-
const co = new Codeowners(cwd);
41-
console.log(co.codeownersFilePath, co.codeownersDirectory)
4237

4338
if (!codeowners.length) {
4439
console.log("This PR does not have any code-owners")
@@ -50,7 +45,7 @@ async function commentOnMergablePRs() {
5045
codeowners.forEach(owner => {
5146
const filesWhichArentOwned = getFilesNotOwnedByCodeOwner(owner, changedFiles, cwd)
5247
if (filesWhichArentOwned.length === 0) ownersWhoHaveAccessToAllFilesInPR.push(owner)
53-
});
48+
})
5449

5550
if(!ownersWhoHaveAccessToAllFilesInPR.length) {
5651
console.log("This PR does not have any code-owners who own all of the files in the PR")
@@ -76,11 +71,12 @@ ${ourSignature}`
7671

7772

7873
async function mergeIfLGTMAndHasAccess() {
79-
if (context.eventName !== "issue_comment") {
74+
if (context.eventName !== "issue_comment" && context.eventName !== "pull_request_review") {
8075
throw new Error("This GH action can only run when the workflow specifies `pull_request_target` in the `on:`.")
8176
}
82-
console.log("body", context.payload.comment.body.toLowerCase())
83-
if (!context.payload.comment.body.toLowerCase().includes("lgtm")) {
77+
78+
const body = context.payload.comment ? context.payload.comment.body : context.payload.review.body
79+
if (!body.toLowerCase().includes("lgtm")) {
8480
console.log("Comment does not include LGTM ('looks good to me') so not merging")
8581
process.exit(0)
8682
}
@@ -90,13 +86,13 @@ async function mergeIfLGTMAndHasAccess() {
9086
const cwd = "."
9187
const octokit = getOctokit(process.env.GITHUB_TOKEN)
9288
const thisRepo = { owner: context.repo.owner, repo: context.repo.repo }
93-
const issue = context.payload.issue
89+
const issue = context.payload.issue || context.payload.pull_request
9490

9591
core.info(`\n\nLooking at PR: ${issue.title} to see if we can merge`)
9692

9793
const changedFiles = await getPRChangedFiles(octokit, thisRepo, issue.number)
9894

99-
const filesWhichArentOwned = getFilesNotOwnedByCodeOwner("@" + issue.user.login, changedFiles, cwd)
95+
const filesWhichArentOwned = getFilesNotOwnedByCodeOwner("@" + context.payload.sender.login, changedFiles, cwd)
10096
if (filesWhichArentOwned.length !== 0) {
10197
const missing = new Intl.ListFormat().format(filesWhichArentOwned);
10298

0 commit comments

Comments
 (0)