-
-
Notifications
You must be signed in to change notification settings - Fork 440
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DevOps: Create issue from a file (#2579)
- Loading branch information
Showing
1 changed file
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}); | ||
}); | ||
}); |