Skip to content

Commit 6818aaf

Browse files
authored
Handle "No gitconfig to be found" exaction (#8)
1 parent d0e8e82 commit 6818aaf

File tree

1 file changed

+34
-23
lines changed

1 file changed

+34
-23
lines changed

create-pull-request.js

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,31 @@
11
#!/usr/bin/env node
22
const gitRemoteOriginUrl = require("git-remote-origin-url");
3-
const branchName = require('current-git-branch');
3+
const branchName = require("current-git-branch");
44
const open = require("open");
5-
const chalk = require('chalk');
6-
const warning = chalk.keyword('orange');
5+
const chalk = require("chalk");
6+
const warning = chalk.keyword("orange");
7+
const error = chalk.keyword("red");
78

89
(async () => {
9-
const remoteOriginUrl = await gitRemoteOriginUrl();
10+
try {
11+
const remoteOriginUrl = await gitRemoteOriginUrl();
1012

11-
const repoUrl = remoteOriginUrl
12-
.replace(":", "/")
13-
.replace(/^git@/, "https://")
14-
.replace(/\.git$/, "");
13+
const repoUrl = remoteOriginUrl
14+
.replace(":", "/")
15+
.replace(/^git@/, "https://")
16+
.replace(/\.git$/, "");
1517

16-
const pullRequestURL = getPullRequestUrl(repoUrl);
17-
if (!pullRequestURL) {
18-
return;
19-
}
18+
const pullRequestURL = getPullRequestUrl(repoUrl);
19+
if (!pullRequestURL) {
20+
return;
21+
}
2022

21-
await open(pullRequestURL, { app: getBrowser() });
23+
await open(pullRequestURL, { app: getBrowser() });
24+
} catch (err) {
25+
console.log(
26+
error(err.message.charAt(0).toUpperCase() + err.message.slice(1))
27+
);
28+
}
2229
})();
2330

2431
/**
@@ -30,7 +37,7 @@ function getPullRequestUrl(repoUrl) {
3037
if (url.host === "github.com") {
3138
return `${url}/pull/new/${branchName()}`;
3239
} else if (url.host === "bitbucket.org") {
33-
return `${url}/pull-requests/new?source=${branchName()}&t=1`
40+
return `${url}/pull-requests/new?source=${branchName()}&t=1`;
3441
}
3542

3643
return "";
@@ -41,20 +48,24 @@ function getPullRequestUrl(repoUrl) {
4148
*/
4249
function getBrowser() {
4350
const browsers = {
44-
"chrome": "chrome",
45-
"firefox": "firefox",
46-
"edge": "msedge",
47-
"safari": "safari",
48-
"ie": "iexplore",
49-
"opera": "opera"
50-
}
51+
chrome: "chrome",
52+
firefox: "firefox",
53+
edge: "msedge",
54+
safari: "safari",
55+
ie: "iexplore",
56+
opera: "opera",
57+
};
5158

5259
const [, , userInput] = process.argv;
5360
const browser = browsers[userInput];
5461

5562
if (userInput && !browser) {
56-
console.log(warning(`Browser "${userInput}" was not found, we will use your default browser.`));
63+
console.log(
64+
warning(
65+
`Browser "${userInput}" was not found, we will use your default browser.`
66+
)
67+
);
5768
}
5869

5970
return browser || "";
60-
}
71+
}

0 commit comments

Comments
 (0)