Skip to content

Commit 2352c3d

Browse files
authored
add option to group results in table by the change type (#66)
1 parent decfba5 commit 2352c3d

File tree

7 files changed

+32
-22
lines changed

7 files changed

+32
-22
lines changed

README.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,14 @@ jobs:
3737
3838
### 🔌 Inputs
3939
40-
| Input | Required | Default | Description |
41-
| --- | :---: | :---: | --- |
42-
| `collapsibleThreshold` | No | `25` | Number of lock changes, which will result in collapsed comment content and an addition of changes summary table. |
43-
| `failOnDowngrade` | No | `false` | When a dependency downgrade is detected, fail the action. __Comment will still be posted.__ |
44-
| `path` | No | `yarn.lock` | Path to the `yarn.lock` file in the repository. Default value points to the file at project root. |
45-
| `token` | <ins>**Yes**</ins> | – | Repository `GITHUB_TOKEN` which allows action to make calls to the GitHub API (Octokit). |
46-
| `updateComment` | No | `true` | Update the comment on each new commit. If value is set to `false`, bot will post a new comment on each change. |
40+
| Input | Required | Default | Description |
41+
|------------------------|:------------------:|:-----------:|-------------------------------------------------------------------------------------------------------------------|
42+
| `collapsibleThreshold` | No | `25` | Number of lock changes, which will result in collapsed comment content, and an addition of changes summary table. |
43+
| `failOnDowngrade` | No | `false` | WFail the action when a dependency downgrade is detected. __Comment will still be posted.__ |
44+
| `path` | No | `yarn.lock` | Path to the `yarn.lock` file in the repository. Default value points to the file at project root. |
45+
| `token` | <ins>**Yes**</ins> | – | Repository `GITHUB_TOKEN` which allows action to make calls to the GitHub API (Octokit). |
46+
| `updateComment` | No | `true` | Update the comment on each new commit. If value is set to `false`, bot will post a new comment on each change. |
47+
| `groupByType` | No | `false` | Group the dependencies in the comment table by the change type. |
4748

4849
## 📸 Preview
4950

action.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ branding:
55
color: 'yellow'
66
inputs:
77
collapsibleThreshold:
8-
description: 'Number of lock changes, which will result in collapsed comment content an addition of summary table.'
8+
description: 'Number of lock changes, which will result in collapsed comment content, and an addition of changes summary table.'
99
required: false
1010
default: '25'
1111
failOnDowngrade:
12-
description: 'When a dependency downgrade is detected, fail the action.'
12+
description: 'Fail the action when a dependency downgrade is detected. Comment will still be posted.'
1313
required: false
1414
default: 'false'
1515
path:
@@ -23,6 +23,10 @@ inputs:
2323
description: 'Update the comment on each new commit. If value is set to "false", bot will post a new one on each change.'
2424
required: false
2525
default: 'true'
26+
groupByType:
27+
description: 'Group the dependencies in the comment table by the change type.'
28+
required: false
29+
default: 'false'
2630
runs:
2731
using: 'node16'
2832
main: 'dist/index.js'

dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "yarn-lock-changes",
3-
"version": "0.11.1",
3+
"version": "0.11.2",
44
"main": "dist/index.js",
55
"repository": "github:Simek/yarn-lock-changes",
66
"author": "Simek <me@simek.dev>",

src/action.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ const run = async () => {
3434
const inputPath = getInput('path');
3535
const updateComment = getBooleanInput('updateComment');
3636
const failOnDowngrade = getBooleanInput('failOnDowngrade');
37+
const groupByType = getBooleanInput('groupByType');
3738
const collapsibleThreshold = Math.max(parseInt(getInput('collapsibleThreshold'), 10), 0);
3839

3940
const { owner, repo, number } = context.issue;
@@ -98,10 +99,10 @@ const run = async () => {
9899
debug('Bot comment ID: ' + commentId);
99100

100101
if (lockChangesCount) {
101-
let diffsTable = createTable(lockChanges);
102+
let diffsTable = createTable(lockChanges, groupByType);
102103

103104
if (diffsTable.length >= 64000) {
104-
diffsTable = createTable(lockChanges, true);
105+
diffsTable = createTable(lockChanges, groupByType, true);
105106
}
106107

107108
const collapsed = lockChangesCount >= collapsibleThreshold;

src/comment.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const { markdownTable } = require('markdown-table');
22

3-
const { STATUS, countStatuses } = require('./utils');
3+
const { STATUS_ORDER, countStatuses } = require('./utils');
44

55
const ASSETS_URL = {
66
ADDED: 'https://git.io/J38HP',
@@ -12,18 +12,23 @@ const ASSETS_URL = {
1212
const getStatusLabel = status =>
1313
`[<sub><img alt="${status}" src="${ASSETS_URL[status]}" height="16" /></sub>](#)`;
1414

15-
export const createTable = (lockChanges, plainStatuses = false) =>
15+
export const createTable = (lockChanges, groupByType = false, plainStatuses = false) =>
1616
markdownTable(
1717
[
1818
['Name', 'Status', 'Previous', 'Current'],
1919
...Object.entries(lockChanges)
20+
.sort((a, b) =>
21+
groupByType
22+
? STATUS_ORDER.indexOf(a[1].status) - STATUS_ORDER.indexOf(b[1].status) ||
23+
a[0].localeCompare(b[0])
24+
: a[0].localeCompare(b[0])
25+
)
2026
.map(([key, { status, previous, current }]) => [
2127
'`' + key + '`',
2228
plainStatuses ? status : getStatusLabel(status),
2329
previous,
2430
current
2531
])
26-
.sort((a, b) => a[0].localeCompare(b[0]))
2732
],
2833
{ align: ['l', 'c', 'c', 'c'], alignDelimiters: false }
2934
);
@@ -37,10 +42,7 @@ export const createSummary = lockChanges =>
3742
markdownTable(
3843
[
3944
['Status', 'Count'],
40-
createSummaryRow(lockChanges, STATUS.ADDED),
41-
createSummaryRow(lockChanges, STATUS.UPDATED),
42-
createSummaryRow(lockChanges, STATUS.DOWNGRADED),
43-
createSummaryRow(lockChanges, STATUS.REMOVED)
45+
...STATUS_ORDER.map(status => createSummaryRow(lockChanges, status))
4446
].filter(Boolean),
4547
{ align: ['l', 'c'], alignDelimiters: false }
4648
);

src/utils.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ const semverValid = require('semver/functions/valid');
66

77
export const STATUS = {
88
ADDED: 'ADDED',
9+
UPDATED: 'UPDATED',
910
DOWNGRADED: 'DOWNGRADED',
10-
REMOVED: 'REMOVED',
11-
UPDATED: 'UPDATED'
11+
REMOVED: 'REMOVED'
1212
};
1313

14+
export const STATUS_ORDER = [STATUS.ADDED, STATUS.UPDATED, STATUS.DOWNGRADED, STATUS.REMOVED];
15+
1416
export const countStatuses = (lockChanges, statusToCount) =>
1517
Object.values(lockChanges).filter(({ status }) => status === statusToCount).length;
1618

0 commit comments

Comments
 (0)