Skip to content

Commit 5bd102f

Browse files
committed
feat: add support for marking some packages as required
1 parent 0ad9675 commit 5bd102f

File tree

4 files changed

+37
-17
lines changed

4 files changed

+37
-17
lines changed

README.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,14 @@ jobs:
2222
check-versions:
2323
runs-on: ubuntu-latest
2424
steps:
25-
- uses: react-navigation/check-versions-action@v1
25+
- uses: react-navigation/check-versions-action@v1.0.0
2626
with:
2727
github-token: ${{ secrets.GITHUB_TOKEN }}
28-
packages: |
28+
required-packages: |
2929
@react-navigation/native
30+
optional-packages: |
31+
@react-navigation/bottom-tabs
32+
@react-navigation/drawer
3033
@react-navigation/stack
3134
missing-versions-label: 'needs more info'
3235
```
@@ -39,9 +42,13 @@ Make sure to change the `packages` list and the `missing-versions-label`.
3942

4043
The `GITHUB_TOKEN` secret. This is needed so that we can post comments on the issue.
4144

42-
### `packages` (`required`)
45+
### `required-packages`
4346

44-
List of packages to check for. The action will match the content of the issue against these package names to find mentioned versions. If there are packages present in the issue, but not mentioned in this list, then they will be ignored.
47+
List of required packages to check for. The action will match the content of the issue against these package names to find mentioned versions. If the packages are not mentioned or their version is not mentioned in the issue, the action will mark them as missing.
48+
49+
### `optional-packages`
50+
51+
List of optional packages to check for. The action will match the content of the issue against these package names to find mentioned versions. If there are packages present in the issue, but not mentioned in this list, then they will be ignored.
4552

4653
### `comment`
4754

action.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ inputs:
1010
github-token:
1111
description: The `GITHUB_TOKEN` secret.
1212
required: true
13-
packages:
14-
description: 'List of packages to check for'
15-
required: true
13+
required-packages:
14+
description: 'List of optional packages to check for'
15+
optional-packages:
16+
description: 'List of optional packages to check for'
1617
comment:
1718
description: 'Whether to comment on the issue when missing or outdated versions are found'
1819
default: true

src/check-versions.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,22 @@ const REGISTRY = 'https://registry.npmjs.org';
66
* Check package versions in the markdown content
77
*
88
* @param {string} body
9-
* @param {string[]} packages
9+
* @param {string[]} optionalPackages
10+
* @param {string[]} requiredPackages
1011
*/
11-
async function checkVersions(body, packages) {
12+
async function checkVersions(body, optionalPackages, requiredPackages) {
1213
const lines = body.split('\n');
1314

15+
const missing = requiredPackages.reduce((acc, curr) => {
16+
acc[curr] = true;
17+
return acc;
18+
}, {});
19+
1420
const found = {};
15-
const missing = {};
1621
const outdated = {};
1722

23+
const packages = [...requiredPackages, ...optionalPackages];
24+
1825
for (const line of lines) {
1926
for (const p of packages) {
2027
if (line.includes(p)) {
@@ -30,8 +37,8 @@ async function checkVersions(body, packages) {
3037
if (parts[i] === p) {
3138
// Strip semver symbols and v prefix
3239
const version = parts[i + 1]
33-
.replace(/^v/, '')
34-
.replace(/[\^\~]/, '');
40+
? parts[i + 1].replace(/^v/, '').replace(/[\^\~]/, '')
41+
: undefined;
3542

3643
// Check if version matches the proper format
3744
if (version && /^\d+\.\d+\.\d+/.test(version)) {

src/index.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,25 @@ const checkVersions = require('./check-versions');
1010
core.getInput('github-token', { required: true })
1111
);
1212

13-
const packages = core
14-
.getInput('packages', { required: true })
13+
const optionalPackages = (core.getInput('optional-packages') || '')
14+
.split(/\r?\n/)
15+
.map((p) => p.trim());
16+
17+
const requiredPackages = (core.getInput('required-packages') || '')
1518
.split(/\r?\n/)
1619
.map((p) => p.trim());
1720

1821
const { found, missing, outdated } = await checkVersions(
1922
payload.issue.body,
20-
packages
23+
optionalPackages,
24+
requiredPackages
2125
);
2226

2327
const messages = [];
2428

2529
if (Object.keys(missing).length) {
2630
messages.push(
27-
`Found the following packages mentioned in the issue, but couldn't find version numbers for them:
31+
`Couldn't find version numbers for the following packages in the issue:
2832
${Object.keys(missing)
2933
.map((p) => `- \`${p}\``)
3034
.join('\n')}
@@ -84,6 +88,7 @@ Can you verify that the issue still exists after upgrading to the latest version
8488

8589
core.setOutput('missing', Object.keys(missing).join(','));
8690
} catch (e) {
87-
core.setFailed(error.message);
91+
console.log(e);
92+
core.setFailed(e.message);
8893
}
8994
})();

0 commit comments

Comments
 (0)