From 0a019ff8369650acb0fdc73b7dd370d0f58f6687 Mon Sep 17 00:00:00 2001 From: Chris Cummer Date: Tue, 31 Jul 2018 13:58:08 -0700 Subject: [PATCH] Clean up the GitHub module's API credentials loading --- github/github_repo.go | 24 ++++++++++++++++++++---- weatherservices/weather/widget.go | 2 -- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/github/github_repo.go b/github/github_repo.go index 80640f5a..7bf210f7 100644 --- a/github/github_repo.go +++ b/github/github_repo.go @@ -6,6 +6,7 @@ import ( "os" ghb "github.com/google/go-github/github" + "github.com/senorprogrammer/wtf/wtf" "golang.org/x/oauth2" ) @@ -22,14 +23,12 @@ type GithubRepo struct { func NewGithubRepo(name, owner string) *GithubRepo { repo := GithubRepo{ - apiKey: os.Getenv("WTF_GITHUB_TOKEN"), - baseURL: os.Getenv("WTF_GITHUB_BASE_URL"), - uploadURL: os.Getenv("WTF_GITHUB_UPLOAD_URL"), - Name: name, Owner: owner, } + repo.loadAPICredentials() + return &repo } @@ -91,6 +90,23 @@ func (repo *GithubRepo) githubClient() (*ghb.Client, error) { return ghb.NewClient(oauthClient), nil } +func (repo *GithubRepo) loadAPICredentials() { + repo.apiKey = wtf.Config.UString( + "wtf.mods.github.apiKey", + os.Getenv("WTF_GITHUB_TOKEN"), + ) + + repo.baseURL = wtf.Config.UString( + "wtf.mods.github.baseURL", + os.Getenv("WTF_GITHUB_BASE_URL"), + ) + + repo.uploadURL = wtf.Config.UString( + "wtf.mods.github.uploadURL", + os.Getenv("WTF_GITHUB_UPLOAD_URL"), + ) +} + // myPullRequests returns a list of pull requests created by username on this repo func (repo *GithubRepo) myPullRequests(username string) []*ghb.PullRequest { prs := []*ghb.PullRequest{} diff --git a/weatherservices/weather/widget.go b/weatherservices/weather/widget.go index fcfb3904..2d7448e3 100644 --- a/weatherservices/weather/widget.go +++ b/weatherservices/weather/widget.go @@ -1,13 +1,11 @@ package weather import ( - //"fmt" "os" owm "github.com/briandowns/openweathermap" "github.com/gdamore/tcell" "github.com/rivo/tview" - //"github.com/senorprogrammer/wtf/logger" "github.com/senorprogrammer/wtf/wtf" )