Skip to content

Commit

Permalink
feat: paginate remote branches
Browse files Browse the repository at this point in the history
  • Loading branch information
tranhl committed Jul 17, 2024
1 parent 3191ced commit 2182372
Show file tree
Hide file tree
Showing 7 changed files with 7,860 additions and 73 deletions.
43 changes: 26 additions & 17 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42834,10 +42834,10 @@ var remark2 = remark().use(remarkGfm).data("settings", {
// src/main.ts
async function main({
octokit,
mainBranch,
perennialBranches,
currentPullRequest,
pullRequests
pullRequests,
mainBranch,
perennialBranches
}) {
const repoGraph = new import_graphology.MultiDirectedGraph();
repoGraph.addNode(mainBranch, {
Expand Down Expand Up @@ -46842,18 +46842,21 @@ var inputs = {
mainBranch = mainBranchInput !== "" ? mainBranchInput : mainBranch;
return mainBranch;
},
async getPerennialBranches(octokit, config2, context3) {
const [{ data: unprotectedBranches }, { data: protectedBranches }] = await Promise.all([
octokit.rest.repos.listBranches({ ...context3.repo }),
octokit.rest.repos.listBranches({ ...context3.repo, protected: true })
]);
async getRemoteBranches(octokit, context3) {
const remoteBranches = await octokit.paginate(
"GET /repos/{owner}/{repo}/branches",
{
...context3.repo,
per_page: 100
},
(response) => response.data.map((branch) => branch.name)
);
core2.startGroup("Inputs: Remote branches");
core2.info(`Unprotected: ${JSON.stringify(unprotectedBranches)}`);
core2.info(`Protected: ${JSON.stringify(protectedBranches)}`);
core2.info(JSON.stringify(remoteBranches));
core2.endGroup();
const repoBranches = [...unprotectedBranches, ...protectedBranches].map(
(branch) => branch.name
);
return remoteBranches;
},
async getPerennialBranches(config2, remoteBranches) {
let explicitBranches = [];
explicitBranches = config2?.branches?.perennials ?? explicitBranches;
const perennialBranchesInput = core2.getMultilineInput("perennial-branches", {
Expand All @@ -46873,7 +46876,7 @@ var inputs = {
perennialRegex = perennialRegexInput !== "" ? perennialRegexInput : perennialRegex;
const perennialBranches = [
...explicitBranches,
...repoBranches.filter(
...remoteBranches.filter(
(branch) => perennialRegex ? RegExp(perennialRegex).test(branch) : false
)
];
Expand Down Expand Up @@ -46964,17 +46967,23 @@ async function run() {
);
return;
}
const octokit = github2.getOctokit(inputs.getToken());
const [mainBranch, perennialBranches, pullRequests] = await Promise.all([
const octokit = github2.getOctokit(inputs.getToken(), {
request: {
fetch: global.fetch
}
});
const [mainBranch, remoteBranches, pullRequests] = await Promise.all([
inputs.getMainBranch(octokit, config, github2.context),
inputs.getPerennialBranches(octokit, config, github2.context),
inputs.getRemoteBranches(octokit, github2.context),
inputs.getPullRequests(octokit, github2.context)
]);
const perennialBranches = await inputs.getPerennialBranches(config, remoteBranches);
const context3 = {
octokit,
currentPullRequest: inputs.getCurrentPullRequest(github2.context),
pullRequests,
mainBranch,
remoteBranches,
perennialBranches
};
void main(context3);
Expand Down
Loading

0 comments on commit 2182372

Please sign in to comment.