MCPcopy Create free account
hub / github.com/angular/dev-infra / loadAndValidatePullRequest

Function loadAndValidatePullRequest

ng-dev/pr/merge/pull-request.ts:76–169  ·  view source on GitHub ↗
(
  {
    git,
    config,
  }: {
    git: AuthenticatedGitClient;
    config: NgDevConfig<{
      pullRequest: PullRequestConfig;
      github: GithubConfig;
    }>;
  },
  prNumber: number,
  validationConfig: PullRequestValidationConfig,
)

Source from the content-addressed store, hash-verified

74 * @throws {InvalidTargetLabelError} Error thrown if an invalid target label is applied.
75 * @throws {InvalidTargetBranchError} Error thrown if an invalid GitHub PR destination branch
76 * is selected.
77 */
78export async function loadAndValidatePullRequest(
79 {
80 git,
81 config,
82 }: {
83 git: AuthenticatedGitClient;
84 config: NgDevConfig<{
85 pullRequest: PullRequestConfig;
86 github: GithubConfig;
87 }>;
88 },
89 prNumber: number,
90 validationConfig: PullRequestValidationConfig,
91): Promise<PullRequest> {
92 const prData = await fetchPullRequestFromGithub(git, prNumber);
93
94 if (prData === null) {
95 throw new FatalMergeToolError('Pull request could not be found.');
96 }
97
98 let labels = prData.labels.nodes.map((l) => l.name);
99 let githubTargetBranch = prData.baseRefName;
100
101 const {mainBranchName, name, owner} = config.github;
102
103 // Active release trains fetched. May be `null` if e.g. target labeling is disabled
104 // and the active release train information is not available/computable.
105 let activeReleaseTrains: ActiveReleaseTrains | null = null;
106 let target: PullRequestTarget | null = null;
107
108 if (config.pullRequest.__noTargetLabeling) {
109 // If there is no target labeling, we always target the main branch and treat the PR as
110 // if it has been labeled with the `target: major` label (allowing for all types of changes).
111 target = {branches: [config.github.mainBranchName], label: targetLabels['TARGET_MAJOR']};
112 } else {
113 activeReleaseTrains = await ActiveReleaseTrains.fetch({
114 name,
115 nextBranchName: mainBranchName,
116 owner,
117 api: git.github,
118 });
119
120 target = await getTargetBranchesAndLabelForPullRequest(
121 activeReleaseTrains,
122 git.github,
123 config,
124 labels,
125 githubTargetBranch,
126 );
127 }
128
129 const validationFailures = await assertValidPullRequest(
130 prData,
131 validationConfig,
132 config,
133 activeReleaseTrains,

Callers 1

mergeMethod · 0.85

Calls 4

assertValidPullRequestFunction · 0.85
fetchMethod · 0.80

Tested by

no test coverage detected