Auto close issue if version is too old (#38041)

Summary:
*Auto-close* an issue when the version of React Native specified is **TOO OLD**.
Applies `Type: Too Old Version` label and closes such issues using `actOnLabel` workflow.

## Changelog:

[GENERAL] [ADDED] - Auto close issue if version is too old.

Pull Request resolved: https://github.com/facebook/react-native/pull/38041

Test Plan: - Should *auto-close* an issue with `Type: Too Old Version` label

Reviewed By: NickGerleman

Differential Revision: D47331471

Pulled By: cortinico

fbshipit-source-id: 516468299d6923ce72e073a3b7b8b8715d15d6e0
This commit is contained in:
Pranav Yadav
2023-07-10 08:17:16 -07:00
committed by Facebook GitHub Bot
parent 0519c11acd
commit 28dfdb22eb
2 changed files with 37 additions and 1 deletions
+11
View File
@@ -133,5 +133,16 @@ module.exports = async (github, context, labelWithContext) => {
);
await requestAuthorFeedback();
return;
case 'Type: Too Old Version':
await addComment(
`| :warning: | Too Old Version of React Native |\n` +
`| --- | --- |\n` +
`| :information_source: | It looks like your issue or the example you provided uses a [**Too Old Version of React Native**](https://github.com/reactwg/react-native-releases/blob/main/README.md#releases-support-policy).\nDue to the number of issues we receive, we're currently only accepting new issues against one of the supported versions. Please [upgrade](https://reactnative.dev/docs/upgrading) to latest and verify if the issue persists (alternatively, create a new project and repro the issue in it). If you cannot upgrade, please open your issue on [StackOverflow](https://stackoverflow.com/questions/tagged/react-native) to get further community support. |`,
);
await closeIssue();
return;
default:
// No action needed
return;
}
};
+26 -1
View File
@@ -42,6 +42,11 @@ module.exports = async (github, context) => {
).data;
const latestVersion = parseVersionFromString(latestRelease.name);
// We want to "insta-close" an issue if RN version provided is too old. And encourage users to upgrade.
if (isVersionTooOld(issueVersion, latestVersion)) {
return {label: 'Type: Too Old Version'};
}
if (!isVersionSupported(issueVersion, latestVersion)) {
return {label: 'Type: Unsupported Version'};
}
@@ -59,7 +64,11 @@ module.exports = async (github, context) => {
}
};
// We support N-2 minor versions, and the latest major.
/**
* Check if the RN version provided in an issue is supported.
*
* "We support `N-2` minor versions, and the `latest` major".
*/
function isVersionSupported(actualVersion, latestVersion) {
return (
actualVersion.major >= latestVersion.major &&
@@ -67,6 +76,22 @@ function isVersionSupported(actualVersion, latestVersion) {
);
}
/**
* Check if the RN version provided in an issue is too old.
* "We support `N-2` minor versions, and the `latest` major".
*
* A RN version is *too old* if it's:
* - `1` or more *major* behind the *latest major*.
* - `5` or more *minor* behind the *latest minor* in the *same major*. Less aggressive.
* (e.g. If `0.72.0` is the current latest then `0.67.0` and lower is too old for `0.72.0`)
*/
function isVersionTooOld(actualVersion, latestVersion) {
return (
latestVersion.major - actualVersion.major >= 1 ||
latestVersion.minor - actualVersion.minor >= 5
);
}
// Assumes that releases are sorted in the order of recency (i.e. most recent releases are earlier in the list)
// This enables us to stop looking as soon as we find the first release with a matching major/minor version, since
// we know it's the most recent release, therefore the highest patch available.