Skip to content

Commit

Permalink
feature: @putout/plugin-github: add set-add-and-commit (EndBug/add-an…
Browse files Browse the repository at this point in the history
  • Loading branch information
coderaiser committed Nov 1, 2022
1 parent f1fb139 commit be25fd2
Show file tree
Hide file tree
Showing 11 changed files with 139 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
- name: Typos
run: typos --write-changes
- name: Commit fixes
uses: EndBug/add-and-commit@v7
uses: EndBug/add-and-commit@v9
with:
message: "chore: ${{ env.NAME }}: actions: lint ☘️"
- name: Coverage
Expand Down
11 changes: 10 additions & 1 deletion packages/plugin-github/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ npm i @putout/plugin-github -D
"rules": {
"github/set-node-versions": "on",
"github/set-checkout-version": "on",
"github/set-setup-node-version": "on"
"github/set-setup-node-version": "on",
"github/set-add-and-commit": "on"
}
}
```
Expand Down Expand Up @@ -57,6 +58,14 @@ jobs:
+ - uses: actions/setup-node@v3
```

## set-add-and-commit

```diff
steps:
- uses: EndBug/add-and-commit@v7
+ uses: EndBug/add-and-commit@v9
```

## License

MIT
1 change: 1 addition & 0 deletions packages/plugin-github/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ module.exports.rules = {
...getRule('set-node-versions'),
...getRule('set-checkout-version'),
...getRule('set-setup-node-version'),
...getRule('set-add-and-commit'),
};

12 changes: 12 additions & 0 deletions packages/plugin-github/lib/set-add-and-commit/fixture/latest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
__putout_processor_json({
"jobs": {
"build": {
"runs-on": "ubuntu-latest",
"steps": [
{
"uses": 'EndBug/add-and-commit@v9'
},
]
}
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
__putout_processor_json({
"jobs": {
"build": {
"runs-on": "ubuntu-latest",
"steps": [
{
"uses": 'EndBug/add-and-commit@v9'
},
]
}
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
__putout_processor_json({
"jobs": {
"build": {
"runs-on": "ubuntu-latest",
"steps": [
{
"uses": "EndBug/add-and-commit@v7"
},
]
}
}
});
40 changes: 40 additions & 0 deletions packages/plugin-github/lib/set-add-and-commit/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
'use strict';

const {
types,
operator,
} = require('putout');

const {traverseProperty} = require('../traverse-property');

const {
replaceWith,
getTemplateValues,
} = operator;

const {StringLiteral} = types;
const checkoutNode = StringLiteral('EndBug/add-and-commit@v9');

module.exports.report = () => 'Latest version of EndBug/add-and-commit is missing';

module.exports.fix = (path) => {
replaceWith(path, checkoutNode);
};

module.exports.traverse = ({push}) => ({
'__putout_processor_json(__a)'(path) {
const {__a} = getTemplateValues(path, '__putout_processor_json(__a)');

for (const propertyPath of traverseProperty(__a, 'uses')) {
const valuePath = propertyPath.get('value');
const {value} = valuePath.node;

if (value === 'EndBug/add-and-commit@v9')
continue;

if (value === 'EndBug/add-and-commit@v7')
push(valuePath);
}
},
});

23 changes: 23 additions & 0 deletions packages/plugin-github/lib/set-add-and-commit/index.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict';

const {createTest} = require('@putout/test');
const setAddAndCommit = require('.');

const test = createTest(__dirname, {
'github/set-add-and-commit': setAddAndCommit,
});

test('plugin-github: set-set-add-and-commit: report', (t) => {
t.report('set-add-and-commit', 'Latest version of EndBug/add-and-commit is missing');
t.end();
});

test('plugin-github: set-set-add-and-commit: transform', (t) => {
t.transform('set-add-and-commit');
t.end();
});

test('plugin-github: set-set-add-and-commit: no report: latest', (t) => {
t.noReport('latest');
t.end();
});
12 changes: 12 additions & 0 deletions packages/plugin-github/test/fixture/set-add-and-commit-fix.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
__putout_processor_json({
"jobs": {
"build": {
"runs-on": "ubuntu-latest",
"steps": [
{
"uses": 'EndBug/add-and-commit@v9'
},
]
}
}
});
12 changes: 12 additions & 0 deletions packages/plugin-github/test/fixture/set-add-and-commit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
__putout_processor_json({
"jobs": {
"build": {
"runs-on": "ubuntu-latest",
"steps": [
{
"uses": "EndBug/add-and-commit@v7"
},
]
}
}
});
4 changes: 4 additions & 0 deletions packages/plugin-github/test/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@ test('plugin-github: transform: set-setup-node-version', (t) => {
t.end();
});

test('plugin-github: transform: set-add-and-commit', (t) => {
t.transform('set-add-and-commit');
t.end();
});

0 comments on commit be25fd2

Please sign in to comment.