@@ -14,7 +14,7 @@ async function run() {
14
14
}
15
15
16
16
// Merge if they say they have access
17
- if ( context . eventName === "issue_comment" ) {
17
+ if ( context . eventName === "issue_comment" || context . eventName === "pull_request_review" ) {
18
18
mergeIfLGTMAndHasAccess ( )
19
19
}
20
20
}
@@ -33,12 +33,7 @@ async function commentOnMergablePRs() {
33
33
core . info ( `\n\nLooking at PR: '${ pr . title } ' for codeowners` )
34
34
35
35
const changedFiles = await getPRChangedFiles ( octokit , thisRepo , pr . number )
36
- console . log ( "changed files" , changedFiles )
37
36
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 )
42
37
43
38
if ( ! codeowners . length ) {
44
39
console . log ( "This PR does not have any code-owners" )
@@ -50,7 +45,7 @@ async function commentOnMergablePRs() {
50
45
codeowners . forEach ( owner => {
51
46
const filesWhichArentOwned = getFilesNotOwnedByCodeOwner ( owner , changedFiles , cwd )
52
47
if ( filesWhichArentOwned . length === 0 ) ownersWhoHaveAccessToAllFilesInPR . push ( owner )
53
- } ) ;
48
+ } )
54
49
55
50
if ( ! ownersWhoHaveAccessToAllFilesInPR . length ) {
56
51
console . log ( "This PR does not have any code-owners who own all of the files in the PR" )
@@ -76,11 +71,12 @@ ${ourSignature}`
76
71
77
72
78
73
async function mergeIfLGTMAndHasAccess ( ) {
79
- if ( context . eventName !== "issue_comment" ) {
74
+ if ( context . eventName !== "issue_comment" && context . eventName !== "pull_request_review" ) {
80
75
throw new Error ( "This GH action can only run when the workflow specifies `pull_request_target` in the `on:`." )
81
76
}
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" ) ) {
84
80
console . log ( "Comment does not include LGTM ('looks good to me') so not merging" )
85
81
process . exit ( 0 )
86
82
}
@@ -90,13 +86,13 @@ async function mergeIfLGTMAndHasAccess() {
90
86
const cwd = "."
91
87
const octokit = getOctokit ( process . env . GITHUB_TOKEN )
92
88
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
94
90
95
91
core . info ( `\n\nLooking at PR: ${ issue . title } to see if we can merge` )
96
92
97
93
const changedFiles = await getPRChangedFiles ( octokit , thisRepo , issue . number )
98
94
99
- const filesWhichArentOwned = getFilesNotOwnedByCodeOwner ( "@" + issue . user . login , changedFiles , cwd )
95
+ const filesWhichArentOwned = getFilesNotOwnedByCodeOwner ( "@" + context . payload . sender . login , changedFiles , cwd )
100
96
if ( filesWhichArentOwned . length !== 0 ) {
101
97
const missing = new Intl . ListFormat ( ) . format ( filesWhichArentOwned ) ;
102
98
0 commit comments