Skip to content

Commit 8cedeb4

Browse files
RichardLittgr2m
authored andcommitted
feat: get GitHub username from global .gitconfig
And not from npm
1 parent 174dfbc commit 8cedeb4

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"dependencies": {
2121
"base32": "0.0.6",
2222
"bluebird": "^3.4.6",
23+
"git-config-path": "^1.0.1",
2324
"github-url-from-git": "^1.4.0",
2425
"ini": "^1.3.4",
2526
"inquirer": "^1.2.2",
@@ -29,6 +30,7 @@
2930
"npm": "^4.0.3",
3031
"npm-registry-client": "^7.3.0",
3132
"npmlog": "^4.0.0",
33+
"parse-git-config": "^1.1.1",
3234
"parse-github-repo-url": "^1.0.0",
3335
"request": "^2.58.0",
3436
"request-promise": "^4.1.1",

src/lib/github.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ const npm = require('npm')
77
const request = require('request-promise').defaults({resolveWithFullResponse: true})
88
const validator = require('validator')
99
const log = require('npmlog')
10-
10+
const gitConfigPath = require('git-config-path')('global')
11+
const parse = require('parse-git-config')
1112
const passwordStorage = require('./password-storage')('github')
1213

1314
async function ask2FA () {
@@ -77,11 +78,13 @@ module.exports = async function (pkg, info) {
7778
return
7879
}
7980

81+
const githubUserFromGitConfig = (parse.sync({path: gitConfigPath}).github) ? parse.sync({path: gitConfigPath}).github.user : null
82+
8083
const answers = await inquirer.prompt([{
8184
type: 'input',
8285
name: 'username',
8386
message: 'What is your GitHub username?',
84-
default: info.options['gh-username'] || npm.config.get('username'),
87+
default: info.options['gh-username'] || githubUserFromGitConfig || npm.config.get('username'),
8588
validate: _.ary(_.bind(validator.isLength, validator, _, 1), 1)
8689
}, {
8790
type: 'password',

0 commit comments

Comments
 (0)