Skip to content

Commit f192873

Browse files
Fix PR link regexes after the move to react/react-native
Two regexes still look only for github.com/facebook/react-native: - close-pr.yml does not find "Pull Request resolved: https://github.com/react/react-native/pull/N" in the commit message, so react-native-bot stopped leaving the "This pull request was successfully merged" comment after the move. - checkForReproducer.js does not accept a link to a pull request as a reproducer. The pattern is a template literal, so "\d" became "d", and it only allowed "facebook". Issues with such a link got "Needs: Repro". Both regexes now accept "facebook" and "react", because people still write links with "facebook". Add a test for pull request links in checkForReproducer.
1 parent e04aaf6 commit f192873

3 files changed

Lines changed: 73 additions & 2 deletions

File tree

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @format
8+
*/
9+
10+
'use strict';
11+
12+
const checkForReproducer = require('../checkForReproducer');
13+
14+
const ISSUE_AUTHOR = 'issue-author';
15+
16+
function buildGithub(body) {
17+
return {
18+
rest: {
19+
issues: {
20+
get: jest.fn().mockResolvedValue({
21+
data: {
22+
user: {login: ISSUE_AUTHOR},
23+
created_at: '2026-10-01T00:00:00Z',
24+
body,
25+
},
26+
}),
27+
listComments: jest.fn().mockResolvedValue({data: []}),
28+
listEventsForTimeline: jest.fn().mockResolvedValue({data: []}),
29+
removeLabel: jest.fn().mockResolvedValue({}),
30+
addLabels: jest.fn().mockResolvedValue({}),
31+
},
32+
},
33+
};
34+
}
35+
36+
const context = {
37+
repo: {owner: 'react', repo: 'react-native'},
38+
payload: {issue: {number: 1}},
39+
};
40+
41+
describe('checkForReproducer reproducer links', () => {
42+
test.each([
43+
'https://github.com/react/react-native/pull/58972',
44+
'https://github.com/facebook/react-native/pull/58972',
45+
])('accepts a pull request link as a reproducer: %s', async link => {
46+
const github = buildGithub(`Reproducer: ${link}`);
47+
48+
await checkForReproducer(github, context);
49+
50+
expect(github.rest.issues.removeLabel).toHaveBeenCalledWith(
51+
expect.objectContaining({name: 'Needs: Repro'}),
52+
);
53+
expect(github.rest.issues.addLabels).not.toHaveBeenCalled();
54+
});
55+
56+
test.each([
57+
'Reproducer: https://github.com/someone-else/some-repo/pull/12',
58+
'It crashes when I scroll.',
59+
])('asks for a reproducer when there is none: %s', async body => {
60+
const github = buildGithub(body);
61+
62+
await checkForReproducer(github, context);
63+
64+
expect(github.rest.issues.addLabels).toHaveBeenCalledWith(
65+
expect.objectContaining({
66+
labels: ['Needs: Repro', 'Needs: Author Feedback'],
67+
}),
68+
);
69+
expect(github.rest.issues.removeLabel).not.toHaveBeenCalled();
70+
});
71+
});

‎.github/workflow-scripts/checkForReproducer.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ module.exports = async (github, context) => {
4343
const hasValidReproducer = entities.some(entity => {
4444
const hasPullRequestRepoLink = containsPattern(
4545
entity.body,
46-
`https?:\/\/github\.com\/facebook\/react-native\/pull\/\d+\/?`,
46+
`https?:\\/\\/github\\.com\\/(?:facebook|react)\\/react-native\\/pull\\/\\d+\\/?`,
4747
);
4848

4949
const hasExpoSnackLink = containsPattern(

‎.github/workflows/close-pr.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
// Looking at the commit message, checks which PR number, if any, was closed by this commit
2727
const getClosedPrIfExists = (commit) => {
2828
if(!commit || !commit.message) return;
29-
const prClosingRegex = /Closes https:\/\/github.com\/facebook\/react-native\/pull\/([0-9]+)|Pull Request resolved: https:\/\/github.com\/facebook\/react-native\/pull\/([0-9]+)/;
29+
const prClosingRegex = /Closes https:\/\/github.com\/(?:facebook|react)\/react-native\/pull\/([0-9]+)|Pull Request resolved: https:\/\/github.com\/(?:facebook|react)\/react-native\/pull\/([0-9]+)/;
3030
const prClosingMatch = commit.message.match(prClosingRegex);
3131
if(!prClosingMatch || (!prClosingMatch[1] && ! prClosingMatch[2])) return;
3232
return prClosingMatch[1] ?? prClosingMatch[2];

0 commit comments

Comments
 (0)