Module: TokenResolver

Defined in:
lib/cli/token_resolver.rb

Class Method Summary collapse

Class Method Details

.resolve(options) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
# File 'lib/cli/token_resolver.rb', line 2

def self.resolve(options)
    return options[:token] if options[:token]
    return ENV["GITHUB_TOKEN"] if ENV["GITHUB_TOKEN"]

    gh_path = `which gh 2>/dev/null`.strip
    if !gh_path.empty? && system("gh", "auth", "status", [:out, :err] => File::NULL)
        token = `gh auth token 2>/dev/null`.strip
        return token unless token.empty?
    end

    nil
end