@@ -12,21 +12,17 @@ async function main() {
1212 let googlersOrgClient : Octokit | null = null ;
1313
1414 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.
2515 const repoToken = await getAuthTokenFor ( ANGULAR_ROBOT , context . repo ) ;
16+ const googlersOrgToken = await getGooglersOrgInstallationToken ( ) ;
17+
2618 // TODO: remove once GHA supports node18 as a target runner for Javascript action
2719 repoClient = new Octokit ( { auth : repoToken , request : { fetch} } ) ;
2820
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 ) ;
3026 } finally {
3127 if ( googlersOrgClient !== null ) {
3228 await revokeActiveInstallationToken ( googlersOrgClient ) ;
@@ -37,8 +33,23 @@ async function main() {
3733 }
3834}
3935
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+
4051async function runPostApprovalChangesAction (
41- googlersOrgClient : Octokit ,
52+ membershipCheckClient : Octokit ,
4253 repoClient : Octokit ,
4354) : Promise < void > {
4455 if ( context . eventName !== 'pull_request_target' ) {
@@ -48,7 +59,7 @@ async function runPostApprovalChangesAction(
4859
4960 const actionUser = context . actor ;
5061
51- if ( await isGooglerOrgMember ( googlersOrgClient , actionUser ) ) {
62+ if ( await isGooglerOrgMember ( membershipCheckClient , actionUser ) ) {
5263 core . info (
5364 'Action performed by an account in the Googler Github Org, skipping as post approval changes are allowed.' ,
5465 ) ;
@@ -94,7 +105,7 @@ async function runPostApprovalChangesAction(
94105 continue ;
95106 }
96107 // Only consider reviews by Googlers for this check.
97- if ( ! ( await isGooglerOrgMember ( googlersOrgClient , user ) ) ) {
108+ if ( ! ( await isGooglerOrgMember ( membershipCheckClient , user ) ) ) {
98109 continue ;
99110 }
100111 knownReviewers . add ( user ) ;
@@ -157,6 +168,7 @@ async function isGooglerOrgMember(client: Octokit, username: string): Promise<bo
157168if ( context . repo . owner === 'angular' ) {
158169 main ( ) . catch ( ( e : Error ) => {
159170 console . error ( e ) ;
171+ console . error ( e . stack ) ;
160172 core . setFailed ( e . message ) ;
161173 } ) ;
162174} else {
0 commit comments