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

Golang github.String函数代码示例

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

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



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

示例1: createSquashStatus

func createSquashStatus(state, description string) *github.RepoStatus {
	return &github.RepoStatus{
		State:       github.String(state),
		Description: github.String(description),
		Context:     github.String(githubStatusSquashContext),
	}
}
开发者ID:salemove,项目名称:github-review-helper,代码行数:7,代码来源:squash.go


示例2: CreateKey

// CreateKey is a heper function that creates a deploy key
// for the specified repository.
func CreateKey(client *github.Client, owner, name, title, key string) (*github.Key, error) {
	var k = new(github.Key)
	k.Title = github.String(title)
	k.Key = github.String(key)
	created, _, err := client.Repositories.CreateKey(owner, name, k)
	return created, err
}
开发者ID:ngpestelos,项目名称:drone,代码行数:9,代码来源:helper.go


示例3: createIssue

func createIssue(
	task string,
	config Config,
	owner string,
	repo string,
	issueTitle string,
	issueBody string,
	milestone *github.Milestone,
) (issue *github.Issue, err error) {

	log.Run(task)
	client := ghutil.NewClient(config.Token())
	labels := []string{config.ReviewLabel()}
	issue, _, err = client.Issues.Create(owner, repo, &github.IssueRequest{
		Title:     github.String(issueTitle),
		Body:      github.String(issueBody),
		Labels:    &labels,
		Milestone: milestone.Number,
	})
	if err != nil {
		return nil, errs.NewError(task, err)
	}

	log.Log(fmt.Sprintf("GitHub issue #%v created", *issue.Number))
	return issue, nil
}
开发者ID:jkotrlik,项目名称:salsaflow,代码行数:26,代码来源:code_review_tool.go


示例4: SetStatus

func (g *Github) SetStatus(u *model.User, r *model.Repo, num, granted, required int) error {
	client := setupClient(g.API, u.Token)

	pr, _, err := client.PullRequests.Get(r.Owner, r.Name, num)
	if err != nil {
		return err
	}

	status := "success"
	desc := "this commit looks good"

	if granted < required {
		status = "pending"
		desc = fmt.Sprintf("%d of %d required approvals granted", granted, required)
	}

	data := github.RepoStatus{
		Context:     github.String(context),
		State:       github.String(status),
		Description: github.String(desc),
	}

	_, _, err = client.Repositories.CreateStatus(r.Owner, r.Name, *pr.Head.SHA, &data)
	return err
}
开发者ID:lgtmco,项目名称:lgtm,代码行数:25,代码来源:github.go


示例5: Tag

func (g *Github) Tag(u *model.User, r *model.Repo, version *string, sha *string) error {
	client := setupClient(g.API, u.Token)

	t := time.Now()
	tag, _, err := client.Git.CreateTag(r.Owner, r.Name, &github.Tag{
		Tag:     version,
		SHA:     sha,
		Message: github.String("Tagged by LGTM"),
		Tagger: &github.CommitAuthor{
			Date:  &t,
			Name:  github.String("LGTM"),
			Email: github.String("[email protected]"),
		},
		Object: &github.GitObject{
			SHA:  sha,
			Type: github.String("commit"),
		},
	})

	if err != nil {
		return err
	}
	_, _, err = client.Git.CreateRef(r.Owner, r.Name, &github.Reference{
		Ref: github.String("refs/tags/" + *version),
		Object: &github.GitObject{
			SHA: tag.SHA,
		},
	})

	return err
}
开发者ID:jonbodner,项目名称:lgtm,代码行数:31,代码来源:github.go


示例6: RegisterResult

//RegisterResult registers the supplied result
func (githubClient *GitHubClient) RegisterResult(result Result) error {
	ts := oauth2.StaticTokenSource(
		&oauth2.Token{AccessToken: githubClient.Token},
	)
	tc := oauth2.NewClient(oauth2.NoContext, ts)
	client := github.NewClient(tc)

	if githubClient.BaseUrl != nil {
		client.BaseURL = githubClient.BaseUrl
	}

	log.Info("Submitting result")
	repositories := client.Repositories
	status, _, err := repositories.CreateStatus(
		githubClient.From,
		githubClient.Repo,
		result.SHA,
		&github.RepoStatus{
			State:       github.String(result.State),
			TargetURL:   github.String(result.Url),
			Description: github.String(result.Message),
			Context:     github.String("continuous-integraion/walter"),
		})
	log.Infof("Submit status: %s", status)
	if err != nil {
		log.Errorf("Failed to register result: %s", err)
	}
	return err
}
开发者ID:FabianFrancoRoldan,项目名称:walter,代码行数:30,代码来源:github.go


