mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
42a2898617
Summary: This PR adds a "check-for-reproducer" GitHub action proposed in https://github.com/facebook/react-native/issues/35591. This GitHub action automatically labels an issue with when no link to GitHub repository under the authors name or link to Snack is present either in the issue body or in the comments. ## Changelog: <!-- Help reviewers and the release process by writing your own changelog entry. Pick one each for the category and type tags: [ANDROID|GENERAL|IOS|INTERNAL] [BREAKING|ADDED|CHANGED|DEPRECATED|REMOVED|FIXED|SECURITY] - Message For more details, see: https://reactnative.dev/contributing/changelogs-in-pull-requests --> [INTERNAL] [ADDED] - Add check-for-reproducer GitHub action Pull Request resolved: https://github.com/facebook/react-native/pull/38338 Test Plan: This action was tested on a private repro mimicking on how GitHub actions are set-up in `facebook/react-native` repository. If you'd want to play around with the action on this private repo just ask for access - provided you're a maintainer. ### Regarding issue body 1. Labels "Needs: Repro" when no link to Expo Snack or a Github repo under the author's name is present in the issue body:  2. Removes the "Needs: Repro" label and deletes the Missing Repro comment when the author edits the issue and provides a link to GitHub repo under their name  3. Removes the "Needs: Repro" label and deletes the Missing Repro comment when the author edits the issue and provides a valid link to Expo Snack  ### Regarding comments 3. Removes the "Needs: Repro" label and deletes the Missing Repro comment when there's a comment with a link to reproduction under issue author's name  4. Removes the "Needs: Repro" label and deletes the Missing Repro comment when there's a comment with a link to Expo Snack  ### Regarding false-positives 5. Adds a "Needs: Repro" label when a link to reprository isn't under the issue author's name  6. Adds a "Needs: Repro" label when a link to Expo Snack's homepage was sent  7. Adds a "Needs: Repro" label when a random link was sent  Reviewed By: NickGerleman Differential Revision: D47511745 Pulled By: cortinico fbshipit-source-id: 2c0e5a989f52b4e50992a3954283f122b14153e0
80 lines
2.0 KiB
JavaScript
80 lines
2.0 KiB
JavaScript
/**
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @format
|
|
*/
|
|
|
|
const NEEDS_REPRO_LABEL = 'Needs: Repro';
|
|
const NEEDS_REPRO_MESSAGE = '| Missing Reproducible Example |';
|
|
|
|
module.exports = async (github, context) => {
|
|
const issueData = {
|
|
issue_number: context.payload.issue.number,
|
|
owner: context.repo.owner,
|
|
repo: context.repo.repo,
|
|
};
|
|
|
|
const issue = await github.rest.issues.get(issueData);
|
|
const comments = await github.rest.issues.listComments(issueData);
|
|
|
|
const botComment = comments.data.find(comment =>
|
|
comment.body.includes(NEEDS_REPRO_MESSAGE),
|
|
);
|
|
|
|
let commentBodies = comments.data.map(comment => comment.body);
|
|
if (botComment) {
|
|
commentBodies = commentBodies.filter(body => body !== botComment.body);
|
|
}
|
|
|
|
const issueAndComments = [issue.data.body, ...commentBodies];
|
|
const issueAndCommentsUniq = [...new Set(issueAndComments)];
|
|
|
|
const user = issue.data.user.login;
|
|
|
|
const hasValidReproducer = issueAndCommentsUniq.some(body => {
|
|
const hasExpoSnackLink = containsPattern(
|
|
body,
|
|
`https?:\\/\\/snack\\.expo\\.dev\\/[^\\s)\\]]+`,
|
|
);
|
|
const hasGithubRepoLink = containsPattern(
|
|
body,
|
|
`https?:\\/\\/github\\.com\\/(${user})\\/[^/]+\\/?\\s?`,
|
|
);
|
|
|
|
return hasExpoSnackLink || hasGithubRepoLink;
|
|
});
|
|
|
|
if (hasValidReproducer) {
|
|
try {
|
|
await github.rest.issues.removeLabel({
|
|
...issueData,
|
|
name: NEEDS_REPRO_LABEL,
|
|
});
|
|
} catch (error) {
|
|
if (!/Label does not exist/.test(error.message)) {
|
|
throw error;
|
|
}
|
|
}
|
|
|
|
if (!botComment) return;
|
|
|
|
await github.rest.issues.deleteComment({
|
|
...issueData,
|
|
comment_id: botComment.id,
|
|
});
|
|
} else {
|
|
await github.rest.issues.addLabels({
|
|
...issueData,
|
|
labels: [NEEDS_REPRO_LABEL],
|
|
});
|
|
}
|
|
};
|
|
|
|
function containsPattern(body, pattern) {
|
|
const regexp = new RegExp(pattern, 'gm');
|
|
return body.search(regexp) !== -1;
|
|
}
|