-
Notifications
You must be signed in to change notification settings - Fork 70
feat(github-actions): remove preview label for non-googlers in pack-and-upload-artifact #3718
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
josephperrott
merged 3 commits into
angular:main
from
josephperrott:remove-preview-label-googlers
Jun 3, 2026
+25,476
−0
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
08c76be
feat(github-actions): remove preview label for non-googlers in pack-a…
josephperrott d079148
refactor(github-actions): address PR feedback on remove-preview-label
josephperrott e4be405
refactor(github-actions): pass angular-robot-key via env to avoid CLI…
josephperrott File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 122 additions & 0 deletions
122
github-actions/previews/pack-and-upload-artifact/lib/remove-preview-label.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| /** | ||
| * @license | ||
| * Copyright Google LLC | ||
| * | ||
| * Use of this source code is governed by an MIT-style license that can be | ||
| * found in the LICENSE file at https://angular.io/license | ||
| */ | ||
|
|
||
| import * as core from '@actions/core'; | ||
| import {Octokit} from '@octokit/rest'; | ||
| import {ANGULAR_ROBOT, getAuthTokenFor, revokeActiveInstallationToken} from '../../../utils.js'; | ||
|
|
||
| async function main() { | ||
| const [pullNumberRaw, labelName] = process.argv.slice(2); | ||
| const pullNumber = Number(pullNumberRaw); | ||
|
|
||
| if (isNaN(pullNumber)) { | ||
| throw new Error(`Invalid pull request number: ${pullNumberRaw}`); | ||
| } | ||
|
|
||
| let repoClient: Octokit | null = null; | ||
| let googlersOrgClient: Octokit | null = null; | ||
|
|
||
| try { | ||
| const [owner, repo] = process.env.GITHUB_REPOSITORY!.split('/', 2); | ||
|
|
||
| // Authenticate using the Angular Robot app for the repository | ||
| const repoToken = await getAuthTokenFor(ANGULAR_ROBOT, {owner, repo}); | ||
| repoClient = new Octokit({auth: repoToken}); | ||
|
|
||
| // Get pull request details to find the author | ||
| const pr = await repoClient.pulls.get({ | ||
| owner, | ||
| repo, | ||
| pull_number: pullNumber, | ||
| }); | ||
| const author = pr.data.user.login; | ||
|
|
||
| core.info(`PR #${pullNumber} author is: ${author}`); | ||
|
josephperrott marked this conversation as resolved.
|
||
|
|
||
| // Authenticate using the Angular Robot app for the googlers organization | ||
| const googlersOrgToken = await getGooglersOrgInstallationToken(); | ||
| if (googlersOrgToken === null) { | ||
| throw new Error('Could not retrieve installation token for `googlers` org.'); | ||
| } | ||
| googlersOrgClient = new Octokit({auth: googlersOrgToken}); | ||
|
|
||
| const isMember = await isGooglerOrgMember(googlersOrgClient, author); | ||
|
|
||
| if (isMember) { | ||
| core.info(`PR author ${author} is a member of the googlers organization.`); | ||
| return; | ||
| } | ||
|
josephperrott marked this conversation as resolved.
|
||
|
|
||
| core.info(`PR author ${author} is NOT a member of the googlers organization.`); | ||
|
|
||
| // Check if the label is present on the PR before attempting to remove it | ||
| const labels = pr.data.labels.map((l) => l.name); | ||
| if (!labels.includes(labelName)) { | ||
| core.info(`Label "${labelName}" is not present on the PR.`); | ||
| return; | ||
| } | ||
|
josephperrott marked this conversation as resolved.
|
||
|
|
||
| core.info(`Removing label "${labelName}" from PR #${pullNumber}...`); | ||
| await repoClient.issues.removeLabel({ | ||
| owner, | ||
| repo, | ||
| issue_number: pullNumber, | ||
| name: labelName, | ||
| }); | ||
| core.info(`Successfully removed label "${labelName}"`); | ||
|
josephperrott marked this conversation as resolved.
|
||
| } finally { | ||
| if (googlersOrgClient !== null) { | ||
| try { | ||
| await revokeActiveInstallationToken(googlersOrgClient); | ||
| } catch (e) { | ||
| core.error(`Failed to revoke googlers org token: ${e}`); | ||
| } | ||
| } | ||
| if (repoClient !== null) { | ||
| try { | ||
| await revokeActiveInstallationToken(repoClient); | ||
| } catch (e) { | ||
| core.error(`Failed to revoke repo token: ${e}`); | ||
| } | ||
| } | ||
| } | ||
|
josephperrott marked this conversation as resolved.
|
||
| } | ||
|
|
||
| async function getGooglersOrgInstallationToken(): Promise<string | null> { | ||
| try { | ||
| return await getAuthTokenFor(ANGULAR_ROBOT, { | ||
| org: 'googlers', | ||
| }); | ||
| } catch (e) { | ||
| core.error('Could not retrieve installation token for `googlers` org.'); | ||
| core.error(e as Error); | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| const isGooglerOrgMemberCache = new Map<string, boolean>(); | ||
|
|
||
| async function isGooglerOrgMember(client: Octokit, username: string): Promise<boolean> { | ||
| if (isGooglerOrgMemberCache.has(username)) { | ||
| return isGooglerOrgMemberCache.get(username)!; | ||
| } | ||
| return await client.orgs | ||
| .checkMembershipForUser({org: 'googlers', username}) | ||
| .then( | ||
| ({status}) => (status as number) === 204, | ||
| () => false, | ||
| ) | ||
| .then((result) => { | ||
| isGooglerOrgMemberCache.set(username, result); | ||
| return result; | ||
| }); | ||
| } | ||
|
josephperrott marked this conversation as resolved.
|
||
|
|
||
| main().catch((e) => { | ||
| core.setFailed(e.message); | ||
| }); | ||
2 changes: 2 additions & 0 deletions
2
github-actions/previews/pack-and-upload-artifact/package.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| { | ||
| "dependencies": { | ||
| "@actions/core": "3.0.1", | ||
| "@octokit/rest": "22.0.1", | ||
| "@types/node": "24.12.4" | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.