当前位置: 首页>>代码示例>>Golang>>正文


Golang github.NewClient函数代码示例

本文整理汇总了Golang中github.com/google/go-github/github.NewClient函数的典型用法代码示例。如果您正苦于以下问题:Golang NewClient函数的具体用法?Golang NewClient怎么用?Golang NewClient使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了NewClient函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: main

func main() {
	flag.Parse()

	token := os.Getenv("GITHUB_AUTH_TOKEN")
	if token == "" {
		println("!!! No OAuth token.  Some tests won't run. !!!\n")
		client = github.NewClient(nil)
	} else {
		t := &oauth.Transport{
			Token: &oauth.Token{AccessToken: token},
		}
		client = github.NewClient(t.Client())
		auth = true
	}

	for _, tt := range []struct {
		url string
		typ interface{}
	}{
		//{"rate_limit", &github.RateLimits{}},
		{"users/octocat", &github.User{}},
		{"user", &github.User{}},
		{"users/willnorris/keys", &[]github.Key{}},
		{"orgs/google-test", &github.Organization{}},
		{"repos/google/go-github", &github.Repository{}},
		{"/gists/9257657", &github.Gist{}},
	} {
		err := testType(tt.url, tt.typ)
		if err != nil {
			fmt.Printf("error: %v\n", err)
		}
	}
}
开发者ID:rjeczalik,项目名称:go-github,代码行数:33,代码来源:fields.go

示例2: createGithubClient

func (grp githubRegistryProvider) createGithubClient(credentialName string) (*http.Client, *github.Client, error) {
	if credentialName == "" {
		return http.DefaultClient, github.NewClient(nil), nil
	}
	c, err := grp.cp.GetCredential(credentialName)

	if err != nil {
		log.Printf("Failed to fetch credential %s: %v", credentialName, err)
		log.Print("Trying to use unauthenticated client")
		return http.DefaultClient, github.NewClient(nil), nil
	}

	if c != nil {
		if c.APIToken != "" {
			ts := oauth2.StaticTokenSource(
				&oauth2.Token{AccessToken: string(c.APIToken)},
			)
			tc := oauth2.NewClient(oauth2.NoContext, ts)
			return tc, github.NewClient(tc), nil
		}
		if c.BasicAuth.Username != "" && c.BasicAuth.Password != "" {
			tp := github.BasicAuthTransport{
				Username: c.BasicAuth.Username,
				Password: c.BasicAuth.Password,
			}
			return tp.Client(), github.NewClient(tp.Client()), nil
		}

	}
	return nil, nil, fmt.Errorf("No suitable credential found for %s", credentialName)

}
开发者ID:danielckv,项目名称:deployment-manager,代码行数:32,代码来源:registryprovider.go

示例3: Before

// Before gets called before any action on every execution.
func Before() cli.BeforeFunc {
	return func(c *cli.Context) error {
		logrus.SetOutput(os.Stdout)
		logrus.SetLevel(logrus.DebugLevel)

		if c.BoolT("update") {
			Update()
		}

		if config.Token != "" {
			config.Client = github.NewClient(
				oauth2.NewClient(
					oauth2.NoContext,
					oauth2.StaticTokenSource(
						&oauth2.Token{
							AccessToken: config.Token,
						},
					),
				),
			)
		} else {
			config.Client = github.NewClient(nil)
		}

		return nil
	}
}
开发者ID:webhippie,项目名称:mygithub,代码行数:28,代码来源:before.go

示例4: TestAsciiCatRespRecorder

