Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the GitHub API to get the label's node ID #3483

Merged
merged 1 commit into from
Dec 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 21 additions & 8 deletions automations/js/src/label_pr.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,23 @@ function getIsFullyLabeled(labels) {
return true
}

/**
* Get the `Label` instance from a label's name.
*
* @param octokit {import('@octokit/rest').Octokit} the Octokit instance to use
* @param repository {string} the full name of the repository, including owner
* @param name {string} the name of the label for which to get node ID
* @returns {Label} the label with the `id` and `name` fields
*/
async function getLabel(octokit, repository, name) {
const [owner, repo] = repository.split('/')
const res = await octokit.issues.getLabel({ owner, repo, name })
return {
id: res.data.node_id,
name,
}
}

/**
* Apply labels to a PR based on the PR's linked issues.
*
Expand All @@ -36,6 +53,7 @@ function getIsFullyLabeled(labels) {
* @param core {import('@actions/core')} GitHub Actions toolkit, for logging
*/
export const main = async (octokit, core) => {
const { GITHUB_REPOSITORY } = process.env
const { eventName, eventAction, prNodeId } = JSON.parse(
readFileSync('/tmp/event.json', 'utf-8')
)
Expand Down Expand Up @@ -109,17 +127,12 @@ export const main = async (octokit, core) => {
if (!getIsFullyLabeled(finalLabels.items)) {
let attnLabel
if (isTriaged) {
attnLabel = {
id: 'MDU6TGFiZWwzMDI5NTEyMjMw',
name: '🏷 status: label work required',
}
attnLabel = '🏷 status: label work required'
} else {
attnLabel = {
id: 'MDU6TGFiZWwzMDI5NTEyMjc1',
name: '🚦 status: awaiting triage',
}
attnLabel = '🚦 status: awaiting triage'
}
core.info(`Pull not fully labelled so adding "${attnLabel}".`)
attnLabel = await getLabel(octokit, GITHUB_REPOSITORY, attnLabel)
finalLabels.add(attnLabel)
}

Expand Down