Skip to content

Commit

Permalink
fix(ng-dev): only include LTS label as a target label if the release …
Browse files Browse the repository at this point in the history
…configuration is defined (#245)

If a project does not have a release configuration defined, the LTS branches cannot be determined
and should not be included in the target labels when determined.
  • Loading branch information
josephperrott authored Oct 1, 2021
1 parent e638278 commit eca29df
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions ng-dev/pr/common/targeting/labels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
isVersionBranch,
ReleaseRepoWithApi,
} from '../../../release/versioning';
import {assertValidGithubConfig, GithubConfig} from '../../../utils/config';
import {assertValidGithubConfig, ConfigValidationError, GithubConfig} from '../../../utils/config';
import {
InvalidTargetBranchError,
InvalidTargetLabelError,
Expand All @@ -23,6 +23,7 @@ import {

import {assertActiveLtsBranch} from './lts-branch';
import {GithubClient} from '../../../utils/git/github';
import {debug} from '../../../utils/console';

/**
* Gets a list of target labels which should be considered by the merge
Expand All @@ -40,7 +41,6 @@ export async function getTargetLabelsForActiveReleaseTrains(
api: GithubClient,
config: Partial<{github: GithubConfig; release: ReleaseConfig}>,
): Promise<TargetLabel[]> {
assertValidReleaseConfig(config);
assertValidGithubConfig(config);

const nextBranchName = getNextBranchName(config.github);
Expand All @@ -52,7 +52,7 @@ export async function getTargetLabelsForActiveReleaseTrains(
};
const {latest, releaseCandidate, next} = await fetchActiveReleaseTrains(repo);

return [
const targetLabels: TargetLabel[] = [
{
name: TargetLabelName.MAJOR,
branches: () => {
Expand Down Expand Up @@ -119,7 +119,13 @@ export async function getTargetLabelsForActiveReleaseTrains(
return [nextBranchName, releaseCandidate.branchName];
},
},
{
];

// LTS branches can only be determined if the release configuration is defined, and must be added
// after asserting the configuration contains a release config.
try {
assertValidReleaseConfig(config);
targetLabels.push({
// LTS changes are rare enough that we won't worry about cherry-picking changes into all
// active LTS branches for PRs created against any other branch. Instead, PR authors need
// to manually create separate PRs for desired LTS branches. Additionally, active LT branches
Expand All @@ -145,9 +151,19 @@ export async function getTargetLabelsForActiveReleaseTrains(
);
}
// Assert that the selected branch is an active LTS branch.
assertValidReleaseConfig(config);
await assertActiveLtsBranch(repo, config.release, githubTargetBranch);
return [githubTargetBranch];
},
},
];
});
} catch (err) {
if (err instanceof ConfigValidationError) {
debug('LTS target label not included in target labels as no valid release configuration was');
debug('found to allow the LTS branches to be determined.');
} else {
throw err;
}
}

return targetLabels;
}

0 comments on commit eca29df

Please sign in to comment.