// TestAsciiCatRespRecorder uses net/http/httptest ResponseRecorder
// (https://godoc.org/net/http/httptest#ResponseRecorder) to test the AsciiCat
// handler directly.
//
// ResponseRecorder is useful for direct testing of handlers,
// but doesn't provide a complete solution when the router itself handles complex logic.
// See TestGetIssuesTestSrv in get_issues_test.go for an example of testing complex router logic
func TestAsciiCatRespRecorder(t *testing.T) {
	// create a ResponseRecorder, which implements http.ResponseWriter. it will be passed into the handler
	w := httptest.NewRecorder()
	// create a fake request to be passed into the handler
	r, err := http.NewRequest("GET", "/ascii_cat", nil)
	if err != nil {
		t.Fatalf("error constructing test HTTP request [%s]", err)
	}
	// create and execute the handler, passing the ResponseRecorder and fake request
	handler := AsciiCat(github.NewClient(nil))
	handler.ServeHTTP(w, r)

	// now that the request has been 'served' by the handler, check the response that it would
	// have returned
	if w.Code != http.StatusOK {
		t.Fatalf("expected code %d, got %d", http.StatusOK, w.Code)
	}
	bodyStr := string(w.Body.Bytes())
	if len(bodyStr) <= 0 {
		t.Fatalf("expected non-empty response body")
	}
	ghClient := github.NewClient(nil)
	expectedCat, _, err := ghClient.Octocat("Hello, Go In 5 Minutes Viewer!")
	if err != nil {
		t.Fatalf("error getting expected octocat string [%s]", err)
	}
	if bodyStr != expectedCat {
		t.Fatalf("got unexpected octocat string [%s]", bodyStr)
	}
	// ResponseRecorder records more useful data about the response.
	// see http://godoc.org/net/http/httptest#ResponseRecorder for details
}
开发者ID:choirudin2210,项目名称:go-in-5-minutes,代码行数:39,代码来源:ascii_cat_test.go

示例5: downloadReleaseFromGithub

func downloadReleaseFromGithub(r repo, artifact string, alias string) {
	client := github.NewClient(nil)

	config, err := loadConfig()
	if err != nil {
		DieWithError(err, "Could not load user config")
	}

	if token, ok := config.Config["token"]; ok {
		log.Debug("Using Github token from config.")
		// if the user has a token stored, use it
		ts := oauth2.StaticTokenSource(
			&oauth2.Token{AccessToken: token},
		)
		tc := oauth2.NewClient(oauth2.NoContext, ts)
		client = github.NewClient(tc)
	} else {
		log.Debug("No Github token found in config. Add it with `mup config` if you need it")
	}

	// with a provided token, this will also get repos for the authenticated user
	// TODO: support pagination
	releases, resp, err := client.Repositories.ListReleases(r.Owner, r.Repo, nil)
	if resp.StatusCode == 404 {
		Die("Could not find repository %s/%s. Maybe it doesn't exist, or you need to add your token for μpdater to have access.", r.Owner, r.Repo)
	} else if err != nil {
		DieWithError(err, "Error reaching Github")
	}

	updateFromGithubReleases(client, r, releases, "", artifact, alias)
}
开发者ID:jordanti,项目名称:mupdater,代码行数:31,代码来源:apps.go

示例6: MakeClient

func MakeClient(token string) *github.Client {
	if len(token) > 0 {
		ts := oauth2.StaticTokenSource(&oauth2.Token{AccessToken: token})
		tc := oauth2.NewClient(oauth2.NoContext, ts)
		return github.NewClient(tc)
	}
	return github.NewClient(nil)
}
开发者ID:shrids,项目名称:kubernetes,代码行数:8,代码来源:github.go

示例7: makeGithubClient

func makeGithubClient(token string) *github.Client {
	if token != "" {
		t := &oauth.Transport{
			Token: &oauth.Token{AccessToken: token},
		}
		return github.NewClient(t.Client())
	}
	return github.NewClient(nil)
}
开发者ID:gdestuynder,项目名称:r2d2,代码行数:9,代码来源:github_cli.go

示例8: buildGithubClient

