chore(validateTags): auto add labels

This commit is contained in:
xHyroM 2022-07-16 15:51:03 +02:00
parent d5389a6757
commit f59112306c

View file

@ -49,29 +49,52 @@ for (const [key, value] of Object.entries(tags)) {
} }
if (errors.length === 0) { if (errors.length === 0) {
fetch(`https://api.github.com/repos/xHyroM/bun-discord-bot/pulls/${pullRequestNumber}/reviews`, { requestGithub(
method: 'POST', `pulls/${pullRequestNumber}/reviews`,
headers: { {
'Accept': 'application/vnd.github+json',
'Authorization': `token ${githubToken}`
},
body: JSON.stringify({
commit_id: commitSha, commit_id: commitSha,
event: 'APPROVE', event: 'APPROVE',
}) }
}) );
requestGithub(
`issues/${pullRequestNumber}/labels/waiting`,
{},
'DELETE'
);
requestGithub(
`issues/${pullRequestNumber}/labels`,
{
labels: ['ready']
}
);
} else { } else {
fetch(`https://api.github.com/repos/xHyroM/bun-discord-bot/pulls/${pullRequestNumber}/reviews`, { requestGithub(
method: 'POST', `pulls/${pullRequestNumber}/reviews`,
{
commit_id: commitSha,
body: '### Please fix the following problems:\n' + errors.join('\n'),
event: 'REQUEST_CHANGES',
}
);
requestGithub(
`issues/${pullRequestNumber}/labels`,
{
labels: ['waiting']
}
);
}
function requestGithub(url: string, body: any, method?: 'POST' | 'DELETE') {
fetch(`https://api.github.com/repos/xHyroM/bun-discord-bot/${url}`, {
method: method || 'POST',
headers: { headers: {
'Accept': 'application/vnd.github+json', 'Accept': 'application/vnd.github+json',
'Authorization': `token ${githubToken}` 'Authorization': `token ${githubToken}`
}, },
body: JSON.stringify({ body: JSON.stringify(body)
commit_id: commitSha,
body: 'Please fix the following problems:\n' + errors.join('\n'),
event: 'REQUEST_CHANGES',
})
}) })
} }