Skip to content

Commit b1e8bec

Browse files
authored
DevOps: Create issue from a file (#2579)
1 parent 6a7d567 commit b1e8bec

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
const fs = require("fs");
2+
const path = require("path");
3+
const axios = require("axios");
4+
require("dotenv").config();
5+
6+
const puppeteerSharpRepo =
7+
"https://api.github.com/repos/hardkoded/puppeteer-sharp/issues";
8+
const repo ='hardkoded/puppeteer-sharp';
9+
10+
// Gets the token from the environment variables
11+
const token = process.env.GITHUB_TOKEN;
12+
const directoryPath = process.env.CDP_DIRECTORY;
13+
14+
fs.readdir(directoryPath, (err, files) => {
15+
if (err) {
16+
return console.log("Unable to scan directory: " + err);
17+
}
18+
19+
// Handle each file
20+
files.forEach((file) => {
21+
const filename = path.parse(file).name;
22+
23+
const title = `Split ${filename} class`;
24+
const body = `Get the ${filename} class ready for the bidi protocol`;
25+
/*
26+
console.log(`Creating issue for ${filename}`);
27+
console.log(`Title: ${title}`);
28+
console.log(`Body: ${body}`);
29+
*/
30+
// Check if the issue already exists
31+
axios
32+
.get(
33+
`https://api.github.com/search/issues?q=${title}+in:title+is:issue+repo:${repo}`,
34+
{
35+
headers: {
36+
Authorization: `token ${token}`,
37+
},
38+
}
39+
)
40+
.then((response) => {
41+
const issues = response.data.items;
42+
if (issues.length > 0) {
43+
console.log(`Issue found: ${title}`);
44+
} else {
45+
console.log(`No issue found with the title: ${title}`);
46+
return axios.post(
47+
puppeteerSharpRepo,
48+
{
49+
title: title,
50+
body: body,
51+
},
52+
{
53+
headers: {
54+
Authorization: `token ${token}`,
55+
},
56+
}
57+
);
58+
}
59+
})
60+
.catch((error) => {
61+
console.error(error.message);
62+
});
63+
});
64+
});

0 commit comments

Comments
 (0)