mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
37d1e8e7a0
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/45480 We currently use the default GITHUB_ACTION which makes a lot of interaction appear as user "GitHub Actions". Instead we could use the `REACT_NATIVE_BOT_GITHUB_TOKEN` which we have as secret so the bot will actually perform the actions. Changelog: [Internal] [Changed] - Act as react-native-bot on all the actions Reviewed By: cipolleschi Differential Revision: D59815201 fbshipit-source-id: 702b121ec07d0db10abf25e23f7ddf5658dd5d62
64 lines
2.7 KiB
YAML
64 lines
2.7 KiB
YAML
name: Label closed PR as merged and leave a comment
|
|
on:
|
|
push
|
|
|
|
permissions:
|
|
contents: read
|
|
pull-requests: write
|
|
|
|
jobs:
|
|
comment-and-label:
|
|
runs-on: ubuntu-latest
|
|
if: github.repository == 'facebook/react-native'
|
|
steps:
|
|
- uses: actions/github-script@v6
|
|
with:
|
|
github-token: ${{ secrets.REACT_NATIVE_BOT_GITHUB_TOKEN }}
|
|
script: |
|
|
if(!context.payload.commits || !context.payload.commits.length) return;
|
|
const sha = context.payload.commits[0].id;
|
|
|
|
const {commit, author} = (await github.rest.repos.getCommit({
|
|
ref: sha,
|
|
owner: context.repo.owner,
|
|
repo: context.repo.repo,
|
|
})).data;
|
|
|
|
// Looking at the commit message, checks which PR number, if any, was closed by this commit
|
|
const getClosedPrIfExists = (commit) => {
|
|
if(!commit || !commit.message) return;
|
|
const prClosingRegex = /Closes https:\/\/github.com\/facebook\/react-native\/pull\/([0-9]+)|Pull Request resolved: https:\/\/github.com\/facebook\/react-native\/pull\/([0-9]+)/;
|
|
const prClosingMatch = commit.message.match(prClosingRegex);
|
|
if(!prClosingMatch || (!prClosingMatch[1] && ! prClosingMatch[2])) return;
|
|
return prClosingMatch[1] ?? prClosingMatch[2];
|
|
};
|
|
|
|
const closedPrNumber = getClosedPrIfExists(commit);
|
|
if(!closedPrNumber) return;
|
|
|
|
const pr = (await github.rest.pulls.get({
|
|
pull_number: closedPrNumber,
|
|
owner: context.repo.owner,
|
|
repo: context.repo.repo,
|
|
})).data;
|
|
|
|
const authorName = author?.login ? `@${author.login}` : commit.author.name;
|
|
|
|
github.rest.issues.createComment({
|
|
issue_number: closedPrNumber,
|
|
owner: context.repo.owner,
|
|
repo: context.repo.repo,
|
|
body: `This pull request was successfully merged by ${authorName} in **${sha}**\n\n<sup>[When will my fix make it into a release?](https://github.com/reactwg/react-native-releases/blob/main/docs/faq.md#when-will-my-fix-make-it-into-a-release) | [How to file a pick request?](https://github.com/reactwg/react-native-releases/blob/main/docs/faq.md#how-to-open-a-pick-request)</sup>`
|
|
});
|
|
|
|
// If the PR has already been processed (labeled as Merged), skip it
|
|
const mergedLabel = "Merged";
|
|
if(pr.labels && pr.labels.some(label => label.name === mergedLabel)) return;
|
|
|
|
github.rest.issues.addLabels({
|
|
issue_number: closedPrNumber,
|
|
owner: context.repo.owner,
|
|
repo: context.repo.repo,
|
|
labels: [mergedLabel]
|
|
});
|