-
Notifications
You must be signed in to change notification settings - Fork 34
/
example_organization_test.go
40 lines (33 loc) · 1.08 KB
/
example_organization_test.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
package github_test
import (
"context"
"fmt"
"log"
"github.com/fluxcd/go-git-providers/github"
"github.com/fluxcd/go-git-providers/gitprovider"
gogithub "github.com/google/go-github/v66/github"
)
// checkErr is used for examples in this repository.
func checkErr(err error) {
if err != nil {
log.Fatal(err)
}
}
func ExampleOrganizationsClient_Get() {
// Create a new client
ctx := context.Background()
c, err := github.NewClient()
checkErr(err)
// Get public information about the fluxcd organization
org, err := c.Organizations().Get(ctx, gitprovider.OrganizationRef{
Domain: github.DefaultDomain,
Organization: "fluxcd",
})
checkErr(err)
// Use .Get() to aquire a high-level gitprovider.OrganizationInfo struct
orgInfo := org.Get()
// Cast the internal object to a *gogithub.Organization to access custom data
internalOrg := org.APIObject().(*gogithub.Organization)
fmt.Printf("Name: %s. Description: %s.", *orgInfo.Name, internalOrg.GetDescription())
// Output: Name: Flux project. Description: Open and extensible continuous delivery solution for Kubernetes.
}