Skip to content

Commit

Permalink
refactor(ng-dev): move all AuthenticatedGitClient configuration to be…
Browse files Browse the repository at this point in the history
… through single configure function (#180)

PR Close #180
  • Loading branch information
josephperrott committed Aug 27, 2021
1 parent c76f891 commit 1663ae9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 36 deletions.
12 changes: 9 additions & 3 deletions github-actions/slash-commands/lib/commands/rebase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,19 @@ import {Octokit} from '@octokit/rest';
import {context} from '@actions/github';
import {getAuthTokenFor, ANGULAR_ROBOT} from '../../../utils';
import {AuthenticatedGitClient} from '../../../../ng-dev/utils/git/authenticated-git-client';
import {setConfig} from '../../../../ng-dev/utils/config';

export async function rebase() {
const token = await getAuthTokenFor(ANGULAR_ROBOT);
const {owner, repo: name} = context.repo;
const mainBranchName = context.payload.repository!.default_branch;
setConfig({
github: {
name: context.repo.repo,
owner: context.repo.owner,
mainBranchName: context.payload.repository!.default_branch,
},
});

AuthenticatedGitClient.configureForGithubActions(token, {github: {name, owner, mainBranchName}});
AuthenticatedGitClient.configure(token);

if ((await rebasePr(context.issue.number, token)) !== 0) {
// For any failure to rebase, comment on the PR informing the user a rebase was unable to be
Expand Down
29 changes: 15 additions & 14 deletions github-actions/slash-commands/main.js

Large diffs are not rendered by default.

19 changes: 0 additions & 19 deletions ng-dev/utils/git/authenticated-git-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,25 +127,6 @@ export class AuthenticatedGitClient extends GitClient {
'Unable to configure `AuthenticatedGitClient` as it has been configured already.',
);
}
if (process.env['GITHUB_ACTIONS']) {
throw Error(
'Cannot use `configure` static method to create AuthenticatedGitClient in a Github Action.',
);
}
AuthenticatedGitClient._authenticatedInstance = new AuthenticatedGitClient(token);
}

/** Configures an authenticated git client in the context of a Github action. */
static configureForGithubActions(token: string, config: {github: GithubConfig}): void {
if (AuthenticatedGitClient._authenticatedInstance) {
throw Error(
'Unable to configure `AuthenticatedGitClient` as it has been configured already.',
);
}
AuthenticatedGitClient._authenticatedInstance = new AuthenticatedGitClient(
token,
undefined,
config,
);
}
}

0 comments on commit 1663ae9

Please sign in to comment.