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

Callers 1

mergeMethod · 0.85

Calls 4

assertValidPullRequestFunction · 0.85
fetchMethod · 0.80

Tested by

no test coverage detected