mirror of
https://github.com/renovatebot/renovate.git
synced 2026-10-30 17:27:26 +00:00
135dd45e7e
As per request in #45462, we can perform a prefactor to ensure that our scripts for CI-related functionality are part of `tools`, so they're linted appropriately. Co-authored-by: Claude Sonnet 5 <jamie.tanna+claude-code@mend.io>
100 lines
2.7 KiB
JavaScript
100 lines
2.7 KiB
JavaScript
// Parses the ISO date string and checks it's past the age window
|
|
// Co-authored-by: GPT-4.1 (GitHub Copilot)
|
|
/**
|
|
* @param {string} dateString
|
|
* @param {number} daysAgo
|
|
*/
|
|
function isOlderThanDaysAgo(dateString, daysAgo) {
|
|
const parsedDate = new Date(dateString);
|
|
const now = new Date();
|
|
const thresholdDate = new Date(now.getTime() - daysAgo * 24 * 60 * 60 * 1000);
|
|
return parsedDate < thresholdDate;
|
|
}
|
|
|
|
/**
|
|
* @param {{ github: any, context: any, discussionAnsweredDays: number }} params
|
|
*/
|
|
module.exports = async ({ github, context, discussionAnsweredDays }) => {
|
|
const owner = context.repo.owner;
|
|
const repo = context.repo.repo;
|
|
|
|
let cursor = null;
|
|
|
|
const query = `query ($cursor: String) {
|
|
repository(owner: "${owner}", name: "${repo}") {
|
|
discussions(after: $cursor, states: OPEN, answered: true, first: 10, orderBy: {field: CREATED_AT, direction: ASC}) {
|
|
pageInfo {
|
|
endCursor
|
|
hasNextPage
|
|
}
|
|
edges {
|
|
node {
|
|
id
|
|
answerChosenAt
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}`;
|
|
|
|
let pageNumber = 0;
|
|
while (true) {
|
|
// oxlint-disable-next-line no-console
|
|
console.debug({ cursor }, 'Starting query');
|
|
/** @type {{ repository: any }} */
|
|
const { repository } = await github.graphql(query, { cursor });
|
|
|
|
// oxlint-disable-next-line no-console
|
|
console.debug(
|
|
{ pageNumber },
|
|
`Found ${repository.discussions.edges.length} discussions in this page of data`,
|
|
);
|
|
|
|
let numMutating = 0;
|
|
let mutation = 'mutation {';
|
|
for (const i in repository.discussions.edges) {
|
|
const edge = repository.discussions.edges[i];
|
|
if (
|
|
isOlderThanDaysAgo(edge.node.answerChosenAt, discussionAnsweredDays)
|
|
) {
|
|
mutation += `m${i}: closeDiscussion(input: {discussionId: "${edge.node.id}"}) {
|
|
clientMutationId
|
|
}\n`;
|
|
numMutating++;
|
|
}
|
|
}
|
|
mutation += '}';
|
|
|
|
if (numMutating > 0) {
|
|
// oxlint-disable-next-line no-console
|
|
console.debug(
|
|
{ pageNumber },
|
|
`Attempting the following mutation:\n${mutation}`,
|
|
);
|
|
|
|
await github.graphql(mutation);
|
|
|
|
// oxlint-disable-next-line no-console
|
|
console.log({ pageNumber }, `Closed ${numMutating} answered Discussions`);
|
|
} else {
|
|
// oxlint-disable-next-line no-console
|
|
console.debug(
|
|
{ pageNumber },
|
|
`Did not find any Discussions to close in this page of data`,
|
|
);
|
|
}
|
|
|
|
if (!repository.discussions.pageInfo.hasNextPage) {
|
|
break;
|
|
}
|
|
|
|
pageNumber++;
|
|
cursor = repository.discussions.pageInfo.endCursor;
|
|
|
|
// wait 5 seconds between each call, to reduce GitHub API rate limits
|
|
await new Promise((resolve) => setTimeout(resolve, 5000));
|
|
}
|
|
|
|
return '';
|
|
};
|