本文整理汇总了Golang中github.com/google/go-github/github.Bool函数的典型用法代码示例。如果您正苦于以下问题:Golang Bool函数的具体用法?Golang Bool怎么用?Golang Bool使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Bool函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: create
func create(desc string, pub bool, files map[string]string) (*github.Gist, error) {
ghat := getAccessToken()
ts := oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: ghat},
)
tc := oauth2.NewClient(oauth2.NoContext, ts)
client := github.NewClient(tc)
f := make(map[github.GistFilename]github.GistFile)
for k := range files {
_k := github.GistFilename(k)
f[_k] = github.GistFile{Content: github.String(files[k])}
}
gist := &github.Gist{
Description: github.String(desc),
Public: github.Bool(pub),
Files: f,
}
gist, _, err := client.Gists.Create(gist)
return gist, err
}
示例2: newDraftRepositoryRelease
func newDraftRepositoryRelease(id int, version string) github.RepositoryRelease {
return github.RepositoryRelease{
TagName: github.String(version),
Draft: github.Bool(true),
ID: github.Int(id),
}
}
示例3: TestGitHubClient_Upload
func TestGitHubClient_Upload(t *testing.T) {
client := testGithubClient(t)
testTag := "github-client-upload-asset"
req := &github.RepositoryRelease{
TagName: github.String(testTag),
Draft: github.Bool(true),
}
release, err := client.CreateRelease(context.TODO(), req)
if err != nil {
t.Fatal("CreateRelease failed:", err)
}
defer func() {
if err := client.DeleteRelease(context.TODO(), *release.ID); err != nil {
t.Fatalf("DeleteRelease failed: %s", err)
}
}()
filename := filepath.Join("./testdata", "darwin_386")
asset, err := client.UploadAsset(context.TODO(), *release.ID, filename)
if err != nil {
t.Fatal("UploadAsset failed:", err)
}
githubClient, ok := client.(*GitHubClient)
if !ok {
t.Fatal("Faield to asset to GithubClient")
}
rc, url, err := githubClient.Repositories.DownloadReleaseAsset(
githubClient.Owner, githubClient.Repo, *asset.ID)
if err != nil {
t.Fatal("DownloadReleaseAsset failed:", err)
}
var buf bytes.Buffer
if len(url) != 0 {
res, err := http.Get(url)
if err != nil {
t.Fatal("http.Get failed:", err)
}
if _, err := io.Copy(&buf, res.Body); err != nil {
t.Fatal("Copy failed:", err)
}
res.Body.Close()
} else {
if _, err := io.Copy(&buf, rc); err != nil {
t.Fatal("Copy failed:", err)
}
rc.Close()
}
if got, want := buf.String(), "darwin_386\n"; got != want {
t.Fatalf("file body is %q, want %q", got, want)
}
}
示例4: TestGHR_UploadAssets
func TestGHR_UploadAssets(t *testing.T) {
githubClient := testGithubClient(t)
GHR := &GHR{
GitHub: githubClient,
outStream: ioutil.Discard,
}
testTag := "ghr-upload-assets"
req := &github.RepositoryRelease{
TagName: github.String(testTag),
Draft: github.Bool(true),
}
// Create an existing release before
release, err := githubClient.CreateRelease(context.TODO(), req)
if err != nil {
t.Fatalf("CreateRelease failed: %s", err)
}
defer func() {
if err := githubClient.DeleteRelease(context.TODO(), *release.ID); err != nil {
t.Fatal("DeleteRelease failed:", err)
}
}()
localTestAssets, err := LocalAssets(TestDir)
if err != nil {
t.Fatal("LocalAssets failed:", err)
}
if err := GHR.UploadAssets(context.TODO(), *release.ID, localTestAssets, 4); err != nil {
t.Fatal("GHR.UploadAssets failed:", err)
}
assets, err := githubClient.ListAssets(context.TODO(), *release.ID)
if err != nil {
t.Fatal("ListAssets failed:", err)
}
if got, want := len(assets), 4; got != want {
t.Fatalf("upload assets number = %d, want %d", got, want)
}
// Delete all assets
parallel := 4
if err := GHR.DeleteAssets(context.TODO(), *release.ID, localTestAssets, parallel); err != nil {
t.Fatal("GHR.DeleteAssets failed:", err)
}
assets, err = githubClient.ListAssets(context.TODO(), *release.ID)
if err != nil {
t.Fatal("ListAssets failed:", err)
}
if got, want := len(assets), 0; got != want {
t.Fatalf("upload assets number = %d, want %d", got, want)
}
}
示例5: TestActivity_Watching
func TestActivity_Watching(t *testing.T) {
watchers, _, err := client.Activity.ListWatchers("google", "go-github", nil)
if err != nil {
t.Fatalf("Activity.ListWatchers returned error: %v", err)
}
if len(watchers) == 0 {
t.Errorf("Activity.ListWatchers('google', 'go-github') returned no watchers")
}
// the rest of the tests requires auth
if !checkAuth("TestActivity_Watching") {
return
}
// first, check if already watching google/go-github
sub, _, err := client.Activity.GetRepositorySubscription("google", "go-github")
if err != nil {
t.Fatalf("Activity.GetRepositorySubscription returned error: %v", err)
}
if sub != nil {
t.Fatalf("Already watching google/go-github. Please manually stop watching it first.")
}
// watch google/go-github
sub = &github.Subscription{Subscribed: github.Bool(true)}
_, _, err = client.Activity.SetRepositorySubscription("google", "go-github", sub)
if err != nil {
t.Fatalf("Activity.SetRepositorySubscription returned error: %v", err)
}
// check again and verify watching
sub, _, err = client.Activity.GetRepositorySubscription("google", "go-github")
if err != nil {
t.Fatalf("Activity.GetRepositorySubscription returned error: %v", err)
}
if sub == nil || !*sub.Subscribed {
t.Fatalf("Not watching google/go-github after setting subscription.")
}
// delete subscription
_, err = client.Activity.DeleteRepositorySubscription("google", "go-github")
if err != nil {
t.Fatalf("Activity.DeleteRepositorySubscription returned error: %v", err)
}
// check again and verify not watching
sub, _, err = client.Activity.GetRepositorySubscription("google", "go-github")
if err != nil {
t.Fatalf("Activity.GetRepositorySubscription returned error: %v", err)
}
if sub != nil {
t.Fatalf("Still watching google/go-github after deleting subscription.")
}
}
示例6: CreateRepo
// CreateRepo will create a new repository in the organization on github.
//
// TODO: When the hook option is activated, it can only create a push hook.
// Extend this to include a optional event hook.
func (o *Organization) CreateRepo(opt RepositoryOptions) (err error) {
err = o.connectAdminToGithub()
if err != nil {
return
}
if opt.Name == "" {
return errors.New("Missing required name field. ")
}
repo := &github.Repository{}
repo.Name = github.String(opt.Name)
repo.Private = github.Bool(opt.Private)
repo.AutoInit = github.Bool(opt.AutoInit)
repo.HasIssues = github.Bool(opt.Issues)
if opt.TeamID != 0 {
repo.TeamID = github.Int(opt.TeamID)
}
_, _, err = o.githubadmin.Repositories.Create(o.Name, repo)
if err != nil {
return
}
if opt.Hook != "" {
config := make(map[string]interface{})
config["url"] = global.Hostname + "/event/hook"
config["content_type"] = "json"
hook := github.Hook{
Name: github.String("web"),
Config: config,
Events: []string{
opt.Hook,
},
}
_, _, err = o.githubadmin.Repositories.CreateHook(o.Name, opt.Name, &hook)
}
return
}
示例7: NewHook
// NewHook returns a new github.Hook instance that represents the appropriate
// configuration for the Conveyor webhook.
func NewHook(url, secret string) *github.Hook {
return &github.Hook{
Events: []string{"push"},
Active: github.Bool(true),
Name: github.String("web"),
Config: map[string]interface{}{
"url": url,
"content_type": "json",
"secret": secret,
},
}
}
示例8: TestRepositories_EditBranches
func TestRepositories_EditBranches(t *testing.T) {
if !checkAuth("TestRepositories_EditBranches") {
return
}
// get authenticated user
me, _, err := client.Users.Get("")
if err != nil {
t.Fatalf("Users.Get('') returned error: %v", err)
}
repo, err := createRandomTestRepository(*me.Login, true)
if err != nil {
t.Fatalf("createRandomTestRepository returned error: %v", err)
}
branch, _, err := client.Repositories.GetBranch(*repo.Owner.Login, *repo.Name, "master")
if err != nil {
t.Fatalf("Repositories.GetBranch() returned error: %v", err)
}
if *branch.Protection.Enabled {
t.Fatalf("Branch %v of repo %v is already protected", "master", *repo.Name)
}
branch.Protection.Enabled = github.Bool(true)
branch.Protection.RequiredStatusChecks = &github.RequiredStatusChecks{
EnforcementLevel: github.String("everyone"),
Contexts: &[]string{"continous-integration"},
}
branch, _, err = client.Repositories.EditBranch(*repo.Owner.Login, *repo.Name, "master", branch)
if err != nil {
t.Fatalf("Repositories.EditBranch() returned error: %v", err)
}
if !*branch.Protection.Enabled {
t.Fatalf("Branch %v of repo %v should be protected, but is not!", "master", *repo.Name)
}
if *branch.Protection.RequiredStatusChecks.EnforcementLevel != "everyone" {
t.Fatalf("RequiredStatusChecks should be enabled for everyone, set for: %v", *branch.Protection.RequiredStatusChecks.EnforcementLevel)
}
wantedContexts := []string{"continous-integration"}
if !reflect.DeepEqual(*branch.Protection.RequiredStatusChecks.Contexts, wantedContexts) {
t.Fatalf("RequiredStatusChecks.Contexts should be: %v but is: %v", wantedContexts, *branch.Protection.RequiredStatusChecks.Contexts)
}
_, err = client.Repositories.Delete(*repo.Owner.Login, *repo.Name)
if err != nil {
t.Fatalf("Repositories.Delete() returned error: %v", err)
}
}
示例9: TestGitHubClient_ListAssets
func TestGitHubClient_ListAssets(t *testing.T) {
client := testGithubClient(t)
testTag := "github-list-assets"
req := &github.RepositoryRelease{
TagName: github.String(testTag),
Draft: github.Bool(true),
}
release, err := client.CreateRelease(context.TODO(), req)
if err != nil {
t.Fatal("CreateRelease failed:", err)
}
defer func() {
if err := client.DeleteRelease(context.TODO(), *release.ID); err != nil {
t.Fatalf("DeleteRelease failed: %s", err)
}
}()
for _, filename := range []string{"darwin_386", "darwin_amd64"} {
filename := filepath.Join("./testdata", filename)
if _, err := client.UploadAsset(context.TODO(), *release.ID, filename); err != nil {
t.Fatal("UploadAsset failed:", err)
}
}
assets, err := client.ListAssets(context.TODO(), *release.ID)
if err != nil {
t.Fatal("ListAssets failed:", err)
}
if got, want := len(assets), 2; got != want {
t.Fatalf("ListAssets number = %d, want %d", got, want)
}
if err := client.DeleteAsset(context.TODO(), *assets[0].ID); err != nil {
t.Fatal("DeleteAsset failed:", err)
}
assets, err = client.ListAssets(context.TODO(), *release.ID)
if err != nil {
t.Fatal("ListAssets failed:", err)
}
if got, want := len(assets), 1; got != want {
t.Fatalf("ListAssets number = %d, want %d", got, want)
}
}
示例10: createRepo
// create a new private repository named name for the given team
func createRepo(name string, team int) {
repo := &github.Repository{
Name: github.String(name),
Private: github.Bool(false), // TODO Update once github has given me private repos
}
r, _, err := client.Repositories.Create(courseOrg, repo)
if err != nil {
fmt.Printf("Failed to create repo: %s: %v\n", name, err)
return
}
fmt.Printf("Created repository: %s for team %d;\n URL: %s\n", name, team, *r.URL)
_, err = client.Organizations.AddTeamRepo(team, courseOrg, name)
if err != nil {
fmt.Printf("Failed to add team %d to repo: %s: %v\n", team, name, err)
}
fmt.Println("Added team to repository:", name)
}
示例11: Create
// Create will create a Gist(https://gist.github.com/)
//
// If gist was created http.Response.StatusCode will be
// http.StatusCreated.(201)
func Create(githubToken string, gistParam CreateParams) (string, *http.Response, error) {
client := connectGithub(githubToken)
gf := &github.GistFile{
Filename: github.String(gistParam.FileName),
Content: github.String(gistParam.Content),
}
gist := &github.Gist{
Description: github.String(gistParam.Description),
Public: github.Bool(gistParam.Public),
Files: map[github.GistFilename]github.GistFile{"": *gf},
}
gst, resp, err := client.Gists.Create(gist)
return *gst.HTMLURL, resp.Response, err
}
示例12: CreateDeployment
func (b *GithubBackend) CreateDeployment(ref string, env string) error {
client := b.getClient()
user, repo := b.parseGithubInfo()
status_req := github.DeploymentRequest{
Ref: &ref,
Task: github.String("deploy"),
AutoMerge: github.Bool(false),
Environment: &env,
}
_, _, err := client.Repositories.CreateDeployment(user, repo, &status_req)
if err != nil {
return err
}
return nil
}
示例13: TestGHR_CreateRelease
func TestGHR_CreateRelease(t *testing.T) {
t.Parallel()
githubClient := testGithubClient(t)
GHR := &GHR{
GitHub: githubClient,
outStream: ioutil.Discard,
}
testTag := "create-release"
req := &github.RepositoryRelease{
TagName: &testTag,
Draft: github.Bool(false),
}
recreate := false
release, err := GHR.CreateRelease(context.TODO(), req, recreate)
if err != nil {
t.Fatal("CreateRelease failed:", err)
}
defer GHR.DeleteRelease(context.TODO(), *release.ID, testTag)
}
示例14: CreateRepo
// CreateRepo creates a repository in the github user account
func (repo GithubRepository) CreateRepo(username, reponame, org string, private bool) (*domain.Repository, error) {
rp := &github.Repository{
Name: github.String(reponame),
Private: github.Bool(private),
}
rp, _, err := repo.client.Repositories.Create(org, rp)
if err != nil {
return nil, err
}
r := &domain.Repository{
Name: rp.Name,
FullName: rp.FullName,
Description: rp.Description,
Private: rp.Private,
HTMLURL: rp.HTMLURL,
CloneURL: rp.CloneURL,
SSHURL: rp.SSHURL,
}
return r, nil
}
示例15:
On("Get", repositoryOwner, repositoryName, issueNumber).
Return(nil, nil, errors.New("an error"))
})
It("fails with a gateway error", func() {
handle()
Expect(responseRecorder.Code).To(Equal(http.StatusBadGateway))
})
})
Context("with the PR being already merged", func() {
BeforeEach(func() {
pullRequests.
On("Get", repositoryOwner, repositoryName, issueNumber).
Return(&github.PullRequest{
Merged: github.Bool(true),
}, nil, nil)
})
It("removes the 'merging' label from the PR", func() {
issues.
On("RemoveLabelForIssue", repositoryOwner, repositoryName, issueNumber, grh.MergingLabel).
Return(nil, nil, nil)
handle()
Expect(responseRecorder.Code).To(Equal(http.StatusOK))
})
})
Context("with the PR not being mergeable", func() {
BeforeEach(func() {