Currently the `GitClient` accepts a generic parameter for determining
whether the `githubToken` should be set or not. This worked fine so far
in terms of distinguishing between an authenticated and
non-authenticated git client instance, but if we intend to conditionally
show methods only for authenticated instances, the generic parameter
is not suitable.
This commit splits up the `GitClient` into two classes. One for
the base logic without any authorization, and a second class that
extends the base logic with authentication logic. i.e. the
`AuthenticatedGitClient`. This allows us to have specific methods only
for the authenticated instance. e.g.
* `hasOauthScopes` has been moved to only exist for authenticated
instances.
* the GraphQL functionality within `gitClient.github` is not
accessible for non-authenticated instances. GraphQL API requires
authentication as per Github.
The initial motiviation for this was that we want to throw if
`hasOAuthScopes` is called without the Octokit instance having
a token configured. This should help avoiding issues as within
3b434ed94d
that prevented the caretaker process momentarily.
Additionally, the Git client has moved from `index.ts` to
`git-client.ts` for better discoverability in the codebase.
PR Close #42468
60 lines
1.9 KiB
TypeScript
60 lines
1.9 KiB
TypeScript
/**
|
|
* @license
|
|
* Copyright Google LLC All Rights Reserved.
|
|
*
|
|
* 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 {Arguments, Argv, CommandModule} from 'yargs';
|
|
|
|
import {getConfig} from '../../utils/config';
|
|
import {error, green, info, red, yellow} from '../../utils/console';
|
|
import {GitClient} from '../../utils/git/git-client';
|
|
import {addGithubTokenOption} from '../../utils/git/github-yargs';
|
|
import {getReleaseConfig} from '../config/index';
|
|
|
|
import {CompletionState, ReleaseTool} from './index';
|
|
|
|
/** Command line options for publishing a release. */
|
|
export interface ReleasePublishOptions {
|
|
githubToken: string;
|
|
}
|
|
|
|
/** Yargs command builder for configuring the `ng-dev release publish` command. */
|
|
function builder(argv: Argv): Argv<ReleasePublishOptions> {
|
|
return addGithubTokenOption(argv);
|
|
}
|
|
|
|
/** Yargs command handler for staging a release. */
|
|
async function handler() {
|
|
const git = GitClient.get();
|
|
const config = getConfig();
|
|
const releaseConfig = getReleaseConfig(config);
|
|
const projectDir = git.baseDir;
|
|
const task = new ReleaseTool(releaseConfig, config.github, projectDir);
|
|
const result = await task.run();
|
|
|
|
switch (result) {
|
|
case CompletionState.FATAL_ERROR:
|
|
error(red(`Release action has been aborted due to fatal errors. See above.`));
|
|
process.exitCode = 2;
|
|
break;
|
|
case CompletionState.MANUALLY_ABORTED:
|
|
info(yellow(`Release action has been manually aborted.`));
|
|
process.exitCode = 1;
|
|
break;
|
|
case CompletionState.SUCCESS:
|
|
info(green(`Release action has completed successfully.`));
|
|
break;
|
|
}
|
|
}
|
|
|
|
/** CLI command module for publishing a release. */
|
|
export const ReleasePublishCommandModule: CommandModule<{}, ReleasePublishOptions> = {
|
|
builder,
|
|
handler,
|
|
command: 'publish',
|
|
describe: 'Publish new releases and configure version branches.',
|
|
};
|