Skip to content

Commit

Permalink
[New] Add transform func to middle to set args.repo before parse
Browse files Browse the repository at this point in the history
  • Loading branch information
Green-Ranger11 committed Dec 1, 2021
1 parent 420f4bc commit 8d11f17
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions bin/can-merge
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ const {
NODE_ENV,
} = process.env;

const setRepository = (argv) => {
const args = argv;
args.repo = getRepo(argv.remote);
return argv;
};

const args = Yargs
.usage('Usage: can-merge -p <pr> [-r <repo>]')
.help()
Expand Down Expand Up @@ -60,21 +66,20 @@ const args = Yargs
},
})
.check((argv) => {
if (!argv.repo && !getRepo()) {
throw new Error('Could not infer any git repository from directory. \
\nAre you sure you are in a git repository? Otherwise, please specify --repo');
}
if (argv.remote && !getRepo(argv.remote)) {
throw new Error(`Could not find remote git repo with remote name ${argv.remote}`);
if (!getRepo(argv.remote)) {
if (!argv.repo) {
throw new Error('Could not infer any git repository from directory. \
\nAre you sure you are in a git repository? Otherwise, please specify --repo');
}
if (argv.remote) {
throw new Error(`Could not find remote git repo with remote name ${argv.remote}`);
}
}
return true;
})
.middleware(setRepository)
.parse();

if (args.remote) {
args.repo = getRepo(args.remote);
}

const token = args.token || GITHUB_TOKEN || GH_TOKEN;

runQuery(args.pr, args.repo, args.sha, token).then((response) => {
Expand Down

0 comments on commit 8d11f17

Please sign in to comment.