We rely on a Github API `/branches` request to determine the active release trains. Currently this logic is broken if more than 100 protected branches exist within a repository. This issue surfaced recently where the `items_per_page` setting was set to `30`, causing the merge tooling and release tooling to not detect the proper "latest" release train. This commit uses Github pagination for retrieving branches to determine the active release trains, and makes the logic more long-term proof. PR Close #42666
29 lines
947 B
TypeScript
29 lines
947 B
TypeScript
/**
|
|
* @license
|
|
* Copyright Google LLC All Rights Reserved.
|
|
*
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
* found in the LICENSE file at https://angular.io/license
|
|
*/
|
|
|
|
/**
|
|
* Builds the `Link` response header to indicate an API response that is suitable
|
|
* for pagination. This follows the specification as outlined within:
|
|
* https://docs.github.com/en/rest/guides/traversing-with-pagination
|
|
*/
|
|
export function buildGithubPaginationResponseHeader(
|
|
totalPages: number, currentPage: number, baseUrl: string) {
|
|
const links = [`<${baseUrl}?page=1>; rel="first"`, `<${baseUrl}?page=${totalPages}>; rel="last"`];
|
|
|
|
if (currentPage < totalPages) {
|
|
links.push(`<${baseUrl}?page=${currentPage + 1}>; rel="next"`);
|
|
}
|
|
|
|
// Pages start with `1` as per the Github API specification.
|
|
if (currentPage > 1) {
|
|
links.push(`<${baseUrl}?page=${currentPage - 1}>; rel="prev"`);
|
|
}
|
|
|
|
return links.join(',');
|
|
}
|