示例7: FinaliseRelease

func (tool *codeReviewTool) FinaliseRelease(v *version.Version) (action.Action, error) {
	// Get a GitHub client.
	config, err := LoadConfig()
	if err != nil {
		return nil, err
	}
	client := ghutil.NewClient(config.Token())

	owner, repo, err := git.ParseUpstreamURL()
	if err != nil {
		return nil, err
	}

	// Get the relevant review milestone.
	releaseString := v.BaseString()
	task := fmt.Sprintf("Get GitHub review milestone for release %v", releaseString)
	log.Run(task)
	milestone, err := milestoneForVersion(config, owner, repo, v)
	if err != nil {
		return nil, errs.NewError(task, err)
	}
	if milestone == nil {
		log.Warn(fmt.Sprintf(
			"Weird, GitHub review milestone for release %v not found", releaseString))
		return nil, nil
	}

	// Close the milestone unless there are some issues open.
	task = fmt.Sprintf(
		"Make sure the review milestone for release %v can be closed", releaseString)
	if num := *milestone.OpenIssues; num != 0 {
		return nil, errs.NewError(
			task,
			fmt.Errorf(
				"review milestone for release %v cannot be closed: %v issue(s) open",
				releaseString, num))
	}

	milestoneTask := fmt.Sprintf("Close GitHub review milestone for release %v", releaseString)
	log.Run(milestoneTask)
	milestone, _, err = client.Issues.EditMilestone(owner, repo, *milestone.Number, &github.Milestone{
		State: github.String("closed"),
	})
	if err != nil {
		return nil, errs.NewError(milestoneTask, err)
	}

	// Return a rollback function.
	return action.ActionFunc(func() error {
		log.Rollback(milestoneTask)
		task := fmt.Sprintf("Reopen GitHub review milestone for release %v", releaseString)
		_, _, err := client.Issues.EditMilestone(owner, repo, *milestone.Number, &github.Milestone{
			State: github.String("open"),
		})
		if err != nil {
			return errs.NewError(task, err)
		}
		return nil
	}), nil
}
开发者ID:jkotrlik,项目名称:salsaflow,代码行数:60,代码来源:code_review_tool.go


示例8: TestMain

// Test handler with correct input.
func TestMain(t *testing.T) {
	pullrequest := github.PullRequestEvent{
		Action: github.String("opened"),
		Number: github.Int(0),
		Repo: &github.Repository{
			FullName: github.String("test"),
		},
	}
	reqbody, _ := json.Marshal(pullrequest)

	handler := New(Configuration{})
	runner := func(handler *Handler, event github.PullRequestEvent) {}

	ts := httptest.NewServer(mainHandler(handler, runner))
	defer ts.Close()

	req, _ := http.NewRequest("GET", ts.URL, bytes.NewBuffer(reqbody))
	resp, err := http.DefaultClient.Do(req)

	if err != nil {
		t.Fatalf("HTTP Request failed: %s", err)
	}

	if resp.StatusCode != http.StatusAccepted {
		t.Errorf("Expected HTTP %d, got HTTP %d", http.StatusAccepted, resp.StatusCode)
	}
}
开发者ID:hansrodtang,项目名称:pull,代码行数:28,代码来源:pull_test.go


示例9: 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
}
开发者ID:chanux,项目名称:gogist,代码行数:28,代码来源:main.go


示例10: CreateTeam

// CreateTeam will create a new team in the organization on github.
func (o *Organization) CreateTeam(opt TeamOptions) (teamID int, err error) {
	err = o.connectAdminToGithub()
	if err != nil {
		return
	}

	team := &github.Team{}
	team.Name = github.String(opt.Name)
	if opt.Permission != "" {
		team.Permission = github.String(opt.Permission)
	}
	team, _, err = o.githubadmin.Organizations.CreateTeam(o.Name, team)
	if err != nil {
		return
	}

	if opt.RepoNames != nil {
		for _, repo := range opt.RepoNames {
			_, err = o.githubadmin.Organizations.AddTeamRepo(*team.ID, o.Name, repo, nil)
			if err != nil {
				log.Println(err)
			}
		}
	}

	return *team.ID, nil
}
开发者ID:tokams,项目名称:autograder,代码行数:28,代码来源:organisation.go


示例11: Success

func Success(url string, desc string, c string) *github.RepoStatus {
	return &github.RepoStatus{
		State:       github.String("success"),
		TargetURL:   github.String(url),
		Description: github.String(desc),
		Context:     github.String("pull/" + c),
	}
}
开发者ID:hansrodtang,项目名称:pull,代码行数:8,代码来源:helpers.go


