豆豆友情提示:这是一个非官方 GitHub 代理镜像,主要用于网络测试或访问加速。请勿在此进行登录、注册或处理任何敏感信息。进行这些操作请务必访问官方网站 github.com。 Raw 内容也通过此代理提供。
Skip to content

Commit 8d1d6c5

Browse files
committed
fix(ng-dev): properly handle github token escapes with ng-dev service auth (#774)
We now correctly handle when the github-escape-hatch is used and don't always assume that a github token should be checked for. PR Close #774
1 parent 0bb6369 commit 8d1d6c5

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed

github-actions/slash-commands/main.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70153,7 +70153,7 @@ async function fetchPullRequestFromGithub(git, prNumber) {
7015370153
}
7015470154

7015570155
//
70156-
async function rebasePr(prNumber, githubToken) {
70156+
async function rebasePr(prNumber) {
7015770157
const git = await AuthenticatedGitClient.get();
7015870158
if (git.hasUncommittedChanges()) {
7015970159
Log.error("Cannot perform rebase of PR with local changes.");
@@ -70169,8 +70169,8 @@ async function rebasePr(prNumber, githubToken) {
7016970169
const baseRefName = pr.baseRef.name;
7017070170
const fullHeadRef = `${pr.headRef.repository.nameWithOwner}:${headRefName}`;
7017170171
const fullBaseRef = `${pr.baseRef.repository.nameWithOwner}:${baseRefName}`;
70172-
const headRefUrl = addTokenToGitHttpsUrl(pr.headRef.repository.url, githubToken);
70173-
const baseRefUrl = addTokenToGitHttpsUrl(pr.baseRef.repository.url, githubToken);
70172+
const headRefUrl = addTokenToGitHttpsUrl(pr.headRef.repository.url, git.githubToken);
70173+
const baseRefUrl = addTokenToGitHttpsUrl(pr.baseRef.repository.url, git.githubToken);
7017470174
const forceWithLeaseFlag = `--force-with-lease=${headRefName}:${pr.headRefOid}`;
7017570175
if (!pr.maintainerCanModify && !pr.viewerDidAuthor) {
7017670176
Log.error(`Cannot rebase as you did not author the PR and the PR does not allow maintainersto modify the PR`);
@@ -70229,7 +70229,7 @@ async function rebase(installationClient, installationToken) {
7022970229
}
7023070230
});
7023170231
AuthenticatedGitClient.configure(installationToken);
70232-
if (await rebasePr(import_github5.context.issue.number, installationToken) !== 0) {
70232+
if (await rebasePr(import_github5.context.issue.number) !== 0) {
7023370233
await installationClient.issues.createComment({
7023470234
...import_github5.context.repo,
7023570235
issue_number: import_github5.context.issue.number,

ng-dev/utils/ng-dev-service.ts

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
restoreNgTokenFromDiskIfValid,
1616
} from '../auth/shared/ng-dev-token.js';
1717
import {assertValidGithubConfig, getConfig} from './config.js';
18-
import {addGithubTokenOption} from './git/github-yargs.js';
18+
import {configureGitClientWithTokenOrFromEnvironment} from './git/github-yargs.js';
1919
import {Log} from './logging.js';
2020

2121
/** Configuration for the firebase application used for ng-dev token management. */
@@ -48,15 +48,19 @@ export async function useNgDevService<T>(
4848
}
4949

5050
return (
51-
addGithubTokenOption(argv)
51+
argv
5252
// TODO(josephperrott): remove once stability is validated.
5353
.option('github-escape-hatch' as 'githubEscapeHatch', {
5454
type: 'boolean',
55-
default: false,
55+
hidden: true,
56+
})
57+
.option('github-token' as 'githubToken', {
58+
type: 'string',
59+
implies: 'github-escape-hatch',
5660
hidden: true,
5761
})
5862
.middleware(
59-
async (args: Arguments<T & {githubToken: string | null; githubEscapeHatch: boolean}>) => {
63+
async (args: Arguments<T & {githubToken?: string; githubEscapeHatch?: boolean}>) => {
6064
// TODO(josephperrott): remove this guard against running multiple times after
6165
// https://github.com/yargs/yargs/issues/2223 is fixed
6266
if (ngDevServiceMiddlewareHasRun) {
@@ -67,17 +71,17 @@ export async function useNgDevService<T>(
6771
initializeApp(firebaseConfig);
6872
await restoreNgTokenFromDiskIfValid();
6973

70-
if (args.githubEscapeHatch === true) {
71-
Log.warn('This escape hatch should only be used if the service is erroring. Please');
72-
Log.warn(
73-
'inform #dev-infra of the need to use this escape hatch so it can be triaged.',
74-
);
74+
if (isAuthCommand) {
75+
Log.debug('Skipping ng-dev token request as this is an auth command');
7576
return;
7677
}
77-
args.githubToken = null;
7878

79-
if (isAuthCommand) {
80-
Log.debug('Skipping ng-dev token request as this is an auth command');
79+
if (args.githubEscapeHatch === true) {
80+
// Use the configuration helper to set up the GithubClient using the provided auth
81+
// token or environment.
82+
configureGitClientWithTokenOrFromEnvironment(args.githubToken);
83+
Log.warn('This escape hatch should only be used if the service is erroring. Please');
84+
Log.warn('inform #dev-infra of using this escape hatch so it can be triaged.');
8185
return;
8286
}
8387

0 commit comments

Comments
 (0)