From 954d17e9290997e4e176df5ad8fd6250928b004d Mon Sep 17 00:00:00 2001 From: tbradsha <32492176+tbradsha@users.noreply.github.com> Date: Fri, 6 Dec 2024 13:08:59 -0700 Subject: [PATCH 01/15] Update index.js --- .../src/tasks/add-labels/index.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/projects/github-actions/repo-gardening/src/tasks/add-labels/index.js b/projects/github-actions/repo-gardening/src/tasks/add-labels/index.js index 30a95cbbb435..949cb9eabc4f 100644 --- a/projects/github-actions/repo-gardening/src/tasks/add-labels/index.js +++ b/projects/github-actions/repo-gardening/src/tasks/add-labels/index.js @@ -1,6 +1,7 @@ const { getInput } = require( '@actions/core' ); const debug = require( '../../utils/debug' ); const getFiles = require( '../../utils/get-files' ); +const getLabels = require( '../../utils/labels/get-labels' ); /* global GitHub, WebhookPayloadPullRequest */ @@ -320,7 +321,7 @@ async function getLabelsToAdd( octokit, owner, repo, number, isDraft, isRevert ) } /** - * Assigns any issues that are being worked to the author of the matching PR. + * Adds appropriate labels to the specified PR. * * @param {WebhookPayloadPullRequest} payload - Pull request event payload. * @param {GitHub} octokit - Initialized Octokit REST client. @@ -336,20 +337,24 @@ async function addLabels( payload, octokit ) { // If the PR title includes the word "revert", mark it as such. const isRevert = title.toLowerCase().includes( 'revert' ); - const labels = await getLabelsToAdd( octokit, owner.login, name, number, isDraft, isRevert ); + const currentLabels = payload.pull_request.labels; - if ( ! labels.length ) { + const labelsToAdd = await getLabelsToAdd( octokit, owner.login, name, number, isDraft, isRevert ); + + if ( ! labelsToAdd.length ) { debug( 'add-labels: Could not find labels to add to that PR. Aborting' ); return; } + console.log(currentLabels); + console.log(labelsToAdd); - debug( `add-labels: Adding labels ${ labels } to PR #${ number }` ); + debug( `add-labels: Adding labels ${ labelsToAdd } to PR #${ number }` ); - await octokit.rest.issues.addLabels( { + await octokit.rest.issues.setLabels( { owner: owner.login, repo: name, issue_number: number, - labels, + labelsToAdd, } ); } From 36dc6bdb47dccfb7b52caf651ffc0d3e6136919a Mon Sep 17 00:00:00 2001 From: tbradsha <32492176+tbradsha@users.noreply.github.com> Date: Fri, 6 Dec 2024 13:18:17 -0700 Subject: [PATCH 02/15] Update index.js --- .../github-actions/repo-gardening/src/tasks/add-labels/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/github-actions/repo-gardening/src/tasks/add-labels/index.js b/projects/github-actions/repo-gardening/src/tasks/add-labels/index.js index 949cb9eabc4f..e60411f5eda4 100644 --- a/projects/github-actions/repo-gardening/src/tasks/add-labels/index.js +++ b/projects/github-actions/repo-gardening/src/tasks/add-labels/index.js @@ -354,7 +354,7 @@ async function addLabels( payload, octokit ) { owner: owner.login, repo: name, issue_number: number, - labelsToAdd, + labels: labelsToAdd, } ); } From 9b84d7bc79543c500b502988b0fcc7b6fe090169 Mon Sep 17 00:00:00 2001 From: tbradsha <32492176+tbradsha@users.noreply.github.com> Date: Fri, 6 Dec 2024 13:22:08 -0700 Subject: [PATCH 03/15] Update index.js --- .../github-actions/repo-gardening/src/tasks/add-labels/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/github-actions/repo-gardening/src/tasks/add-labels/index.js b/projects/github-actions/repo-gardening/src/tasks/add-labels/index.js index e60411f5eda4..32f086eff963 100644 --- a/projects/github-actions/repo-gardening/src/tasks/add-labels/index.js +++ b/projects/github-actions/repo-gardening/src/tasks/add-labels/index.js @@ -337,7 +337,7 @@ async function addLabels( payload, octokit ) { // If the PR title includes the word "revert", mark it as such. const isRevert = title.toLowerCase().includes( 'revert' ); - const currentLabels = payload.pull_request.labels; + const currentLabels = payload.pull_request.labels.map( l => l.name ); const labelsToAdd = await getLabelsToAdd( octokit, owner.login, name, number, isDraft, isRevert ); From 1ffc7b1afe7920a4d5ced0041a3d34003e54387d Mon Sep 17 00:00:00 2001 From: tbradsha <32492176+tbradsha@users.noreply.github.com> Date: Fri, 6 Dec 2024 13:39:17 -0700 Subject: [PATCH 04/15] Update index.js --- .../src/tasks/add-labels/index.js | 24 +++++++++---------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/projects/github-actions/repo-gardening/src/tasks/add-labels/index.js b/projects/github-actions/repo-gardening/src/tasks/add-labels/index.js index 32f086eff963..97b87047cf40 100644 --- a/projects/github-actions/repo-gardening/src/tasks/add-labels/index.js +++ b/projects/github-actions/repo-gardening/src/tasks/add-labels/index.js @@ -50,18 +50,19 @@ function cleanName( name ) { } /** - * Build a list of labels to add to the issue, based off our file list. + * Build a list of labels to add to the pull request, based off our file list. * - * @param {GitHub} octokit - Initialized Octokit REST client. - * @param {string} owner - Repository owner. - * @param {string} repo - Repository name. - * @param {string} number - PR number. - * @param {boolean} isDraft - Whether the pull request is a draft. - * @param {boolean} isRevert - Whether the pull request is a revert. + * @param {GitHub} octokit - Initialized Octokit REST client. + * @param {string} owner - Repository owner. + * @param {string} repo - Repository name. + * @param {string} number - PR number. + * @param {boolean} isDraft - Whether the pull request is a draft. + * @param {boolean} isRevert - Whether the pull request is a revert. + * @param {array} currentLabels - Current labels on the pull request. * @return {Promise} Promise resolving to an array of keywords we'll search for. */ -async function getLabelsToAdd( octokit, owner, repo, number, isDraft, isRevert ) { - const keywords = new Set(); +async function getLabelsToAdd( octokit, owner, repo, number, isDraft, isRevert, currentLabels ) { + const keywords = new Set( currentLabels ); // Get next valid milestone. const files = await getFiles( octokit, owner, repo, number ); @@ -338,15 +339,12 @@ async function addLabels( payload, octokit ) { const isRevert = title.toLowerCase().includes( 'revert' ); const currentLabels = payload.pull_request.labels.map( l => l.name ); - - const labelsToAdd = await getLabelsToAdd( octokit, owner.login, name, number, isDraft, isRevert ); + const labelsToAdd = await getLabelsToAdd( octokit, owner.login, name, number, isDraft, isRevert, currentLabels ); if ( ! labelsToAdd.length ) { debug( 'add-labels: Could not find labels to add to that PR. Aborting' ); return; } - console.log(currentLabels); - console.log(labelsToAdd); debug( `add-labels: Adding labels ${ labelsToAdd } to PR #${ number }` ); From 91c712f0d56552657b2126cfb7fe87b3c2b0f18f Mon Sep 17 00:00:00 2001 From: tbradsha <32492176+tbradsha@users.noreply.github.com> Date: Fri, 6 Dec 2024 14:02:44 -0700 Subject: [PATCH 05/15] Update index.js --- .../src/tasks/add-labels/index.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/projects/github-actions/repo-gardening/src/tasks/add-labels/index.js b/projects/github-actions/repo-gardening/src/tasks/add-labels/index.js index 97b87047cf40..662e08e88651 100644 --- a/projects/github-actions/repo-gardening/src/tasks/add-labels/index.js +++ b/projects/github-actions/repo-gardening/src/tasks/add-labels/index.js @@ -339,13 +339,27 @@ async function addLabels( payload, octokit ) { const isRevert = title.toLowerCase().includes( 'revert' ); const currentLabels = payload.pull_request.labels.map( l => l.name ); + console.log(1,currentLabels); const labelsToAdd = await getLabelsToAdd( octokit, owner.login, name, number, isDraft, isRevert, currentLabels ); + console.log(2,labelsToAdd); - if ( ! labelsToAdd.length ) { - debug( 'add-labels: Could not find labels to add to that PR. Aborting' ); + // Nothing new was added, so abort. + if ( labelsToAdd.length === currentLabels.length ) { + debug( 'add-labels: No new labels to add to that PR. Aborting.' ); return; } + // Limit to 90 labels to allow for additional labels elsewhere. + const bigLabel = 'All the things (90+ labels)'; + if ( labelsToAdd.length > 90 ) { + debug( 'add-labels: GitHub only allows 100 labels on a PR, so limiting to the first 90.' ); + labelsToAdd.splice( 90 ); + labelsToAdd.push( bigLabel ); + } else if ( labelsToAdd.includes( bigLabel ) ) { + labelsToAdd = labelsToAdd.filter( label => label !== bigLabel ); + } + console.log(3,labelsToAdd); + debug( `add-labels: Adding labels ${ labelsToAdd } to PR #${ number }` ); await octokit.rest.issues.setLabels( { From a12241b407ca93d27a9019f8c97dfc65de24c00f Mon Sep 17 00:00:00 2001 From: tbradsha <32492176+tbradsha@users.noreply.github.com> Date: Fri, 6 Dec 2024 14:11:54 -0700 Subject: [PATCH 06/15] Update index.js --- .../github-actions/repo-gardening/src/tasks/add-labels/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/github-actions/repo-gardening/src/tasks/add-labels/index.js b/projects/github-actions/repo-gardening/src/tasks/add-labels/index.js index 662e08e88651..3d95ce9e3e0c 100644 --- a/projects/github-actions/repo-gardening/src/tasks/add-labels/index.js +++ b/projects/github-actions/repo-gardening/src/tasks/add-labels/index.js @@ -351,7 +351,7 @@ async function addLabels( payload, octokit ) { // Limit to 90 labels to allow for additional labels elsewhere. const bigLabel = 'All the things (90+ labels)'; - if ( labelsToAdd.length > 90 ) { + if ( labelsToAdd.length > 2 ) { debug( 'add-labels: GitHub only allows 100 labels on a PR, so limiting to the first 90.' ); labelsToAdd.splice( 90 ); labelsToAdd.push( bigLabel ); From 4eee04b14fff67d1487c5bd36a2c23e41acff076 Mon Sep 17 00:00:00 2001 From: tbradsha <32492176+tbradsha@users.noreply.github.com> Date: Fri, 6 Dec 2024 14:20:43 -0700 Subject: [PATCH 07/15] Update index.js --- .../src/tasks/add-labels/index.js | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/projects/github-actions/repo-gardening/src/tasks/add-labels/index.js b/projects/github-actions/repo-gardening/src/tasks/add-labels/index.js index 3d95ce9e3e0c..4ee4fe351be6 100644 --- a/projects/github-actions/repo-gardening/src/tasks/add-labels/index.js +++ b/projects/github-actions/repo-gardening/src/tasks/add-labels/index.js @@ -1,7 +1,6 @@ const { getInput } = require( '@actions/core' ); const debug = require( '../../utils/debug' ); const getFiles = require( '../../utils/get-files' ); -const getLabels = require( '../../utils/labels/get-labels' ); /* global GitHub, WebhookPayloadPullRequest */ @@ -52,17 +51,17 @@ function cleanName( name ) { /** * Build a list of labels to add to the pull request, based off our file list. * - * @param {GitHub} octokit - Initialized Octokit REST client. - * @param {string} owner - Repository owner. - * @param {string} repo - Repository name. - * @param {string} number - PR number. - * @param {boolean} isDraft - Whether the pull request is a draft. - * @param {boolean} isRevert - Whether the pull request is a revert. - * @param {array} currentLabels - Current labels on the pull request. + * @param {GitHub} octokit - Initialized Octokit REST client. + * @param {string} owner - Repository owner. + * @param {string} repo - Repository name. + * @param {string} number - PR number. + * @param {boolean} isDraft - Whether the pull request is a draft. + * @param {boolean} isRevert - Whether the pull request is a revert. + * @param {array} curLabels - Current labels on the pull request. * @return {Promise} Promise resolving to an array of keywords we'll search for. */ -async function getLabelsToAdd( octokit, owner, repo, number, isDraft, isRevert, currentLabels ) { - const keywords = new Set( currentLabels ); +async function getLabelsToAdd( octokit, owner, repo, number, isDraft, isRevert, curLabels ) { + const keywords = new Set( curLabels ); // Get next valid milestone. const files = await getFiles( octokit, owner, repo, number ); @@ -340,7 +339,7 @@ async function addLabels( payload, octokit ) { const currentLabels = payload.pull_request.labels.map( l => l.name ); console.log(1,currentLabels); - const labelsToAdd = await getLabelsToAdd( octokit, owner.login, name, number, isDraft, isRevert, currentLabels ); + let labelsToAdd = await getLabelsToAdd( octokit, owner.login, name, number, isDraft, isRevert, currentLabels ); console.log(2,labelsToAdd); // Nothing new was added, so abort. @@ -351,7 +350,7 @@ async function addLabels( payload, octokit ) { // Limit to 90 labels to allow for additional labels elsewhere. const bigLabel = 'All the things (90+ labels)'; - if ( labelsToAdd.length > 2 ) { + if ( labelsToAdd.length > 1 ) { debug( 'add-labels: GitHub only allows 100 labels on a PR, so limiting to the first 90.' ); labelsToAdd.splice( 90 ); labelsToAdd.push( bigLabel ); From 3615376c22642fa2dbda7052afb52d38eaa53a19 Mon Sep 17 00:00:00 2001 From: tbradsha <32492176+tbradsha@users.noreply.github.com> Date: Fri, 6 Dec 2024 14:33:07 -0700 Subject: [PATCH 08/15] Update index.js --- .../src/tasks/add-labels/index.js | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/projects/github-actions/repo-gardening/src/tasks/add-labels/index.js b/projects/github-actions/repo-gardening/src/tasks/add-labels/index.js index 4ee4fe351be6..c0f967310d78 100644 --- a/projects/github-actions/repo-gardening/src/tasks/add-labels/index.js +++ b/projects/github-actions/repo-gardening/src/tasks/add-labels/index.js @@ -51,13 +51,13 @@ function cleanName( name ) { /** * Build a list of labels to add to the pull request, based off our file list. * - * @param {GitHub} octokit - Initialized Octokit REST client. - * @param {string} owner - Repository owner. - * @param {string} repo - Repository name. - * @param {string} number - PR number. - * @param {boolean} isDraft - Whether the pull request is a draft. - * @param {boolean} isRevert - Whether the pull request is a revert. - * @param {array} curLabels - Current labels on the pull request. + * @param {GitHub} octokit - Initialized Octokit REST client. + * @param {string} owner - Repository owner. + * @param {string} repo - Repository name. + * @param {string} number - PR number. + * @param {boolean} isDraft - Whether the pull request is a draft. + * @param {boolean} isRevert - Whether the pull request is a revert. + * @param {string[]} curLabels - Current labels on the pull request. * @return {Promise} Promise resolving to an array of keywords we'll search for. */ async function getLabelsToAdd( octokit, owner, repo, number, isDraft, isRevert, curLabels ) { @@ -338,9 +338,7 @@ async function addLabels( payload, octokit ) { const isRevert = title.toLowerCase().includes( 'revert' ); const currentLabels = payload.pull_request.labels.map( l => l.name ); - console.log(1,currentLabels); let labelsToAdd = await getLabelsToAdd( octokit, owner.login, name, number, isDraft, isRevert, currentLabels ); - console.log(2,labelsToAdd); // Nothing new was added, so abort. if ( labelsToAdd.length === currentLabels.length ) { @@ -357,7 +355,6 @@ async function addLabels( payload, octokit ) { } else if ( labelsToAdd.includes( bigLabel ) ) { labelsToAdd = labelsToAdd.filter( label => label !== bigLabel ); } - console.log(3,labelsToAdd); debug( `add-labels: Adding labels ${ labelsToAdd } to PR #${ number }` ); From 8a08a48c16df061920f8fe63fe4fe8a2cf6da2fb Mon Sep 17 00:00:00 2001 From: tbradsha <32492176+tbradsha@users.noreply.github.com> Date: Fri, 13 Dec 2024 10:25:06 -0700 Subject: [PATCH 09/15] Update index.js --- .../src/tasks/add-labels/index.js | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/projects/github-actions/repo-gardening/src/tasks/add-labels/index.js b/projects/github-actions/repo-gardening/src/tasks/add-labels/index.js index c0f967310d78..3bb3b4fdea12 100644 --- a/projects/github-actions/repo-gardening/src/tasks/add-labels/index.js +++ b/projects/github-actions/repo-gardening/src/tasks/add-labels/index.js @@ -338,7 +338,15 @@ async function addLabels( payload, octokit ) { const isRevert = title.toLowerCase().includes( 'revert' ); const currentLabels = payload.pull_request.labels.map( l => l.name ); - let labelsToAdd = await getLabelsToAdd( octokit, owner.login, name, number, isDraft, isRevert, currentLabels ); + let labelsToAdd = await getLabelsToAdd( + octokit, + owner.login, + name, + number, + isDraft, + isRevert, + currentLabels + ); // Nothing new was added, so abort. if ( labelsToAdd.length === currentLabels.length ) { @@ -346,11 +354,16 @@ async function addLabels( payload, octokit ) { return; } - // Limit to 90 labels to allow for additional labels elsewhere. - const bigLabel = 'All the things (90+ labels)'; - if ( labelsToAdd.length > 1 ) { - debug( 'add-labels: GitHub only allows 100 labels on a PR, so limiting to the first 90.' ); - labelsToAdd.splice( 90 ); + // GitHub allows 100 labels on a PR. Limit to less than that to allow for additional labels elsewhere. + const maxLabels = 90; + const bigLabel = 'All the things (>' + maxLabels + ' labels)'; + if ( labelsToAdd.length > maxLabels ) { + debug( + 'add-labels: GitHub only allows 100 labels on a PR, so limiting to the first ' + + maxLabels + + '.' + ); + labelsToAdd.splice( maxLabels ); labelsToAdd.push( bigLabel ); } else if ( labelsToAdd.includes( bigLabel ) ) { labelsToAdd = labelsToAdd.filter( label => label !== bigLabel ); From a8a8e4d606e835b9411799093844bd1afaa759ea Mon Sep 17 00:00:00 2001 From: tbradsha <32492176+tbradsha@users.noreply.github.com> Date: Fri, 13 Dec 2024 12:12:16 -0700 Subject: [PATCH 10/15] Update index.js --- .../src/tasks/add-labels/index.js | 76 +++++++++++++------ 1 file changed, 54 insertions(+), 22 deletions(-) diff --git a/projects/github-actions/repo-gardening/src/tasks/add-labels/index.js b/projects/github-actions/repo-gardening/src/tasks/add-labels/index.js index 3bb3b4fdea12..c9c59c83a369 100644 --- a/projects/github-actions/repo-gardening/src/tasks/add-labels/index.js +++ b/projects/github-actions/repo-gardening/src/tasks/add-labels/index.js @@ -1,6 +1,7 @@ const { getInput } = require( '@actions/core' ); const debug = require( '../../utils/debug' ); const getFiles = require( '../../utils/get-files' ); +const getLabels = require( '../../utils/labels/get-labels' ); /* global GitHub, WebhookPayloadPullRequest */ @@ -57,11 +58,10 @@ function cleanName( name ) { * @param {string} number - PR number. * @param {boolean} isDraft - Whether the pull request is a draft. * @param {boolean} isRevert - Whether the pull request is a revert. - * @param {string[]} curLabels - Current labels on the pull request. * @return {Promise} Promise resolving to an array of keywords we'll search for. */ -async function getLabelsToAdd( octokit, owner, repo, number, isDraft, isRevert, curLabels ) { - const keywords = new Set( curLabels ); +async function getFileDerivedLabels( octokit, owner, repo, number, isDraft, isRevert ) { + const keywords = new Set(); // Get next valid milestone. const files = await getFiles( octokit, owner, repo, number ); @@ -331,47 +331,79 @@ async function addLabels( payload, octokit ) { const { owner, name } = repository; const { draft, title } = pull_request; + // GitHub allows 100 labels on a PR. + // Limit to less than that to allow a buffer for future manual labels. + const maxLabels = 1; + const bigProjectLabel = '[Project] All the things!'; + // Get labels to add to the PR. const isDraft = !! ( pull_request && draft ); // If the PR title includes the word "revert", mark it as such. const isRevert = title.toLowerCase().includes( 'revert' ); - const currentLabels = payload.pull_request.labels.map( l => l.name ); - let labelsToAdd = await getLabelsToAdd( + let fileDerivedLabels = await getFileDerivedLabels( octokit, owner.login, name, number, isDraft, - isRevert, - currentLabels + isRevert ); + // Grab current labels on the PR. + // We can't rely on payload, as it could be outdated by the time this runs. + const currentLabels = await getLabels( octokit, owner, repository, number ); + const hasBigProjectLabel = currentLabels.includes( bigProjectLabel ); + + // This is an array of labels that GitHub doesn't already have. + let labelsToAdd = fileDerivedLabels.filter( label => ! currentLabels.includes( label ) ); + // Nothing new was added, so abort. - if ( labelsToAdd.length === currentLabels.length ) { + if ( labelsToAdd.length === 0 ) { debug( 'add-labels: No new labels to add to that PR. Aborting.' ); return; } - // GitHub allows 100 labels on a PR. Limit to less than that to allow for additional labels elsewhere. - const maxLabels = 90; - const bigLabel = 'All the things (>' + maxLabels + ' labels)'; - if ( labelsToAdd.length > maxLabels ) { - debug( - 'add-labels: GitHub only allows 100 labels on a PR, so limiting to the first ' + - maxLabels + - '.' - ); - labelsToAdd.splice( maxLabels ); - labelsToAdd.push( bigLabel ); - } else if ( labelsToAdd.includes( bigLabel ) ) { - labelsToAdd = labelsToAdd.filter( label => label !== bigLabel ); + // Determine how many labels can safely be added. + let maxLabelsToAdd = maxLabels - currentLabels.length; + + // Overkill, but let's prevent this label from counting toward the max. + if ( hasBigProjectLabel ) { + maxLabelsToAdd++; + } + + // If there are too many labels, we need to reduce the label count to keep GitHub happy. + if ( labelsToAdd.length > maxLabelsToAdd ) { + debug( `add-labels: Too many labels! Grouping project labels into '${bigProjectLabel}'.` ); + + // Filter out project-type labels in deference to bigProjectLabel. + // In theory we could also remove any existing project-type labels here, but for now + // let's not as that would prevent manually adding specific project labels. + const projectLabelRegex = /^(\[Action\]|\[Package\]|\[Plugin\]|\[JS Package\])/; + labelsToAdd = labelsToAdd.filter( label => ! projectLabelRegex.test( label ) ); + + if ( ! hasBigProjectLabel ) { + // Add to the beginning of the labels array in case the array gets truncated later on. + labelsToAdd.unshift( bigProjectLabel ); + } + } else if ( hasBigProjectLabel ) { + await octokit.rest.issues.removeLabel( { + owner, + repo, + issue_number: number, + name: bigProjectLabel, + } ); + } + // In the rare chance there would still be too many labels... + if ( labelsToAdd.length > maxLabelsToAdd ) { + debug( `add-labels: Limiting to the first ${maxLabels}.` ); + labelsToAdd.splice( maxLabelsToAdd ); } debug( `add-labels: Adding labels ${ labelsToAdd } to PR #${ number }` ); - await octokit.rest.issues.setLabels( { + await octokit.rest.issues.addLabels( { owner: owner.login, repo: name, issue_number: number, From d33953d576483960dc158510d08168ad63e6240b Mon Sep 17 00:00:00 2001 From: tbradsha <32492176+tbradsha@users.noreply.github.com> Date: Fri, 13 Dec 2024 12:25:13 -0700 Subject: [PATCH 11/15] Update index.js --- .../repo-gardening/src/tasks/add-labels/index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/projects/github-actions/repo-gardening/src/tasks/add-labels/index.js b/projects/github-actions/repo-gardening/src/tasks/add-labels/index.js index c9c59c83a369..3326b24d2d76 100644 --- a/projects/github-actions/repo-gardening/src/tasks/add-labels/index.js +++ b/projects/github-actions/repo-gardening/src/tasks/add-labels/index.js @@ -353,7 +353,7 @@ async function addLabels( payload, octokit ) { // Grab current labels on the PR. // We can't rely on payload, as it could be outdated by the time this runs. - const currentLabels = await getLabels( octokit, owner, repository, number ); + const currentLabels = await getLabels( octokit, owner.login, name, number ); const hasBigProjectLabel = currentLabels.includes( bigProjectLabel ); // This is an array of labels that GitHub doesn't already have. @@ -389,8 +389,8 @@ async function addLabels( payload, octokit ) { } } else if ( hasBigProjectLabel ) { await octokit.rest.issues.removeLabel( { - owner, - repo, + owner: owner.login, + name, issue_number: number, name: bigProjectLabel, } ); From d14f0a1f4aa33c4e0cce4322bf5a1a2a02d466d6 Mon Sep 17 00:00:00 2001 From: tbradsha <32492176+tbradsha@users.noreply.github.com> Date: Fri, 13 Dec 2024 12:32:39 -0700 Subject: [PATCH 12/15] Update index.js --- .../github-actions/repo-gardening/src/tasks/add-labels/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/github-actions/repo-gardening/src/tasks/add-labels/index.js b/projects/github-actions/repo-gardening/src/tasks/add-labels/index.js index 3326b24d2d76..0dac96a0745f 100644 --- a/projects/github-actions/repo-gardening/src/tasks/add-labels/index.js +++ b/projects/github-actions/repo-gardening/src/tasks/add-labels/index.js @@ -333,7 +333,7 @@ async function addLabels( payload, octokit ) { // GitHub allows 100 labels on a PR. // Limit to less than that to allow a buffer for future manual labels. - const maxLabels = 1; + const maxLabels = 3; const bigProjectLabel = '[Project] All the things!'; // Get labels to add to the PR. From b34ac490d9958d101936c71d93786eef3ccdb915 Mon Sep 17 00:00:00 2001 From: tbradsha <32492176+tbradsha@users.noreply.github.com> Date: Fri, 13 Dec 2024 12:36:01 -0700 Subject: [PATCH 13/15] Update index.js --- .../github-actions/repo-gardening/src/tasks/add-labels/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/github-actions/repo-gardening/src/tasks/add-labels/index.js b/projects/github-actions/repo-gardening/src/tasks/add-labels/index.js index 0dac96a0745f..ac89da55a55f 100644 --- a/projects/github-actions/repo-gardening/src/tasks/add-labels/index.js +++ b/projects/github-actions/repo-gardening/src/tasks/add-labels/index.js @@ -333,7 +333,7 @@ async function addLabels( payload, octokit ) { // GitHub allows 100 labels on a PR. // Limit to less than that to allow a buffer for future manual labels. - const maxLabels = 3; + const maxLabels = 5; const bigProjectLabel = '[Project] All the things!'; // Get labels to add to the PR. From f6c8513c9d5b179fd09f94a6c59aad995d39304f Mon Sep 17 00:00:00 2001 From: tbradsha <32492176+tbradsha@users.noreply.github.com> Date: Fri, 13 Dec 2024 12:38:22 -0700 Subject: [PATCH 14/15] Update index.js --- .../github-actions/repo-gardening/src/tasks/add-labels/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/github-actions/repo-gardening/src/tasks/add-labels/index.js b/projects/github-actions/repo-gardening/src/tasks/add-labels/index.js index ac89da55a55f..8ced9d2ec9b1 100644 --- a/projects/github-actions/repo-gardening/src/tasks/add-labels/index.js +++ b/projects/github-actions/repo-gardening/src/tasks/add-labels/index.js @@ -366,7 +366,7 @@ async function addLabels( payload, octokit ) { } // Determine how many labels can safely be added. - let maxLabelsToAdd = maxLabels - currentLabels.length; + let maxLabelsToAdd = Math.max( 0, maxLabels - currentLabels.length ); // Overkill, but let's prevent this label from counting toward the max. if ( hasBigProjectLabel ) { From c692f4c852687833837a8c1b2e305fb76bfb4e17 Mon Sep 17 00:00:00 2001 From: tbradsha <32492176+tbradsha@users.noreply.github.com> Date: Fri, 13 Dec 2024 16:14:22 -0700 Subject: [PATCH 15/15] Update index.js --- .../repo-gardening/src/tasks/add-labels/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/projects/github-actions/repo-gardening/src/tasks/add-labels/index.js b/projects/github-actions/repo-gardening/src/tasks/add-labels/index.js index 8ced9d2ec9b1..d0447d01b122 100644 --- a/projects/github-actions/repo-gardening/src/tasks/add-labels/index.js +++ b/projects/github-actions/repo-gardening/src/tasks/add-labels/index.js @@ -354,7 +354,6 @@ async function addLabels( payload, octokit ) { // Grab current labels on the PR. // We can't rely on payload, as it could be outdated by the time this runs. const currentLabels = await getLabels( octokit, owner.login, name, number ); - const hasBigProjectLabel = currentLabels.includes( bigProjectLabel ); // This is an array of labels that GitHub doesn't already have. let labelsToAdd = fileDerivedLabels.filter( label => ! currentLabels.includes( label ) ); @@ -369,6 +368,7 @@ async function addLabels( payload, octokit ) { let maxLabelsToAdd = Math.max( 0, maxLabels - currentLabels.length ); // Overkill, but let's prevent this label from counting toward the max. + const hasBigProjectLabel = currentLabels.includes( bigProjectLabel ); if ( hasBigProjectLabel ) { maxLabelsToAdd++; } @@ -390,7 +390,7 @@ async function addLabels( payload, octokit ) { } else if ( hasBigProjectLabel ) { await octokit.rest.issues.removeLabel( { owner: owner.login, - name, + repo: name, issue_number: number, name: bigProjectLabel, } );