From b1e8bec8ba41d801e63c2364450dacaee53f0c85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dar=C3=ADo=20Kondratiuk?= Date: Mon, 1 Apr 2024 17:36:44 -0300 Subject: [PATCH] DevOps: Create issue from a file (#2579) --- tools/github-ops/create-issue-from-file.js | 64 ++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 tools/github-ops/create-issue-from-file.js diff --git a/tools/github-ops/create-issue-from-file.js b/tools/github-ops/create-issue-from-file.js new file mode 100644 index 000000000..09970e0d3 --- /dev/null +++ b/tools/github-ops/create-issue-from-file.js @@ -0,0 +1,64 @@ +const fs = require("fs"); +const path = require("path"); +const axios = require("axios"); +require("dotenv").config(); + +const puppeteerSharpRepo = + "https://api.github.com/repos/hardkoded/puppeteer-sharp/issues"; +const repo ='hardkoded/puppeteer-sharp'; + +// Gets the token from the environment variables +const token = process.env.GITHUB_TOKEN; +const directoryPath = process.env.CDP_DIRECTORY; + +fs.readdir(directoryPath, (err, files) => { + if (err) { + return console.log("Unable to scan directory: " + err); + } + + // Handle each file + files.forEach((file) => { + const filename = path.parse(file).name; + + const title = `Split ${filename} class`; + const body = `Get the ${filename} class ready for the bidi protocol`; +/* + console.log(`Creating issue for ${filename}`); + console.log(`Title: ${title}`); + console.log(`Body: ${body}`); +*/ + // Check if the issue already exists + axios + .get( + `https://api.github.com/search/issues?q=${title}+in:title+is:issue+repo:${repo}`, + { + headers: { + Authorization: `token ${token}`, + }, + } + ) + .then((response) => { + const issues = response.data.items; + if (issues.length > 0) { + console.log(`Issue found: ${title}`); + } else { + console.log(`No issue found with the title: ${title}`); + return axios.post( + puppeteerSharpRepo, + { + title: title, + body: body, + }, + { + headers: { + Authorization: `token ${token}`, + }, + } + ); + } + }) + .catch((error) => { + console.error(error.message); + }); + }); +});