X Tutup
Skip to content

Commit 2aa77fb

Browse files
committed
Add Context.SetAuthToken
1 parent de85294 commit 2aa77fb

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

context/blank_context.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ func (c *blankContext) AuthToken() (string, error) {
2626
return c.authToken, nil
2727
}
2828

29+
func (c *blankContext) SetAuthToken(t string) {
30+
c.authToken = t
31+
}
32+
2933
func (c *blankContext) AuthLogin() (string, error) {
3034
return c.authLogin, nil
3135
}

context/context.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
// Context represents the interface for querying information about the current environment
1111
type Context interface {
1212
AuthToken() (string, error)
13+
SetAuthToken(string)
1314
AuthLogin() (string, error)
1415
Branch() (string, error)
1516
SetBranch(string)
@@ -36,10 +37,11 @@ func InitDefaultContext() Context {
3637

3738
// A Context implementation that queries the filesystem
3839
type fsContext struct {
39-
config *configEntry
40-
remotes Remotes
41-
branch string
42-
baseRepo *GitHubRepository
40+
config *configEntry
41+
remotes Remotes
42+
branch string
43+
baseRepo *GitHubRepository
44+
authToken string
4345
}
4446

4547
func (c *fsContext) configFile() string {
@@ -54,18 +56,27 @@ func (c *fsContext) getConfig() (*configEntry, error) {
5456
return nil, err
5557
}
5658
c.config = entry
59+
c.authToken = ""
5760
}
5861
return c.config, nil
5962
}
6063

6164
func (c *fsContext) AuthToken() (string, error) {
65+
if c.authToken != "" {
66+
return c.authToken, nil
67+
}
68+
6269
config, err := c.getConfig()
6370
if err != nil {
6471
return "", err
6572
}
6673
return config.Token, nil
6774
}
6875

76+
func (c *fsContext) SetAuthToken(t string) {
77+
c.authToken = t
78+
}
79+
6980
func (c *fsContext) AuthLogin() (string, error) {
7081
config, err := c.getConfig()
7182
if err != nil {

0 commit comments

Comments
 (0)
X Tutup