Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Actualizar auto-close-pr.properties.json #161

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Loading