in src/common/github-service.ts [216:280]
public async getPrsForVersion(
version: string,
excludedLabels: readonly string[] = [],
includedLabels: readonly string[] = [],
ignoredVersionLabels: readonly string[] = []
): Promise<Observable<Progress<PrItem>>> {
const semVer = semver.parse(version);
if (!semVer) {
throw new Error('Invalid version entered');
}
let excludedVersions: string[] = [];
if (semVer && semVer.patch === 0 && semVer.minor === 0) {
// If we're loading a major version we need some special logic to exclude all PRs that
// already have been part of the previous major version. Therefore we're getting all previous
// major label and exclude them in the search.
const labelsQuery = this.octokit.search.labels.endpoint.merge({
q: `v${semVer.major - 1}`,
repository_id: this.repoId,
});
excludedVersions = (await this.octokit.paginate<Label>(labelsQuery)).map(
(label) => label.name ?? ''
);
}
const labelExclusions = [...excludedLabels, ...excludedVersions]
.map((label) => `-label:"${label}"`)
.join(' ');
const labelInclusion =
includedLabels.length > 0 ? `label:${includedLabels.map((l) => `"${l}"`).join(',')}` : '';
const options = this.octokit.search.issuesAndPullRequests.endpoint.merge({
q:
`repo:${GITHUB_OWNER}/${this.repoName} label:${version} is:pr is:merged ` +
`base:master base:main base:${semVer.major}.x base:${semVer.major}.${semVer.minor} ` +
`${labelExclusions} ${labelInclusion}`,
per_page: 100,
});
const progressSubject$ = new Subject<Progress<PrItem>>();
(async () => {
const items: PrItem[] = [];
for await (const response of this.octokit.paginate.iterator<PrItem>(options)) {
items.push(...filterPrsForVersion(response.data, version, ignoredVersionLabels));
if (response.headers.link) {
const links = parseLinkHeader(response.headers.link);
if (links?.last?.page) {
const currentPage = Number(new URL(response.url).searchParams.get('page')) || 1;
progressSubject$.next({
type: 'progress',
percentage: currentPage / Number(links.last.page),
items,
});
}
}
}
progressSubject$.next({ type: 'complete', items });
progressSubject$.complete();
})();
return progressSubject$.asObservable();
}