Skip to content

Commit

Permalink
feat: check for env vars GITHUB_TOKEN and GH_TOKEN
Browse files Browse the repository at this point in the history
user better name for the config folder
  • Loading branch information
robertoentringer committed Jul 13, 2020
1 parent 21199b7 commit 952404b
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions hubnow.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ const { homedir } = require('os')
const path = require('path')
const fs = require('fs')

const home = path.join(homedir(), '.hubnow')
const auth = path.join(home, 'auth.json')
const configFolder = path.join(homedir(), '.hubnow')
const auth = path.join(configFolder, 'auth.json')

const getRepos = async (opts) => {
const query = `query repo {
Expand Down Expand Up @@ -104,15 +104,17 @@ const inputToken = async () => {
}

const saveToken = (token) => {
if (!fs.existsSync(home)) fs.mkdirSync(home)
if (!fs.existsSync(configFolder)) fs.mkdirSync(configFolder)
const helptext = "This is your github credentials file. DON'T SHARE! More: https://git.io/fjrf3"
const filecontent = JSON.stringify({ helptext, token }, null, 2)
fs.writeFileSync(auth, filecontent)
}

const getToken = async () => {
try {
return JSON.parse(fs.readFileSync(auth)).token
return (
process.env.GITHUB_TOKEN || process.env.GH_TOKEN || JSON.parse(fs.readFileSync(auth)).token
)
} catch (err) {
return await inputToken()
}
Expand Down

0 comments on commit 952404b

Please sign in to comment.