From 43e07a4941a58fdf80304e7ee83d7df3f7182f3a Mon Sep 17 00:00:00 2001 From: Gabriel Donadel Dall'Agnol Date: Tue, 18 Jan 2022 23:51:51 -0800 Subject: [PATCH] chore(dangerfile): Auto-label pull requests opened against release branches (#32917) Summary: ## Summary Update dangerfile in order auto-label pull requests opened against release branches Closes https://github.com/facebook/react-native/issues/32692 ## Changelog [Internal] [Added] - Auto-label pull requests opened against release branches Pull Request resolved: https://github.com/facebook/react-native/pull/32917 Test Plan: As I don't have admin rights to this repo I tested this script on [a PR in my fork](https://github.com/gabrieldonadel/react-native/pull/1) by running ``` yarn danger pr https://github.com/gabrieldonadel/react-native/pull/1 ``` https://user-images.githubusercontent.com/11707729/150026370-4cce7831-c4ee-4269-b6a8-646f965826c5.mov As you can see in the video once I run the script it automatically adds the label Reviewed By: lunaleaps Differential Revision: D33647174 Pulled By: yungsters fbshipit-source-id: a7e7cab458b4cb7ff2cf318c4df1e9fb5d91a9f7 --- bots/dangerfile.js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/bots/dangerfile.js b/bots/dangerfile.js index faa76671a5c..30545cbd078 100644 --- a/bots/dangerfile.js +++ b/bots/dangerfile.js @@ -89,11 +89,26 @@ if (!includesChangelog) { // Warns if the PR is opened against stable, as commits need to be cherry picked and tagged by a release maintainer. // Fails if the PR is opened against anything other than `main` or `-stable`. -const isMergeRefMaster = danger.github.pr.base.ref === 'main'; +const isMergeRefMain = danger.github.pr.base.ref === 'main'; const isMergeRefStable = danger.github.pr.base.ref.indexOf('-stable') !== -1; -if (!isMergeRefMaster && !isMergeRefStable) { +if (!isMergeRefMain && !isMergeRefStable) { const title = ':exclamation: Base Branch'; const idea = 'The base branch for this PR is something other than `main` or a `-stable` branch. [Are you sure you want to target something other than the `main` branch?](https://reactnative.dev/docs/contributing#pull-requests)'; fail(`${title} - ${idea}`); } + +// If the PR is opened against stable should add `Pick Request` label +if (isMergeRefStable) { + const {owner, repo, number: issueNumber} = danger.github.thisPR; + + danger.github.api.request( + 'POST /repos/{owner}/{repo}/issues/{issueNumber}/labels', + { + owner, + repo, + issueNumber, + labels: ['Pick Request'], + }, + ); +}