Skip to content

Commit

Permalink
Revert "Revert "Allow running cml pr create without files (#1263)" (#…
Browse files Browse the repository at this point in the history
…1270)"

This reverts commit 746ed2f.
  • Loading branch information
dacbd committed Dec 6, 2022
1 parent 47b21a8 commit 49dd4a4
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 13 deletions.
1 change: 0 additions & 1 deletion bin/cml/pr.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,4 @@ exports.builder = (yargs) =>
)
)
.option('options', { default: options, hidden: true })
.check(({ globpath }) => globpath)
.strict();
2 changes: 1 addition & 1 deletion bin/cml/pr/create.e2e.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('CML e2e', () => {
Manage pull requests
Commands:
cml.js pr create <glob path...> Create a pull request with the specified
cml.js pr create [glob path...] Create a pull request with the specified
files
https://cml.dev/doc/ref/pr
Expand Down
2 changes: 1 addition & 1 deletion bin/cml/pr/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const {
const DESCRIPTION = 'Create a pull request with the specified files';
const DOCSURL = 'https://cml.dev/doc/ref/pr';

exports.command = 'create <glob path...>';
exports.command = 'create [glob path...]';
exports.description = `${DESCRIPTION}\n${DOCSURL}`;

exports.handler = async (opts) => {
Expand Down
20 changes: 10 additions & 10 deletions src/cml.js
Original file line number Diff line number Diff line change
Expand Up @@ -543,18 +543,14 @@ class CML {
};

const { files } = await git.status();
if (!files.length) {
if (!files.length && globs.length) {
winston.warn('No files changed. Nothing to do.');
return;
}

const paths = (await globby(globs)).filter((path) =>
files.map((file) => file.path).includes(path)
);
if (!paths.length) {
winston.warn('Input files are not affected. Nothing to do.');
return;
}

const sha = await this.triggerSha();
const shaShort = sha.substr(0, 8);
Expand All @@ -581,12 +577,16 @@ class CML {
await exec(`git fetch ${remote} ${sha}`);
await exec(`git checkout -B ${target} ${sha}`);
await exec(`git checkout -b ${source}`);
await exec(`git add ${paths.join(' ')}`);
let commitMessage = message || `CML PR for ${shaShort}`;
if (skipCi || (!message && !(merge || rebase || squash))) {
commitMessage += ' [skip ci]';

if (paths.length) {
await exec(`git add ${paths.join(' ')}`);
let commitMessage = message || `CML PR for ${shaShort}`;
if (skipCi || (!message && !(merge || rebase || squash))) {
commitMessage += ' [skip ci]';
}
await exec(`git commit -m "${commitMessage}"`);
}
await exec(`git commit -m "${commitMessage}"`);

await exec(`git push --set-upstream ${remote} ${source}`);
}

Expand Down

2 comments on commit 49dd4a4

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test Comment

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test Comment

Please sign in to comment.