Skip to content

Commit c49a57c

Browse files
authoredFeb 9, 2020
feat: passdown argv to lint command (#891)
passdown travis-cli argument to @commitlint/cli
1 parent 01c451c commit c49a57c

File tree

2 files changed

+39
-4
lines changed

2 files changed

+39
-4
lines changed
 

‎@commitlint/travis-cli/src/cli.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,15 @@ async function main() {
4242
// Restore stashed changes if any
4343
await pop();
4444

45+
const args = process.argv.slice(2);
46+
4547
// Lint all commits in TRAVIS_COMMIT_RANGE if available
4648
if (IS_PR && RANGE) {
4749
const [start, end] = RANGE.split('.').filter(Boolean);
48-
await lint(['--from', start, '--to', end]);
50+
await lint(['--from', start, '--to', end, ...args]);
4951
} else {
5052
const input = await log(COMMIT);
51-
await lint([], {input});
53+
await lint(args, {input});
5254
}
5355
}
5456

‎@commitlint/travis-cli/src/cli.test.js

+35-2
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ const validBaseEnv = {
1818
TRAVIS_PULL_REQUEST_SLUG: 'TRAVIS_PULL_REQUEST_SLUG'
1919
};
2020

21-
const cli = async (config = {}) => {
21+
const cli = async (config = {}, args = []) => {
2222
try {
23-
return await execa(bin, [], config);
23+
return await execa(bin, args, config);
2424
} catch (err) {
2525
throw new Error([err.stdout, err.stderr].join('\n'));
2626
}
@@ -98,6 +98,39 @@ test('should call git with expected args on pull_request', async () => {
9898
]);
9999
});
100100

101+
test('should call git with extra expected args on pull_request', async () => {
102+
const cwd = await git.clone(
103+
'https://github.com/conventional-changelog/commitlint.git',
104+
['--depth=10'],
105+
__dirname,
106+
TRAVIS_COMMITLINT_GIT_BIN
107+
);
108+
109+
const result = await cli(
110+
{
111+
cwd,
112+
env: {...validBaseEnv, TRAVIS_EVENT_TYPE: 'pull_request'}
113+
},
114+
['--config', './config/commitlint.config.js']
115+
);
116+
const invocations = await getInvocations(result.stdout);
117+
expect(invocations.length).toBe(3);
118+
119+
const [stash, branches, commilint] = invocations;
120+
121+
expect(stash).toEqual(['git', 'stash', '-k', '-u', '--quiet']);
122+
expect(branches).toEqual(['git', 'stash', 'pop', '--quiet']);
123+
expect(commilint).toEqual([
124+
'commitlint',
125+
'--from',
126+
'TRAVIS_COMMIT_A',
127+
'--to',
128+
'TRAVIS_COMMIT_B',
129+
'--config',
130+
'./config/commitlint.config.js'
131+
]);
132+
});
133+
101134
function getInvocations(stdout) {
102135
const matches = stdout.match(/[^[\]]+/g);
103136
const raw = Array.isArray(matches) ? matches : [];

0 commit comments

Comments
 (0)
Please sign in to comment.