Last active
January 5, 2023 21:11
-
-
Save guibranco/715880ae902171d6fbca26a3af05997e to your computer and use it in GitHub Desktop.
Update all opened issues from a repository to trigger a GH action to run
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 organization = pm.collectionVariables.get("org"); | |
const repository = pm.collectionVariables.get("repository"); | |
const headerAuthorization = `Authorization: Bearer ${ghToken}`; | |
const repositoryUrl = `https://api.github.com/repos/${organization}/${repository}`; | |
pm.sendRequest({ | |
url: repositoryUrl, | |
method: 'GET', | |
header: headerAuthorization, | |
}, function (err, res) { | |
if (err) { | |
console.log(err); | |
} | |
const repository = res.json(); | |
const pages = Math.ceil(repository.open_issues / 100); | |
for (let currentPage = 1; currentPage <= pages; currentPage++) { | |
let issuesUrl = `${repositoryUrl}/issues?page=${currentPage}&per_page=100&state=open&sort=updated&direction=desc`; | |
pm.sendRequest({ | |
url: issuesUrl, | |
method: 'GET', | |
header: headerAuthorization, | |
}, function (err, res) { | |
if (err) { | |
console.log(err); | |
} | |
const issues = res.json(); | |
for (let index in issues) { | |
const issue = issues[index]; | |
if (issue.labels.length > 0) { | |
continue; | |
} | |
pm.sendRequest({ | |
url: issue.url, | |
method: "POST", | |
header: headerAuthorization, | |
body: JSON.stringify({ | |
body: issue.body + "\r\n" | |
}) | |
}, function (err, res) { | |
if (err) { | |
console.log(err); | |
} | |
console.log(res.json()); | |
}); | |
} | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment