Пример #1
0
func TestListCommits(t *testing.T) {
	Setup()
	defer Teardown()

	// commits for repo_id = 1
	commits, err := database.ListCommits(1, "master")
	if err != nil {
		t.Error(err)
	}

	// verify commit count
	if len(commits) != 2 {
		t.Errorf("Expected %d commits in database, got %d", 2, len(commits))
		return
	}

	// get the first user in the list and verify
	// fields are being populated correctly
	commit := commits[1] // TODO something strange is happening with ordering here

	if commit.ID != 1 {
		t.Errorf("Expected ID %d, got %d", 1, commit.ID)
	}

	if commit.Status != "Success" {
		t.Errorf("Expected Status %s, got %s", "Success", commit.Status)
	}

	if commit.Hash != "4f4c4594be6d6ddbc1c0dd521334f7ecba92b608" {
		t.Errorf("Expected Hash %s, got %s", "4f4c4594be6d6ddbc1c0dd521334f7ecba92b608", commit.Hash)
	}

	if commit.Branch != "master" {
		t.Errorf("Expected Branch %s, got %s", "master", commit.Branch)
	}

	if commit.Author != "*****@*****.**" {
		t.Errorf("Expected Author %s, got %s", "master", commit.Author)
	}

	if commit.Message != "commit message" {
		t.Errorf("Expected Message %s, got %s", "master", commit.Message)
	}

	if commit.Gravatar != "8c58a0be77ee441bb8f8595b7f1b4e87" {
		t.Errorf("Expected Gravatar %s, got %s", "8c58a0be77ee441bb8f8595b7f1b4e87", commit.Gravatar)
	}
}
Пример #2
0
// Display a Repository dashboard.
func RepoDashboard(w http.ResponseWriter, r *http.Request, u *User, repo *Repo) error {
	branch := r.FormValue(":branch")

	// get a list of all branches
	branches, err := database.ListBranches(repo.ID)
	if err != nil {
		return err
	}

	// if no branch is provided then we'll
	// want to use a default value.
	if len(branch) == 0 {
		branch = repo.DefaultBranch()
	}

	// get a list of recent commits for the
	// repository and specific branch
	commits, err := database.ListCommits(repo.ID, branch)
	if err != nil {
		return err
	}

	// get a token that can be exchanged with the
	// websocket handler to authorize listening
	// for a stream of changes for this repository
	token := channel.Create(repo.Slug)

	data := struct {
		User     *User
		Repo     *Repo
		Branches []*Commit
		Commits  []*Commit
		Branch   string
		Token    string
	}{u, repo, branches, commits, branch, token}

	return RenderTemplate(w, "repo_dashboard.html", &data)
}