Skip to content

Commit

Permalink
Actualizar auto-close-pr.properties.json
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikemotos12 authored Aug 31, 2024
1 parent 23f49ce commit 77ef934
Showing 1 changed file with 60 additions and 1 deletion.
61 changes: 60 additions & 1 deletion workflow-templates/auto-close-pr.properties.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,63 @@
{
"name": "Auto close PRs",
"description": "Automatically close pull requests from non-staff."
}
}import { Octokit } from "octokit";

const octokit = new Octokit({ });

async function getPaginatedData(url) {
const nextPattern = /(?<=<)([\S]*)(?=>; rel="Next")/i;
let pagesRemaining = true;
let data = [];

while (pagesRemaining) {
const response = await octokit.request(`GET ${url}`, {
per_page: 100,
headers: {
"X-GitHub-Api-Version":
"2022-11-28",
},
});

const parsedData = parseData(response.data)
data = [...data, ...parsedData];

const linkHeader = response.headers.link;

pagesRemaining = linkHeader && linkHeader.includes(`rel=\"next\"`);

if (pagesRemaining) {
url = linkHeader.match(nextPattern)[0];
}
}

return data;
}

function parseData(data) {
// If the data is an array, return that
if (Array.isArray(data)) {
return data
}

// Some endpoints respond with 204 No Content instead of empty array
// when there is no data. In that case, return an empty array.
if (!data) {
return []
}

// Otherwise, the array of items that we want is in an object
// Delete keys that don't include the array of items
delete data.incomplete_results;
delete data.repository_selection;
delete data.total_count;
// Pull out the array of items
const namespaceKey = Object.keys(data)[0];
data = data[namespaceKey];

return data;
}

const data = await getPaginatedData("/repos/octocat/Spoon-Knife/issues");

console.log(data);

0 comments on commit 77ef934

Please sign in to comment.