Esempio n. 1
0
File: cla.go Progetto: spxtr/contrib
// Initialize will initialize the munger.
func (cla *ClaMunger) Initialize(config *githubhelper.Config, features *features.Features) error {
	if len(cla.CLAStatusContext) == 0 {
		glog.Fatalf("No --cla-status-context flag set with cla munger.")
	}

	cla.pinger = c.NewPinger(claNagNotifyName).
		SetDescription(cncfclaNotFoundMessage).SetTimePeriod(timePeriod).SetMaxCount(maxPings)

	return nil
}
Esempio n. 2
0
func TestCLAMunger(t *testing.T) {
	runtime.GOMAXPROCS(runtime.NumCPU())

	tests := []struct {
		name        string
		issue       *github.Issue
		status      *github.CombinedStatus
		mustHave    []string
		mustNotHave []string
	}{
		{
			name:  "CLA status success should add cncf/cla:yes label and remove cncf/cla:no label",
			issue: github_test.Issue("user1", 1, []string{cncfClaNoLabel}, true),
			status: &github.CombinedStatus{
				Statuses: []github.RepoStatus{
					{
						Context: stringPtr(claContext),
						State:   stringPtr(contextSuccess),
					},
				},
			},
			mustHave:    []string{cncfClaYesLabel},
			mustNotHave: []string{cncfClaNoLabel},
		},
		{
			name:  "CLA status failure should add cncf/cla:no label and remove cncf/cla:yes label",
			issue: github_test.Issue("user1", 1, []string{cncfClaYesLabel}, true),
			status: &github.CombinedStatus{
				Statuses: []github.RepoStatus{
					{
						Context: stringPtr(claContext),
						State:   stringPtr(contextFailure),
					},
				},
			},
			mustHave:    []string{cncfClaNoLabel},
			mustNotHave: []string{cncfClaYesLabel},
		},
		{
			name:  "CLA status error should apply cncf/cla:no label.",
			issue: github_test.Issue("user1", 1, []string{}, true),
			status: &github.CombinedStatus{
				Statuses: []github.RepoStatus{
					{
						Context: stringPtr(claContext),
						State:   stringPtr(contextError),
					},
				},
			},
			mustHave:    []string{cncfClaNoLabel},
			mustNotHave: []string{cncfClaYesLabel},
		},
		{
			name:  "CLA status pending should not apply labels.",
			issue: github_test.Issue("user1", 1, []string{}, true),
			status: &github.CombinedStatus{
				Statuses: []github.RepoStatus{
					{
						Context: stringPtr(claContext),
						State:   stringPtr(contextPending),
					},
				},
			},
			mustHave:    []string{},
			mustNotHave: []string{cncfClaYesLabel, cncfClaNoLabel},
		},
	}

	for testNum, test := range tests {
		pr := ValidPR()
		pr.Head = &github.PullRequestBranch{}
		pr.Head.SHA = stringPtr("0")
		client, server, mux := github_test.InitServer(t, test.issue, pr, nil, nil, nil, nil, nil)
		setUpMockFunctions(mux, t, test.issue)

		path := fmt.Sprintf("/repos/o/r/commits/%s/status", *pr.Head.SHA)
		mux.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) {
			w.WriteHeader(http.StatusOK)
			out := test.status
			data, err := json.Marshal(out)
			if err != nil {
				t.Errorf("Unexpected error: %v", err)
			}
			w.Write(data)
		})

		config := &github_util.Config{}
		config.Org = "o"
		config.Project = "r"
		config.SetClient(client)

		cla := ClaMunger{
			CLAStatusContext: claContext,
			pinger:           c.NewPinger("[fake-ping]").SetDescription(""),
		}
		obj, err := config.GetObject(*test.issue.Number)
		if err != nil {
			t.Fatalf("%v", err)
		}
		cla.Munge(obj)

		for _, lab := range test.mustHave {
			if !obj.HasLabel(lab) {
				t.Errorf("%s:%d: Did not find label %q, labels: %v", test.name, testNum, lab, obj.Issue.Labels)
			}
		}
		for _, lab := range test.mustNotHave {
			if obj.HasLabel(lab) {
				t.Errorf("%s:%d: Found label %q and should not have, labels: %v", test.name, testNum, lab, obj.Issue.Labels)
			}
		}
		server.Close()
	}
}
Esempio n. 3
0
	"github.com/google/go-github/github"
	"github.com/spf13/cobra"
	"k8s.io/contrib/mungegithub/features"
	mgh "k8s.io/contrib/mungegithub/github"
	c "k8s.io/contrib/mungegithub/mungers/matchers/comment"
	"k8s.io/contrib/mungegithub/mungers/mungerutil"
)

const (
	flakeNagNotifyName = "FLAKE-PING"
	// defaultTimePeriod is priority/P1 (to get a human to prioritize)
	defaultTimePeriod = 4 * 24 * time.Hour
)

var (
	pinger = c.NewPinger(flakeNagNotifyName).
		SetDescription("This flaky-test issue would love to have more attention.")
	// Only include priorities that you care about. Others won't be pinged
	timePeriods = map[string]time.Duration{
		"priority/P0": 2 * 24 * time.Hour,
		"priority/P1": 8 * 24 * time.Hour,
		"priority/P2": time.Duration(1<<63 - 1),
		"priority/P3": time.Duration(1<<63 - 1),
	}
)

// NagFlakeIssues pings assignees on flaky-test issues
type NagFlakeIssues struct{}

var _ Munger = &NagFlakeIssues{}