Skip to content

Instantly share code, notes, and snippets.

@guibranco
Created January 27, 2024 01:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guibranco/5ec45294620d1159d6d5cf9694f97434 to your computer and use it in GitHub Desktop.
Save guibranco/5ec45294620d1159d6d5cf9694f97434 to your computer and use it in GitHub Desktop.
Create issue if a file exists in the repository (a specific workflow file).
const ghToken = pm.globals.get("GH_PAT");
const authorizationHeader = `Authorization: Bearer ${ghToken}`;
const workflowName = "build.yml"
const issueTitle = `Remove \`${workflowName}\``;
const repositories = pm.response.json();
for (let i = 0; i < repositories.length; i++) {
const repository = repositories[i];
if (!repository.has_issues) {
continue;
}
const issueBody = `**Is your feature request related to a problem? Please describe.**\r\nRemove the workflow file [${workflowName}](${repository.html_url}/blob/main/.github/workflows/${workflowName}).`;
pm.sendRequest({
url: `https://api.github.com/repos/${repository.full_name}/contents/.github/workflows/${workflowName}`,
method: "GET",
header: authorizationHeader
}, function (err, res) {
if(res.code == 200) {
const createIssue = `https://api.github.com/repos/${repository.full_name}/issues`;
pm.sendRequest({
url: createIssue,
method: "POST",
header: authorizationHeader,
body: JSON.stringify({
title: issueTitle,
body: issueBody,
assignee: "guibranco",
labels: ["CI/CD", "github-actions", "enhancement"]
}),
},
function (err, res) {
console.log(res);
});
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment