Exemple #1
0
func GithubServiceFactory(facts *hubbub.Facts) (*hubbub.Service, error) {
	if !facts.IsAvailable("github.access_token") {
		return nil, errors.New("no github access token available")
	}

	ts := oauth2.StaticTokenSource(&oauth2.Token{AccessToken: facts.GetString("github.access_token")})
	oc := oauth2.NewClient(oauth2.NoContext, ts)
	gs := GithubService{github.NewClient(oc), nil, nil, facts.GetString("repo.owner"), facts.GetString("repo.name")}

	svc := hubbub.Service(&gs)
	return &svc, nil
}
Exemple #2
0
// Construct an instance of TravisService configured for the given facts
//
// Attempts to configure for either travis.org, or--failing that--for travis
// pro / travis.com.
func TravisServiceFactory(facts *hubbub.Facts) (*hubbub.Service, error) {

	ts := TravisService{}
	owner := facts.GetString("repo.owner")
	name := facts.GetString("repo.name")

	// try travis.com (travis pro)
	if facts.IsAvailable(PRO) && configureClient(&ts, travis.NewProClient(hubbub.String(facts.GetString(PRO))), owner, name) {
		svc := hubbub.Service(&ts)
		return &svc, nil
	}

	// try travis.org
	if facts.IsAvailable(ORG) && configureClient(&ts, travis.NewClient(hubbub.String(facts.GetString(ORG))), owner, name) {
		svc := hubbub.Service(&ts)
		return &svc, nil
	}

	return nil, errors.New("Failed to configure Travis client")
}