コード例 #1
0
ファイル: ping_ci.go プロジェクト: tobad357/contrib
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
0
ファイル: oktotest.go プロジェクト: tobad357/contrib
func (OkToTestMunger) 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
	}
	status, err := github_util.GetStatus(client, opts.Org, opts.Project, *pr.Number, []string{"Jenkins GCE e2e"})
	if err != nil {
		glog.Errorf("unexpected error getting status: %v", err)
		return
	}
	if status == "incomplete" {
		if opts.Dryrun {
			glog.Infof("would have marked %d as ok to test", pr.Number)
			return
		}
		glog.V(2).Infof("status is incomplete, adding ok to test")
		msg := `@k8s-bot ok to test

	pr builder appears to be missing, activating due to 'lgtm' label.`
		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)
		}
	}
}