forked from openshift-pipelines/pipelines-as-code
-
Notifications
You must be signed in to change notification settings - Fork 0
/
github.go
52 lines (47 loc) · 1.51 KB
/
github.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
package bootstrap
import (
"encoding/json"
"fmt"
"github.com/google/go-github/scrape"
"github.com/google/go-github/v42/github"
)
// generateManifest generate manifest from the given options
func generateManifest(opts *bootstrapOpts) ([]byte, error) {
sc := scrape.AppManifest{
Name: github.String(opts.GithubApplicationName),
URL: github.String(opts.GithubApplicationURL),
HookAttributes: map[string]string{"url": opts.RouteName},
RedirectURL: github.String(fmt.Sprintf("http://localhost:%d", opts.webserverPort)),
Description: github.String("Pipeline as Code Application"),
Public: github.Bool(true),
DefaultEvents: []string{
"commit_comment",
"issue_comment",
"pull_request",
"pull_request_review",
"pull_request_review_comment",
"push",
},
DefaultPermissions: &github.InstallationPermissions{
Checks: github.String("write"),
Contents: github.String("write"),
Issues: github.String("write"),
Members: github.String("read"),
Metadata: github.String("read"),
OrganizationPlan: github.String("read"),
PullRequests: github.String("write"),
},
}
return json.Marshal(sc)
}
// getGHClient get github client
func getGHClient(opts *bootstrapOpts) (*github.Client, error) {
if opts.GithubAPIURL == defaultPublicGithub {
return github.NewClient(nil), nil
}
gprovider, err := github.NewEnterpriseClient(opts.GithubAPIURL, "", nil)
if err != nil {
return nil, err
}
return gprovider, nil
}