func buildGithubClient() *github.Client {
	if token != "" {
		tokenSource := oauth2.StaticTokenSource(&oauth2.Token{AccessToken: token})
		httpClient := oauth2.NewClient(oauth2.NoContext, tokenSource)
		return github.NewClient(httpClient)
	}

	return github.NewClient(nil)
}
开发者ID:getcarina,项目名称:dvm,代码行数:9,代码来源:dvm-helper.go

示例9: newGithubClient

func newGithubClient() githubClient {
	gt := os.Getenv(gitHubAPITokenEnvVar)
	t := &oauth.Transport{
		Token: &oauth.Token{AccessToken: gt},
	}
	github.NewClient(t.Client())
	c := github.NewClient(t.Client())
	return githubClientProd{
		org:  c.Organizations,
		repo: c.Repositories,
	}
}
开发者ID:gnomix,项目名称:goship,代码行数:12,代码来源:goship.go

示例10: newClient

func newClient() *github.Client {
	githubToken := os.Getenv("GITHUB_TOKEN")

	if githubToken != "" {
		oauthTransport := &oauth.Transport{
			Token: &oauth.Token{AccessToken: githubToken},
		}
		return github.NewClient(oauthTransport.Client())
	}

	return github.NewClient(nil)
}
开发者ID:neguse,项目名称:github-list-starred,代码行数:12,代码来源:main.go

示例11: getGithubClient

func getGithubClient(db *gorp.DbMap) *github.Client {
	token := getConfig(db).GithubToken
	if token != "" {
		ts := &tokenSource{
			&oauth2.Token{AccessToken: token},
		}
		tc := oauth2.NewClient(oauth2.NoContext, ts)
		return github.NewClient(tc)
	} else {
		return github.NewClient(nil)
	}
}
开发者ID:jamesturk,项目名称:graveyard,代码行数:12,代码来源:github.go

示例12: GetGithubClient

func GetGithubClient(owner string, repository string) (*github.Client, error) {
	accessToken, getTokenError := loadAccessToken(owner, repository)
	if getTokenError != nil {

		return github.NewClient(nil), getTokenError
	}
	t := &oauth.Transport{
		Token: &oauth.Token{AccessToken: accessToken},
	}

	return github.NewClient(t.Client()), nil
}
开发者ID:marmelab,项目名称:go-deploy,代码行数:12,代码来源:repositoriesManagers.go

示例13: newClient

func newClient(accessToken string) (client *github.Client) {
	if accessToken == "" {
		client = github.NewClient(nil)
	} else {
		transport := &oauth.Transport{
			Token: &oauth.Token{AccessToken: accessToken},
		}
		client = github.NewClient(transport.Client())
	}

	return
}
开发者ID:sdidyk,项目名称:githubissues,代码行数:12,代码来源:githubissues.go

示例14: init

func init() {
	token := os.Getenv("GITHUB_AUTH_TOKEN")
	if token == "" {
		print("!!! No OAuth token.  Some tests won't run. !!!\n\n")
		client = github.NewClient(nil)
	} else {
		tc := oauth2.NewClient(oauth2.NoContext, oauth2.StaticTokenSource(
			&oauth2.Token{AccessToken: token},
		))
		client = github.NewClient(tc)
		auth = true
	}
}
开发者ID:dindinet,项目名称:go-github,代码行数:13,代码来源:github_test.go

示例15: CreateClientConnection

// CreateClientConnection is a helper function for creating a connection to the
// Github API based on whether or not an auth token is supplied.
func CreateClientConnection() *github.Client {
	var client *github.Client
	config := new(Configuration)
	if config.Github.Token == "empty" {
		client = github.NewClient(nil)
		return client
	} else {
		ts := oauth2.StaticTokenSource(&oauth2.Token{AccessToken: TOKEN})
		tc := oauth2.NewClient(oauth2.NoContext, ts)
		client = github.NewClient(tc)
		return client
	}
}
开发者ID:jmreicha,项目名称:stalker,代码行数:15,代码来源:github.go


注:本文中的github.com/google/go-github/github.NewClient函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。