Compare commits

...
Author SHA1 Message Date
rickstaa 6883fec5c7 Merge branch 'master' into theme_preview_batch 2022-10-02 17:43:51 +02:00
rickstaa 90f1ed40f9 ci: add batch theme preview script 2022-10-02 17:43:48 +02:00
2 changed files with 57 additions and 1 deletions
+3 -1
View File
@@ -562,4 +562,6 @@ export const run = async (prNumber) => {
}
};
run();
if (typeof require !== "undefined" && require.main === module) {
run();
}
+54
View File
@@ -0,0 +1,54 @@
/**
* @file Apply preview-theme script to all theme pull requests.
*/
import { debug, setFailed } from "@actions/core";
import { getGithubToken, getRepoInfo } from "./helpers.js";
import { run as previewTheme } from "./preview-theme.js";
import github from "@actions/github";
import { fetchOpenPRs, pullsWithLabel } from "./close-stale-theme-prs.js";
/**
* Get all pull request that do not contain a given label.
* @param pull The pull requests to check.
* @param label The label to check for.
* @returns Whether the pull request contains the label.
*/
export const pullsWithoutLabel = (pulls, label) => {
return pulls.filter((pr) => {
return pr.labels.nodes.some((lab) => lab.name !== label);
});
};
/**
* Main function.
*/
const run = async () => {
try {
// Create octokit client.
const dryRun = process.env.DRY_RUN === "true" || false;
debug("Creating octokit client...");
const octokit = github.getOctokit(getGithubToken());
const { owner, repo } = getRepoInfo(github.context);
// Retrieve all theme pull requests.
debug("Retrieving all theme pull requests...");
const prs = await fetchOpenPRs(octokit, owner, repo);
let themePRs = pullsWithLabel(prs, "themes");
themePRs = pullsWithoutLabel(themePRs, "invalid");
debug(`Found ${themePRs.length} theme PRs`);
// Loop through all theme PR and execute the theme-preview script.
for (const pr of themePRs) {
debug(`Applying theme-preview to #${pr.number}...`);
console.log("Pull request number: ", pr.number);
if (!dryRun) {
await previewTheme(pr.number);
}
}
} catch (error) {
setFailed(error.message);
}
};
run();