Repository navigation
Expand file tree
/
Copy pathgithub.go
More file actions
75 lines (69 loc) · 2.08 KB
/
Copy pathgithub.go
File metadata and controls
75 lines (69 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package github
import (
"context"
"github.com/ovh/cds/engine/cache"
"github.com/ovh/cds/sdk"
)
// githubClient is a github.com wrapper for CDS vcs. interface
type githubClient struct {
GitHubURL string
GitHubAPIURL string
ClientID string
OAuthToken string
DisableStatus bool
DisableStatusDetail bool
Cache cache.Store
apiURL string
uiURL string
proxyURL string
username string
token string
}
//GithubConsumer implements vcs.Server and it's used to instantiate a githubClient
type githubConsumer struct {
ClientID string `json:"client-id"`
ClientSecret string `json:"-"`
Cache cache.Store
GitHubURL string
GitHubAPIURL string
uiURL string
apiURL string
proxyURL string
disableStatus bool
disableStatusDetail bool
username string
token string
}
//New creates a new GithubConsumer
func New(ClientID, ClientSecret, githubURL, githubAPIURL, apiURL, uiURL, proxyURL, username, token string, store cache.Store, disableStatus, disableStatusDetail bool) sdk.VCSServer {
//Github const
const (
publicURL = "https://github.com"
publicAPIURL = "https://api.github.com"
)
// if the githubURL is passed as an empty string default it to public GitHub
if githubURL == "" {
githubURL = publicURL
}
// if the githubAPIURL is passed as an empty string default it to public GitHub
if githubAPIURL == "" {
githubAPIURL = publicAPIURL
}
return &githubConsumer{
ClientID: ClientID,
ClientSecret: ClientSecret,
GitHubURL: githubURL,
GitHubAPIURL: githubAPIURL,
Cache: store,
apiURL: apiURL,
uiURL: uiURL,
proxyURL: proxyURL,
disableStatus: disableStatus,
disableStatusDetail: disableStatusDetail,
username: username,
token: token,
}
}
func (c *githubClient) GetAccessToken(_ context.Context) string {
return c.OAuthToken
}