當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。