Esempio n. 1
0
func NonWhitelistUserPR() *github.PullRequest {
	return github_test.PullRequest(noWhitelistUser, false, true, true)
}
Esempio n. 2
0
func UnMergeablePR() *github.PullRequest {
	return github_test.PullRequest(whitelistUser, false, true, false)
}
Esempio n. 3
0
func UndeterminedMergeablePR() *github.PullRequest {
	return github_test.PullRequest(whitelistUser, false, false, false)
}
Esempio n. 4
0
func ValidPR() *github.PullRequest {
	return github_test.PullRequest(whitelistUser, false, true, true)
}
Esempio n. 5
0
func UndeterminedMergeablePR() *github.PullRequest {
	return github_test.PullRequest(someUserName, false, false, false)
}
Esempio n. 6
0
func UnMergeablePR() *github.PullRequest {
	return github_test.PullRequest(someUserName, false, true, false)
}
Esempio n. 7
0
func ValidPR() *github.PullRequest {
	return github_test.PullRequest(someUserName, false, true, true)
}
Esempio n. 8
0
func TestAssignFixes(t *testing.T) {
	runtime.GOMAXPROCS(runtime.NumCPU())

	tests := []struct {
		name       string
		assignee   string
		pr         *github.PullRequest
		prIssue    *github.Issue
		prBody     string
		fixesIssue *github.Issue
	}{
		{
			name:       "fixes an issue",
			assignee:   "dev45",
			pr:         github_test.PullRequest("dev45", false, true, true),
			prIssue:    github_test.Issue("fred", 7779, []string{}, true),
			prBody:     "does stuff and fixes #8889.",
			fixesIssue: github_test.Issue("jill", 8889, []string{}, true),
		},
	}
	for _, test := range tests {
		test.prIssue.Body = &test.prBody
		client, server, mux := github_test.InitServer(t, test.prIssue, test.pr, nil, nil, nil, nil)
		path := fmt.Sprintf("/repos/o/r/issues/%d", *test.fixesIssue.Number)
		mux.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) {
			data, err := json.Marshal(test.fixesIssue)
			if err != nil {
				t.Errorf("%v", err)
			}
			if r.Method != "PATCH" && r.Method != "GET" {
				t.Errorf("Unexpected method: expected: GET/PATCH got: %s", r.Method)
			}
			if r.Method == "PATCH" {
				body, _ := ioutil.ReadAll(r.Body)

				type IssuePatch struct {
					Assignee string
				}
				var ip IssuePatch
				err := json.Unmarshal(body, &ip)
				if err != nil {
					fmt.Println("error:", err)
				}
				if ip.Assignee != test.assignee {
					t.Errorf("Patching the incorrect Assignee %v instead of %v", ip.Assignee, test.assignee)
				}
			}
			w.WriteHeader(http.StatusOK)
			w.Write(data)
		})

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

		c := AssignFixesMunger{}
		err := c.Initialize(config, nil)
		if err != nil {
			t.Fatalf("%v", err)
		}

		err = c.EachLoop()
		if err != nil {
			t.Fatalf("%v", err)
		}

		obj, err := config.GetObject(*test.prIssue.Number)
		if err != nil {
			t.Fatalf("%v", err)
		}

		c.Munge(obj)
		server.Close()
	}
}