Documentation
¶
Overview ¶
Package team synchronises email addresses with GitHub teams.
Discovery ¶
You must provide a discovery adapter in order to use this adapter. This is because converting email addresses to GitHub usernames isn't straightforward. At OVO, we enforce SAML for our GitHub users, and have provided a SAML -> GitHub Username discovery adapter, but you may need to write your own.
Requirements ¶
In order to synchronise with GitHub, you'll need to create a [Personal Access Token] with the following permissions:
- admin:org
- write:org
- read:org
Examples ¶
Index ¶
Examples ¶
Constants ¶
const DiscoveryMechanism gosync.ConfigKey = "discovery_mechanism"
DiscoveryMechanism for converting emails into GitHub users and vice versa. Supported values are:
const GitHubOrg gosync.ConfigKey = "github_org"
GitHubOrg is the name of your GitHub organisation.
For example:
https://github.com/ovotech/go-sync
`ovotech` is the name of our organisation.
const GitHubToken gosync.ConfigKey = "github_token"
GitHubToken is the token used to authenticate with GitHub. See package docs for more information on how to obtain this token.
const TeamSlug gosync.ConfigKey = "team_slug"
TeamSlug is the name of your team slug within your organisation.
For example:
https://github.com/orgs/ovotech/teams/foobar
`foobar` is the name of our team slug.
Variables ¶
This section is empty.
Functions ¶
func Init ¶ added in v0.7.0
Init a new GitHub Team gosync.Adapter.
Required config:
Example ¶
package main
import (
"context"
"log"
gosync "github.com/ovotech/go-sync"
"github.com/ovotech/go-sync/adapters/github/team"
)
func main() {
ctx := context.Background()
adapter, err := team.Init(ctx, map[gosync.ConfigKey]string{
team.GitHubToken: "my-github-token",
team.GitHubOrg: "my-org",
team.TeamSlug: "my-team-slug",
team.DiscoveryMechanism: "saml",
})
if err != nil {
log.Fatal(err)
}
gosync.New(adapter)
}
Types ¶
type Team ¶
func New ¶
func New( client *github.Client, discovery discovery.GitHubDiscovery, org string, slug string, optsFn ...func(*Team), ) *Team
New GitHub Team gosync.Adapter.
Recommended reading for parameters:
- org: team.GitHubOrg
- slug: team.TeamSlug
Example ¶
package main
import (
"context"
"github.com/google/go-github/v47/github"
"github.com/shurcooL/githubv4"
"golang.org/x/oauth2"
gosync "github.com/ovotech/go-sync"
"github.com/ovotech/go-sync/adapters/github/discovery/saml"
"github.com/ovotech/go-sync/adapters/github/team"
)
func main() {
ctx := context.Background()
// Authenticated client to communicate with GitHub APIs.
oauthClient := oauth2.NewClient(ctx, oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: "my-github-token"},
))
var (
// GitHub V3 API is used by GH Teams adapter.
gitHubV3Client = github.NewClient(oauthClient)
// GitHub V4 API is used by SAML discovery.
gitHubV4Client = githubv4.NewClient(oauthClient)
// GitHub Discovery service uses SAML to convert emails into GH users.
samlClient = saml.New(gitHubV4Client, "my-org")
)
adapter := team.New(gitHubV3Client, samlClient, "my-org", "my-team-slug")
gosync.New(adapter)
}