@@ -12,21 +12,17 @@ async function main() {
12
12
let googlersOrgClient : Octokit | null = null ;
13
13
14
14
try {
15
- // Use the `.github` repo from googlers to get an installation that has access to the googlers
16
- // user membership.
17
- const googlersOrgToken = await getAuthTokenFor ( ANGULAR_ROBOT , {
18
- owner : 'googlers' ,
19
- repo : '.github' ,
20
- } ) ;
21
- googlersOrgClient = new Octokit ( { auth : googlersOrgToken } ) ;
22
-
23
- // Use the `.github` repo from googlers to get an installation that has access to the googlers
24
- // user membership.
25
15
const repoToken = await getAuthTokenFor ( ANGULAR_ROBOT , context . repo ) ;
16
+ const googlersOrgToken = await getGooglersOrgInstallationToken ( ) ;
17
+
26
18
// TODO: remove once GHA supports node18 as a target runner for Javascript action
27
19
repoClient = new Octokit ( { auth : repoToken , request : { fetch} } ) ;
28
20
29
- await runPostApprovalChangesAction ( googlersOrgClient , repoClient ) ;
21
+ if ( googlersOrgToken !== null ) {
22
+ googlersOrgClient = new Octokit ( { auth : googlersOrgToken , request : { fetch} } ) ;
23
+ }
24
+
25
+ await runPostApprovalChangesAction ( googlersOrgClient ?? repoClient , repoClient ) ;
30
26
} finally {
31
27
if ( googlersOrgClient !== null ) {
32
28
await revokeActiveInstallationToken ( googlersOrgClient ) ;
@@ -37,8 +33,23 @@ async function main() {
37
33
}
38
34
}
39
35
36
+ async function getGooglersOrgInstallationToken ( ) : Promise < string | null > {
37
+ try {
38
+ // Use the `.github` repo from googlers to get an installation that has access to the googlers
39
+ // user membership.
40
+ return await getAuthTokenFor ( ANGULAR_ROBOT , {
41
+ org : 'googlers' ,
42
+ } ) ;
43
+ } catch ( e ) {
44
+ console . error ( 'Could not retrieve installation token for `googlers` org.' ) ;
45
+ console . error ( e ) ;
46
+ }
47
+
48
+ return null ;
49
+ }
50
+
40
51
async function runPostApprovalChangesAction (
41
- googlersOrgClient : Octokit ,
52
+ membershipCheckClient : Octokit ,
42
53
repoClient : Octokit ,
43
54
) : Promise < void > {
44
55
if ( context . eventName !== 'pull_request_target' ) {
@@ -48,7 +59,7 @@ async function runPostApprovalChangesAction(
48
59
49
60
const actionUser = context . actor ;
50
61
51
- if ( await isGooglerOrgMember ( googlersOrgClient , actionUser ) ) {
62
+ if ( await isGooglerOrgMember ( membershipCheckClient , actionUser ) ) {
52
63
core . info (
53
64
'Action performed by an account in the Googler Github Org, skipping as post approval changes are allowed.' ,
54
65
) ;
@@ -94,7 +105,7 @@ async function runPostApprovalChangesAction(
94
105
continue ;
95
106
}
96
107
// Only consider reviews by Googlers for this check.
97
- if ( ! ( await isGooglerOrgMember ( googlersOrgClient , user ) ) ) {
108
+ if ( ! ( await isGooglerOrgMember ( membershipCheckClient , user ) ) ) {
98
109
continue ;
99
110
}
100
111
knownReviewers . add ( user ) ;
@@ -157,6 +168,7 @@ async function isGooglerOrgMember(client: Octokit, username: string): Promise<bo
157
168
if ( context . repo . owner === 'angular' ) {
158
169
main ( ) . catch ( ( e : Error ) => {
159
170
console . error ( e ) ;
171
+ console . error ( e . stack ) ;
160
172
core . setFailed ( e . message ) ;
161
173
} ) ;
162
174
} else {
0 commit comments