本文整理匯總了Golang中github.com/google/go-github/github.PullRequest類的典型用法代碼示例。如果您正苦於以下問題:Golang PullRequest類的具體用法?Golang PullRequest怎麽用?Golang PullRequest使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了PullRequest類的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: MungePullRequest
func (PingCIMunger) MungePullRequest(client *github.Client, pr *github.PullRequest, issue *github.Issue, commits []github.RepositoryCommit, events []github.IssueEvent, opts opts.MungeOptions) {
if !HasLabel(issue.Labels, "lgtm") {
return
}
if pr.Mergeable == nil || !*pr.Mergeable {
glog.Infof("skipping CI check for %d since mergeable is nil or false", *pr.Number)
return
}
status, err := github_util.GetStatus(client, opts.Org, opts.Project, *pr.Number, []string{"Shippable", "continuous-integration/travis-ci/pr"})
if err != nil {
glog.Errorf("unexpected error getting status: %v", err)
return
}
if status == "incomplete" {
if opts.Dryrun {
glog.Infof("would have pinged CI for %d", pr.Number)
return
}
glog.V(2).Infof("status is incomplete, closing and re-opening")
msg := "Continuous integration appears to have missed, closing and re-opening to trigger it"
if _, _, err := client.Issues.CreateComment(opts.Org, opts.Project, *pr.Number, &github.IssueComment{Body: &msg}); err != nil {
glog.Errorf("failed to create comment: %v", err)
}
state := "closed"
pr.State = &state
if _, _, err := client.PullRequests.Edit(opts.Org, opts.Project, *pr.Number, pr); err != nil {
glog.Errorf("Failed to close pr %d: %v", *pr.Number, err)
return
}
time.Sleep(5 * time.Second)
state = "open"
pr.State = &state
// Try pretty hard to re-open, since it's pretty bad if we accidentally leave a PR closed
for tries := 0; tries < 10; tries++ {
if _, _, err := client.PullRequests.Edit(opts.Org, opts.Project, *pr.Number, pr); err == nil {
break
} else {
glog.Errorf("failed to re-open pr %d: %v", *pr.Number, err)
}
time.Sleep(5 * time.Second)
}
}
}
示例2: ClosePR
func (config *GithubConfig) ClosePR(pr *github.PullRequest) error {
if config.DryRun {
glog.Infof("Would have closed PR# %d but --dry-run was set", *pr.Number)
return nil
}
state := "closed"
pr.State = &state
if _, _, err := config.client.PullRequests.Edit(config.Org, config.Project, *pr.Number, pr); err != nil {
glog.Errorf("Failed to close pr %d: %v", *pr.Number, err)
return err
}
return nil
}
示例3: OpenPR
// OpenPR will attempt to open the given PR.
func (config *GithubConfig) OpenPR(pr *github.PullRequest, numTries int) error {
if config.DryRun {
glog.Infof("Would have openned PR# %d but --dry-run was set", *pr.Number)
return nil
}
var err error
state := "open"
pr.State = &state
// Try pretty hard to re-open, since it's pretty bad if we accidentally leave a PR closed
for tries := 0; tries < numTries; tries++ {
if _, _, err = config.client.PullRequests.Edit(config.Org, config.Project, *pr.Number, pr); err == nil {
return nil
}
glog.Warningf("failed to re-open pr %d: %v", *pr.Number, err)
time.Sleep(5 * time.Second)
}
if err != nil {
glog.Errorf("failed to re-open pr %d after %d tries, giving up: %v", *pr.Number, numTries, err)
}
return err
}
示例4: closePullRequest
func (p *PullRequestCloser) closePullRequest(owner string, repo string, pull github.PullRequest, comment string, label string) error {
issueComment := &github.IssueComment{Body: github.String(comment)}
_, _, err := p.client.Issues.CreateComment(owner, repo, *pull.Number, issueComment)
if err != nil {
return err
}
if label != "" {
_, _, err = p.client.Issues.AddLabelsToIssue(owner, repo, *pull.Number, []string{label})
if err != nil {
return err
}
}
pull.State = github.String("closed")
_, _, err = p.client.PullRequests.Edit(owner, repo, *pull.Number, &pull)
if err != nil {
return err
}
return nil
}