-
Notifications
You must be signed in to change notification settings - Fork 2
/
dummy.go
77 lines (64 loc) · 2.21 KB
/
dummy.go
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
76
77
package githubapptoken
import (
"context"
"encoding/base64"
"github.com/shogo82148/actions-github-app-token/provider/github-app-token/github"
"github.com/shogo82148/goat/jwt"
)
type githubClientDummy struct{}
func (c *githubClientDummy) GetApp(ctx context.Context) (*github.GetAppResponse, error) {
return &github.GetAppResponse{
HTMLURL: "https://github.com/shogo82148/actions-github-app-token",
}, nil
}
func (c *githubClientDummy) GetRepo(ctx context.Context, token, owner, repo string) (*github.GetRepoResponse, error) {
return &github.GetRepoResponse{
ID: 398574950,
NodeID: "R_kgDOF8HFZg",
}, nil
}
func (c *githubClientDummy) GetReposInfo(ctx context.Context, token, nodeID string) (*github.GetReposInfoResponse, error) {
return &github.GetReposInfoResponse{}, nil
}
func (c *githubClientDummy) GetReposContent(ctx context.Context, token, owner, repo, path string) (*github.GetReposContentResponse, error) {
content := `
repositories:
- R_kgDOF8HFZg
`
return &github.GetReposContentResponse{
Type: "file",
Encoding: "base64",
Content: base64.StdEncoding.EncodeToString([]byte(content)),
}, nil
}
func (c *githubClientDummy) GetReposInstallation(ctx context.Context, owner, repo string) (*github.GetReposInstallationResponse, error) {
return &github.GetReposInstallationResponse{
ID: 123456,
}, nil
}
func (c *githubClientDummy) CreateAppAccessToken(ctx context.Context, installationID uint64, permissions *github.CreateAppAccessTokenRequest) (*github.CreateAppAccessTokenResponse, error) {
return &github.CreateAppAccessTokenResponse{
Token: "ghs_dummyGitHubToken",
}, nil
}
func (c *githubClientDummy) ValidateAPIURL(url string) error {
return nil
}
func (c *githubClientDummy) ParseIDToken(ctx context.Context, idToken string) (*github.ActionsIDToken, error) {
return &github.ActionsIDToken{
Claims: &jwt.Claims{
Audience: []string{"https://github-app.shogo82148.com/1234567890"},
},
Repository: "shogo82148/actions-github-app-token",
RepositoryID: "398574950",
}, nil
}
func (c *githubClientDummy) RevokeAppAccessToken(ctx context.Context, token string) error {
return nil
}
func NewDummyHandler() *Handler {
return &Handler{
github: &githubClientDummy{},
appID: 1234567890,
}
}