• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang github.NewClient函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: 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 {
		t := &oauth.Transport{
			Token: &oauth.Token{AccessToken: token},
		}
		client = github.NewClient(t.Client())
		auth = true
	}
}
开发者ID:Christeefym,项目名称:lantern,代码行数:13,代码来源:github_test.go


示例17: NewIssueAPI

func NewIssueAPI() *IssueAPI {
	token, err := queryToken("Github_Token", "vampirewalk")
	if err != nil {
		client := github.NewClient(nil)
		return &IssueAPI{Client: client}
	}

	ts := oauth2.StaticTokenSource(
		&oauth2.Token{AccessToken: token},
	)
	tc := oauth2.NewClient(oauth2.NoContext, ts)
	client := github.NewClient(tc)

	return &IssueAPI{Client: client}
}
开发者ID:vampirewalk,项目名称:rehook,代码行数:15,代码来源:issue_api.go


示例18: addonZip

func addonZip(ctx *gin.Context, user string, repository string, lastReleaseTag string) {
	release := getReleaseByTag(user, repository, lastReleaseTag)
	// if there a release with an asset that matches a addon zip, use it
	if release != nil {
		client := github.NewClient(nil)
		assets, _, _ := client.Repositories.ListReleaseAssets(user, repository, *release.ID, nil)
		platformStruct := xbmc.GetPlatform()
		platform := platformStruct.OS + "_" + platformStruct.Arch
		var assetAllPlatforms string
		for _, asset := range assets {
			if strings.HasSuffix(*asset.Name, platform+".zip") {
				assetPlatform := *asset.BrowserDownloadURL
				log.Info("Using release asset for " + platform + ": " + assetPlatform)
				ctx.Redirect(302, assetPlatform)
				return
			}
			if addonZipRE.MatchString(*asset.Name) {
				assetAllPlatforms = *asset.BrowserDownloadURL
				log.Info("Found all platforms release asset: " + assetAllPlatforms)
				continue
			}
		}
		if assetAllPlatforms != "" {
			log.Info("Using release asset for all platforms: " + assetAllPlatforms)
			ctx.Redirect(302, assetAllPlatforms)
			return
		}
	}
	ctx.AbortWithError(404, errors.New("Release asset not found."))
}
开发者ID:scakemyer,项目名称:quasar,代码行数:30,代码来源:repository.go


示例19: cmdShowLabels

// cmdShowLabels prints the labels for a project for easy inclusion
// in the config
func cmdShowLabels(opts *Options, project string) error {
	tc := AuthClient(opts)
	client := github.NewClient(tc)

	owner, repo, err := ownerRepo(project)
	if err != nil {
		return err
	}

	labels, _, err := client.Issues.ListLabels(owner, repo, &github.ListOptions{})
	if err != nil {
		return err
	}

	out := []Label{}
	for _, label := range labels {
		out = append(out, Label{*label.Name, *label.Color})
	}

	d, err := yaml.Marshal(out)
	if err != nil {
		return err
	}
	fmt.Printf("%s", d)
	return nil
}
开发者ID:simonyangme,项目名称:triage,代码行数:28,代码来源:label.go


示例20: NewPolymerCrawler

// NewPolymerCrawler returns a new PolymerCrawler.
func NewPolymerCrawler(accessToken string) *PolymerCrawler {
	if accessToken == "" {
		log.Println("Github AccessToken is empty.")
		return &PolymerCrawler{
			client: github.NewClient(nil),
		}
	}

	t := &oauth.Transport{
		Token: &oauth.Token{AccessToken: GITHUB_TOKEN},
	}

	return &PolymerCrawler{
		client: github.NewClient(t.Client()),
	}
}
开发者ID:RahulSDeshpande,项目名称:mecca,代码行数:17,代码来源:polymer.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang github.String函数代码示例发布时间:2022-05-23
下一篇:
Golang github.Bool函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap