Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(travis-cli): passdown argv to lint command #891

Merged
merged 1 commit into from Feb 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions @commitlint/travis-cli/src/cli.js
Expand Up @@ -42,13 +42,15 @@ async function main() {
// Restore stashed changes if any
await pop();

const args = process.argv.slice(2);

// Lint all commits in TRAVIS_COMMIT_RANGE if available
if (IS_PR && RANGE) {
const [start, end] = RANGE.split('.').filter(Boolean);
await lint(['--from', start, '--to', end]);
await lint(['--from', start, '--to', end, ...args]);
} else {
const input = await log(COMMIT);
await lint([], {input});
await lint(args, {input});
}
}

Expand Down
37 changes: 35 additions & 2 deletions @commitlint/travis-cli/src/cli.test.js
Expand Up @@ -18,9 +18,9 @@ const validBaseEnv = {
TRAVIS_PULL_REQUEST_SLUG: 'TRAVIS_PULL_REQUEST_SLUG'
};

const cli = async (config = {}) => {
const cli = async (config = {}, args = []) => {
try {
return await execa(bin, [], config);
return await execa(bin, args, config);
} catch (err) {
throw new Error([err.stdout, err.stderr].join('\n'));
}
Expand Down Expand Up @@ -98,6 +98,39 @@ test('should call git with expected args on pull_request', async () => {
]);
});

test('should call git with extra expected args on pull_request', async () => {
const cwd = await git.clone(
'https://github.com/conventional-changelog/commitlint.git',
['--depth=10'],
__dirname,
TRAVIS_COMMITLINT_GIT_BIN
);

const result = await cli(
{
cwd,
env: {...validBaseEnv, TRAVIS_EVENT_TYPE: 'pull_request'}
},
['--config', './config/commitlint.config.js']
);
const invocations = await getInvocations(result.stdout);
expect(invocations.length).toBe(3);

const [stash, branches, commilint] = invocations;

expect(stash).toEqual(['git', 'stash', '-k', '-u', '--quiet']);
expect(branches).toEqual(['git', 'stash', 'pop', '--quiet']);
expect(commilint).toEqual([
'commitlint',
'--from',
'TRAVIS_COMMIT_A',
'--to',
'TRAVIS_COMMIT_B',
'--config',
'./config/commitlint.config.js'
]);
});

function getInvocations(stdout) {
const matches = stdout.match(/[^[\]]+/g);
const raw = Array.isArray(matches) ? matches : [];
Expand Down