示例12: Failure

func Failure(url string, desc string, c string) *github.RepoStatus {
	return &github.RepoStatus{
		State:       github.String("failure"),
		TargetURL:   github.String(url),
		Description: github.String(desc),
		Context:     github.String("pull/" + c),
	}
}
开发者ID:hansrodtang,项目名称:pull,代码行数:8,代码来源:helpers.go


示例13: main

func main() {
	owner := os.Getenv("GITHUB_OWNER")
	repo := os.Getenv("GITHUB_REPO")
	token := os.Getenv("GITHUB_AUTH_TOKEN")
	filename := os.Getenv("GITHUB_RELEASE_ASSET")
	releasename := os.Getenv("GITHUB_RELEASE_NAME")

	// Open the release asset file
	file, err := os.Open(filename)
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}

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

	// Make a commit to Releases.md
	message := releasename
	content := []byte(releasename)
	repositoryContentsOptions := &github.RepositoryContentFileOptions{
		Message: &message,
		Content: content,
		Committer: &github.CommitAuthor{Name: github.String("bonnyrigg"),
			Email: github.String("[email protected]")},
	}
	path := "releases/"
	path += releasename
	_, _, err = client.Repositories.CreateFile(owner, repo,
		path, repositoryContentsOptions)
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}

	// Create the release
	name := github.String(releasename)
	request := &github.RepositoryRelease{
		Name:    name,
		TagName: name,
	}
	release, _, err := client.Repositories.CreateRelease(owner, repo, request)
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}

	// Upload the release asset file to the release
	opt := &github.UploadOptions{Name: filename}
	releaseasset, _, err := client.Repositories.UploadReleaseAsset(owner, repo, *release.ID, opt, file)
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}
	fmt.Printf("%s: Asset %s. Version: %s\n", *releaseasset.Name, *releaseasset.State, *name)
}
开发者ID:larstobi,项目名称:github-release-upload,代码行数:58,代码来源:main.go


示例14: extendReviewRequest

// extendReviewRequest is a general function that can be used to extend
// the given review issue with the given list of commits.
func extendReviewRequest(
	config Config,
	owner string,
	repo string,
	issue *github.Issue,
	commits []*git.Commit,
	opts map[string]interface{},
) error {

	var (
		issueNum     = *issue.Number
		issueBody    = *issue.Body
		bodyBuffer   = bytes.NewBufferString(issueBody)
		addedCommits = make([]*git.Commit, 0, len(commits))
	)

	for _, commit := range commits {
		// Make sure the commit is not added yet.
		commitString := fmt.Sprintf("] %v: %v", commit.SHA, commit.MessageTitle)
		if strings.Contains(issueBody, commitString) {
			log.Log(fmt.Sprintf("Commit %v already listed in issue #%v", commit.SHA, issueNum))
			continue
		}

		// Extend the issue body.
		addedCommits = append(addedCommits, commit)
		fmt.Fprintf(bodyBuffer, "\n- [ ] %v: %v", commit.SHA, commit.MessageTitle)
	}

	if len(addedCommits) == 0 {
		log.Log(fmt.Sprintf("All commits already listed in issue #%v", issueNum))
		return nil
	}

	// Edit the issue.
	task := fmt.Sprintf("Update GitHub issue #%v", issueNum)
	log.Run(task)

	client := ghutil.NewClient(config.Token())
	newIssue, _, err := client.Issues.Edit(owner, repo, issueNum, &github.IssueRequest{
		Body:  github.String(bodyBuffer.String()),
		State: github.String("open"),
	})
	if err != nil {
		return errs.NewError(task, err)
	}

	// Add the review comment.
	if err := addReviewComment(config, owner, repo, issueNum, addedCommits); err != nil {
		return err
	}

	// Open the issue if requested.
	if _, open := opts["open"]; open {
		return openIssue(newIssue)
	}
	return nil
}
开发者ID:jkotrlik,项目名称:salsaflow,代码行数:60,代码来源:code_review_tool.go


示例15: ScheduleDeployment

func (g *Github) ScheduleDeployment(u *model.User, r *model.Repo, d model.DeploymentInfo) error {
	client := setupClient(g.API, u.Token)
	_, _, err := client.Repositories.CreateDeployment(r.Owner, r.Name, &github.DeploymentRequest{
		Ref:         github.String(d.Ref),
		Task:        github.String(d.Task),
		Environment: github.String(d.Environment),
	})
	return err
}
开发者ID:jonbodner,项目名称:lgtm,代码行数:9,代码来源:github.go


示例16: repoStatus

