Openverse is a search engine for openly-licensed media. This monorepo includes all application code.
Use the GitHub API to get the label's node ID (#3483)
Dhruv Bhanushali6dbd3d1e813f
diff --git a/automations/js/src/label_pr.mjs b/automations/js/src/label_pr.mjsindex 8c444870d..126f27b94 100644--- a/automations/js/src/label_pr.mjs+++ b/automations/js/src/label_pr.mjs@@ -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.*@@ -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.envconst { eventName, eventAction, prNodeId } = JSON.parse(readFileSync('/tmp/event.json', 'utf-8'))@@ -109,17 +127,12 @@ export const main = async (octokit, core) => {if (!getIsFullyLabeled(finalLabels.items)) {let attnLabelif (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)}