Skip to content
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

fix(github-actions): properly pass auth token to octokit #897

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 3 additions & 10 deletions github-actions/branch-manager/lib/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,6 @@ function createWorkflowForPullRequest(prInfo?: Partial<WorkflowInputs>) {
console.info(`Requesting workflow run for: ${JSON.stringify(inputs)}`);
return github().then((api) =>
api.actions.createWorkflowDispatch({
headers: {
// Github requires the authorization to be `token <token>` for this endpoint instead of the
// standard `Bearer <token>`.
'authorization': `token ${token}`,
},
owner: 'angular',
repo: 'dev-infra',
ref: 'main',
Expand All @@ -85,15 +80,13 @@ function createWorkflowForPullRequest(prInfo?: Partial<WorkflowInputs>) {
);
}

/** The authorization token for the Github app. */
let token: string;
/** The Octokit instance, if defined to allow token revokation after the action executes. */
/** The Octokit instance, if defined to allow token revocation after the action executes. */
let _github: Octokit | null = null;
/** Get the shared instance of Octokit, first creating the instance if necessary. */
async function github() {
if (_github === null) {
token = await getAuthTokenFor(ANGULAR_ROBOT);
_github = new Octokit({token});
const token = await getAuthTokenFor(ANGULAR_ROBOT);
_github = new Octokit({auth: token});
}
return _github;
}
Expand Down
Loading