Created
January 27, 2024 01:37
-
-
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).
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
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