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

fix(ci): filterUpdateFiles in cron #19517

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
40 changes: 28 additions & 12 deletions scripts/filterUpdateFiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,36 @@ const ghGetBranch = async (branchName = "master") => {
};

const ghCompareCommits = async (base = "", head = "") => {
const basehead = `${base}...${head}`;
const result = await octokit.request(
`GET /repos/pingcap/docs/compare/${basehead}`,
{
owner: "pingcap",
repo: "docs",
basehead,
const nextPattern = /(?<=<)([\S]*)(?=>; rel="next")/i;
let pagesRemaining = true;
let allData = [];
let url = `/repos/pingcap/docs/compare/${base}...${head}`;

while (pagesRemaining) {
const result = await octokit.request(
`GET ${url}`,
{
per_page: 100,
}
);

if (result.status === 200) {
const data = result.data;
allData = [...allData, ...data];

const linkHeader = result.headers.link;

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

if (pagesRemaining) {
url = linkHeader.match(nextPattern)[0];
}
} else {
throw new Error(`ghCompareCommits error: ${result}`);
}
);
if (result.status === 200) {
const data = result.data;
return data;
}
throw new Error(`ghGetBranch error: ${result}`);

return allData;
};

const downloadFile = async (url, targetPath) => {
Expand Down