func repoStatus(client *github.Client, r *model.Repo, b *model.Build, link string) error {
	data := github.RepoStatus{
		Context:     github.String("continuous-integration/drone"),
		State:       github.String(convertStatus(b.Status)),
		Description: github.String(convertDesc(b.Status)),
		TargetURL:   github.String(link),
	}
	_, _, err := client.Repositories.CreateStatus(r.Owner, r.Name, b.Commit, &data)
	return err
}
开发者ID:tnaoto,项目名称:drone,代码行数:10,代码来源:github.go


示例17: CreateUpdateKey

// CreateUpdateKey is a heper function that creates a deployment key
// for the specified repository if it does not already exist, otherwise
// it updates the existing key
func CreateUpdateKey(client *github.Client, owner, name, title, key string) (*github.Key, error) {
	var k, _ = GetKey(client, owner, name, title)
	if k != nil {
		k.Title = github.String(title)
		k.Key = github.String(key)
		client.Repositories.DeleteKey(owner, name, *k.ID)
	}

	return CreateKey(client, owner, name, title, key)
}
开发者ID:carnivalmobile,项目名称:drone,代码行数:13,代码来源:helper.go


示例18: generatePersonalAuthTokenRequest

// generatePersonalAuthTokenRequest is a helper function that generates an
// AuthorizationRequest for a Personal Access Token (no client id).
func generatePersonalAuthTokenRequest() *github.AuthorizationRequest {

	rand := randString()
	auth := github.AuthorizationRequest{
		Note:        github.String("Personal token: Note generated by test: " + rand),
		Scopes:      []github.Scope{github.ScopePublicRepo},
		Fingerprint: github.String("Personal token: Fingerprint generated by test: " + rand),
	}

	return &auth
}
开发者ID:alxp,项目名称:deadci,代码行数:13,代码来源:authorizations_test.go


示例19: CreateUpdateKey

// CreateUpdateKey is a heper function that creates a deployment key
// for the specified repository if it does not already exist, otherwise
// it updates the existing key
func CreateUpdateKey(client *github.Client, owner, name, title, key string) (*github.Key, error) {
	var k, _ = GetKey(client, owner, name, title)
	if k != nil {
		k.Title = github.String(title)
		k.Key = github.String(key)
		var updated, _, err = client.Repositories.EditKey(owner, name, *k.ID, k)
		return updated, err
	}

	return CreateKey(client, owner, name, title, key)
}
开发者ID:ngpestelos,项目名称:drone,代码行数:14,代码来源:helper.go


示例20: TestRepositories_CRUD

func TestRepositories_CRUD(t *testing.T) {
	if !checkAuth("TestRepositories_CRUD") {
		return
	}

	// get authenticated user
	me, _, err := client.Users.Get("")
	if err != nil {
		t.Fatalf("Users.Get('') returned error: %v", err)
	}

	// create random repo name that does not currently exist
	var repoName string
	for {
		repoName = fmt.Sprintf("test-%d", rand.Int())
		_, resp, err := client.Repositories.Get(*me.Login, repoName)
		if err != nil {
			if resp.StatusCode == http.StatusNotFound {
				// found a non-existant repo, perfect
				break
			}
			t.Fatalf("Repositories.Get() returned error: %v", err)
		}
	}

	// create the repository
	repo, _, err := client.Repositories.Create("", &github.Repository{Name: github.String(repoName)})
	if err != nil {
		t.Fatalf("Repositories.Create() returned error: %v", err)
	}

	// update the repository description
	repo.Description = github.String("description")
	repo.DefaultBranch = nil // FIXME: this shouldn't be necessary
	_, _, err = client.Repositories.Edit(*repo.Owner.Login, *repo.Name, repo)
	if err != nil {
		t.Fatalf("Repositories.Edit() returned error: %v", err)
	}

	// delete the repository
	_, err = client.Repositories.Delete(*repo.Owner.Login, *repo.Name)
	if err != nil {
		t.Fatalf("Repositories.Delete() returned error: %v", err)
	}

	// verify that the repository was deleted
	_, resp, err := client.Repositories.Get(*repo.Owner.Login, *repo.Name)
	if err == nil {
		t.Fatalf("Test repository still exists after deleting it.")
	}
	if err != nil && resp.StatusCode != http.StatusNotFound {
		t.Fatalf("Repositories.Get() returned error: %v", err)
	}
}
开发者ID:Christeefym,项目名称:lantern,代码行数:54,代码来源:repos_test.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang github.BasicAuthTransport类代码示例发布时间:2022-05-23
下一篇:
Golang github.NewClient函数代码示例发布时间: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