Skip to content

Commit 7c87273

Browse files
josephperrottdevversion
authored andcommitted
refactor: move to using assertions in place to determine the types of a configuration for the github config
1 parent 62acc14 commit 7c87273

File tree

27 files changed

+123
-110
lines changed

27 files changed

+123
-110
lines changed

ng-dev/caretaker/check/base.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {NgDevConfig} from '../../utils/config';
9+
import {GitClientConfig} from '../../utils/config';
1010
import {AuthenticatedGitClient} from '../../utils/git/authenticated-git-client';
1111
import {CaretakerConfig} from '../config';
1212

@@ -17,7 +17,7 @@ export abstract class BaseModule<Data> {
1717
/** The data for the module. */
1818
readonly data = this.retrieveData();
1919

20-
constructor(protected config: NgDevConfig<{caretaker: CaretakerConfig}>) {}
20+
constructor(protected config: {caretaker: CaretakerConfig; github: GitClientConfig}) {}
2121

2222
/** Asyncronously retrieve data for the module. */
2323
protected abstract retrieveData(): Promise<Data>;

ng-dev/caretaker/check/check.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9+
import {assertValidGithubConfig} from '../../utils/config';
910
import {getCaretakerConfig} from '../config';
1011

1112
import {CiModule} from './ci';
@@ -20,6 +21,7 @@ const moduleList = [GithubQueriesModule, ServicesModule, CiModule, G3Module];
2021
export async function checkServiceStatuses() {
2122
/** The configuration for the caretaker commands. */
2223
const config = getCaretakerConfig();
24+
assertValidGithubConfig(config);
2325
/** List of instances of Caretaker Check modules */
2426
const caretakerCheckModules = moduleList.map((module) => new module(config));
2527

ng-dev/caretaker/config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {assertNoErrors, getConfig, NgDevConfig} from '../utils/config';
9+
import {assertNoErrors, getConfig} from '../utils/config';
1010

1111
export interface CaretakerConfig {
1212
/** Github queries showing a snapshot of pulls/issues caretakers need to monitor. */
@@ -23,7 +23,7 @@ export function getCaretakerConfig() {
2323
// List of errors encountered validating the config.
2424
const errors: string[] = [];
2525
// The non-validated config object.
26-
const config: Partial<NgDevConfig<{caretaker: CaretakerConfig}>> = getConfig();
26+
const config: Partial<{caretaker: CaretakerConfig}> = getConfig();
2727

2828
assertNoErrors(errors);
2929
return config as Required<typeof config>;

ng-dev/commit-message/config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {assertNoErrors, getConfig, NgDevConfig} from '../utils/config';
9+
import {assertNoErrors, getConfig} from '../utils/config';
1010

1111
/** Configuration for commit-message comands. */
1212
export interface CommitMessageConfig {
@@ -21,7 +21,7 @@ export function getCommitMessageConfig() {
2121
// List of errors encountered validating the config.
2222
const errors: string[] = [];
2323
// The non-validated config object.
24-
const config: Partial<NgDevConfig<{commitMessage: CommitMessageConfig}>> = getConfig();
24+
const config: Partial<{commitMessage: CommitMessageConfig}> = getConfig();
2525

2626
if (config.commitMessage === undefined) {
2727
errors.push(`No configuration defined for "commitMessage"`);

ng-dev/format/config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {assertNoErrors, getConfig, NgDevConfig} from '../utils/config';
9+
import {assertNoErrors, getConfig} from '../utils/config';
1010

1111
interface Formatter {
1212
matchers: string[];
@@ -21,7 +21,7 @@ export function getFormatConfig() {
2121
// List of errors encountered validating the config.
2222
const errors: string[] = [];
2323
// The unvalidated config object.
24-
const config: Partial<NgDevConfig<{format: FormatConfig}>> = getConfig();
24+
const config: Partial<{format: FormatConfig}> = getConfig();
2525

2626
if (config.format === undefined) {
2727
errors.push(`No configuration defined for "format"`);

ng-dev/pr/check-target-branches/check-target-branches.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {getConfig} from '../../utils/config';
9+
import {assertValidGithubConfig, getConfig} from '../../utils/config';
1010
import {error, info, red} from '../../utils/console';
1111
import {GitClient} from '../../utils/git/git-client';
1212
import {loadAndValidateConfig, TargetLabel} from '../merge/config';
@@ -19,6 +19,7 @@ import {
1919
export async function getTargetBranchesForPr(prNumber: number) {
2020
/** The ng-dev configuration. */
2121
const config = getConfig();
22+
assertValidGithubConfig(config);
2223
/** Repo owner and name for the github repository. */
2324
const {owner, name: repo} = config.github;
2425
/** The singleton instance of the GitClient. */

ng-dev/pr/merge/config.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {GitClientConfig, NgDevConfig} from '../../utils/config';
9+
import {GitClientConfig} from '../../utils/config';
1010
import {GithubClient} from '../../utils/git/github';
1111

1212
import {GithubApiMergeStrategyConfig} from './strategies/api-merge';
@@ -84,9 +84,10 @@ export interface MergeConfig {
8484
* on branch name computations. We don't want to run these immediately whenever
8585
* the dev-infra configuration is loaded as that could slow-down other commands.
8686
*/
87-
export type DevInfraMergeConfig = NgDevConfig<{
88-
'merge': (api: GithubClient) => MergeConfig | Promise<MergeConfig>;
89-
}>;
87+
export type DevInfraMergeConfig = {
88+
github: GitClientConfig;
89+
merge: (api: GithubClient) => MergeConfig | Promise<MergeConfig>;
90+
};
9091

9192
/** Loads and validates the merge configuration. */
9293
export async function loadAndValidateConfig(

ng-dev/pr/merge/defaults/integration.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {ParsedUrlQuery} from 'querystring';
1111

1212
import {ReleaseConfig} from '../../../release/config/index';
1313
import {_npmPackageInfoCache, NpmPackageInfo} from '../../../release/versioning/npm-registry';
14-
import {GithubConfig} from '../../../utils/config';
14+
import {GitClientConfig} from '../../../utils/config';
1515
import * as console from '../../../utils/console';
1616
import {GithubClient} from '../../../utils/git/github';
1717
import {buildGithubPaginationResponseHeader} from '../../../utils/testing/github-pagination-header';
@@ -25,7 +25,7 @@ const API_ENDPOINT = `https://api.github.com`;
2525

2626
describe('default target labels', () => {
2727
let api: GithubClient;
28-
let githubConfig: GithubConfig;
28+
let githubConfig: GitClientConfig;
2929
let releaseConfig: ReleaseConfig;
3030

3131
beforeEach(() => {

ng-dev/pr/merge/defaults/labels.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
isVersionBranch,
1414
ReleaseRepoWithApi,
1515
} from '../../../release/versioning';
16-
import {GithubConfig} from '../../../utils/config';
16+
import {GitClientConfig} from '../../../utils/config';
1717
import {GithubClient} from '../../../utils/git/github';
1818
import {TargetLabel} from '../config';
1919
import {InvalidTargetBranchError, InvalidTargetLabelError} from '../target-label';
@@ -34,7 +34,7 @@ import {assertActiveLtsBranch} from './lts-branch';
3434
*/
3535
export async function getDefaultTargetLabelConfiguration(
3636
api: GithubClient,
37-
githubConfig: GithubConfig,
37+
githubConfig: GitClientConfig,
3838
releaseConfig: ReleaseConfig,
3939
): Promise<TargetLabel[]> {
4040
const nextBranchName = getNextBranchName(githubConfig);

ng-dev/pr/merge/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {getConfig} from '../../utils/config';
9+
import {assertValidGithubConfig, getConfig} from '../../utils/config';
1010
import {error, green, info, promptConfirm, red, yellow} from '../../utils/console';
1111
import {AuthenticatedGitClient} from '../../utils/git/authenticated-git-client';
1212
import {GithubApiRequestError} from '../../utils/git/github';
@@ -130,6 +130,7 @@ export async function mergePullRequest(prNumber: number, flags: PullRequestMerge
130130
*/
131131
async function createPullRequestMergeTask(flags: PullRequestMergeTaskFlags) {
132132
const devInfraConfig = getConfig();
133+
assertValidGithubConfig(devInfraConfig);
133134
/** The singleton instance of the authenticated git client. */
134135
const git = AuthenticatedGitClient.get();
135136
const {config, errors} = await loadAndValidateConfig(devInfraConfig, git.github);

0 commit comments

Comments
 (0)