From b6f269e8a32f6048428e9dc135457cdcfde5fb2f Mon Sep 17 00:00:00 2001 From: Olga Zinoveva Date: Tue, 9 May 2023 10:19:47 -0700 Subject: [PATCH] Enhance labeling workflow (#37324) Summary: This PR does two things: 1. Improves the labeling workflow in cases where the user is on a supported version but a higher patch number is available. Now, the label name will be friendlier ('Newer Patch Available') and we will report the version they should consider upgrading to in the message body. Once this change is merged, I can also rename all existing versions of this label for consistency. 2. Moves the addDescriptiveLabels.js script to the workflow-scripts folder for consistency with the other workflow scripts. ## Changelog: [INTERNAL] [CHANGED] - Enhancing issue triage workflow for patch versioning Pull Request resolved: https://github.com/facebook/react-native/pull/37324 Test Plan: See some examples of the workflow run in my fork: https://github.com/SlyCaptainFlint/react-native/issues Reviewed By: cipolleschi Differential Revision: D45680812 Pulled By: NickGerleman fbshipit-source-id: 7ab07fcf52fe372d2e449bb43d6618b1c98e9245 --- .github/workflow-scripts/actOnLabel.js | 8 ++++---- .../addDescriptiveLabels.js | 0 .github/workflow-scripts/verifyVersion.js | 9 ++++++--- .github/workflows/on-issue-labeled.yml | 12 ++++++------ 4 files changed, 16 insertions(+), 13 deletions(-) rename .github/{workflows => workflow-scripts}/addDescriptiveLabels.js (100%) diff --git a/.github/workflow-scripts/actOnLabel.js b/.github/workflow-scripts/actOnLabel.js index 923e6baa44b..78571fd0ac0 100644 --- a/.github/workflow-scripts/actOnLabel.js +++ b/.github/workflow-scripts/actOnLabel.js @@ -7,7 +7,7 @@ * @format */ -module.exports = async (github, context, label) => { +module.exports = async (github, context, labelWithContext) => { const closeIssue = async () => { await github.rest.issues.update({ issue_number: context.issue.number, @@ -45,7 +45,7 @@ module.exports = async (github, context, label) => { }); }; - switch (label) { + switch (labelWithContext.label) { case 'Type: Invalid': await addComment( `| :warning: | Issue is Invalid |\n` + @@ -102,11 +102,11 @@ module.exports = async (github, context, label) => { ); await requestAuthorFeedback(); return; - case 'Needs: Verify on Latest Version': + case 'Newer Patch Available': await addComment( `| :warning: | Newer Version of React Native is Available! |\n` + `| --- | --- |\n` + - `| :information_source: | You are on a supported minor version, but it looks like there's a newer patch available. Please [upgrade](https://reactnative.dev/docs/upgrading) to the highest patch for your minor or latest and verify if the issue persists (alternatively, create a new project and repro the issue in it). If it does not repro, please let us know so we can close out this issue. This helps us ensure we are looking at issues that still exist in the most recent releases. |`, + `| :information_source: | You are on a supported minor version, but it looks like there's a newer patch available - ${labelWithContext.newestPatch}. Please [upgrade](https://reactnative.dev/docs/upgrading) to the highest patch for your minor or latest and verify if the issue persists (alternatively, create a new project and repro the issue in it). If it does not repro, please let us know so we can close out this issue. This helps us ensure we are looking at issues that still exist in the most recent releases. |`, ); return; case 'Needs: Version Info': diff --git a/.github/workflows/addDescriptiveLabels.js b/.github/workflow-scripts/addDescriptiveLabels.js similarity index 100% rename from .github/workflows/addDescriptiveLabels.js rename to .github/workflow-scripts/addDescriptiveLabels.js diff --git a/.github/workflow-scripts/verifyVersion.js b/.github/workflow-scripts/verifyVersion.js index da66a1f2f0f..b91efe898ee 100644 --- a/.github/workflow-scripts/verifyVersion.js +++ b/.github/workflow-scripts/verifyVersion.js @@ -23,7 +23,7 @@ module.exports = async (github, context) => { if (reportedVersionIsNightly(issueVersionUnparsed, issueVersion)) return; if (!issueVersion) { - return 'Needs: Version Info'; + return {label: 'Needs: Version Info'}; } // Ensure the version matches one we support @@ -43,7 +43,7 @@ module.exports = async (github, context) => { const latestVersion = parseVersionFromString(latestRelease.name); if (!isVersionSupported(issueVersion, latestVersion)) { - return 'Type: Unsupported Version'; + return {label: 'Type: Unsupported Version'}; } // We want to encourage users to repro the issue on the highest available patch for the given minor. @@ -52,7 +52,10 @@ module.exports = async (github, context) => { recentReleases, ); if (latestPatchForVersion > issueVersion.patch) { - return 'Needs: Verify on Latest Version'; + return { + label: 'Newer Patch Available', + newestPatch: `${issueVersion.major}.${issueVersion.minor}.${latestPatchForVersion}`, + }; } }; diff --git a/.github/workflows/on-issue-labeled.yml b/.github/workflows/on-issue-labeled.yml index f4e976bd3d9..14f9d4e9c5d 100644 --- a/.github/workflows/on-issue-labeled.yml +++ b/.github/workflows/on-issue-labeled.yml @@ -23,25 +23,25 @@ jobs: with: script: | const verifyVersion = require('./.github/workflow-scripts/verifyVersion.js') - const labelToAdd = await verifyVersion(github, context); + const labelWithContext = await verifyVersion(github, context); - if(labelToAdd) { + if(labelWithContext && labelWithContext.label) { await github.rest.issues.addLabels({ issue_number: context.issue.number, owner: context.repo.owner, repo: context.repo.repo, - labels: [labelToAdd] + labels: [labelWithContext.label] }) const actOnLabel = require('./.github/workflow-scripts/actOnLabel.js') - await actOnLabel(github, context, labelToAdd) + await actOnLabel(github, context, labelWithContext) } - name: Add descriptive label uses: actions/github-script@v6 with: script: | - const addDescriptiveLabel = require('./.github/workflows/addDescriptiveLabels.js') + const addDescriptiveLabel = require('./.github/workflow-scripts/addDescriptiveLabels.js') await addDescriptiveLabel(github, context); # Reacts to the label that triggered this workflow (added manually or via other workflows) @@ -54,4 +54,4 @@ jobs: with: script: | const actOnLabel = require('./.github/workflow-scripts/actOnLabel.js') - await actOnLabel(github, context, context.payload.label.name) + await actOnLabel(github, context, {label: context.payload.label.name})