forked from go-gitea/gitea
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add branch overiew page (go-gitea#2108)
* Add branch overiew page * fix changed method name on sub menu * remove unused code
- Loading branch information
Showing
21 changed files
with
700 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// Copyright 2017 The Gitea Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package integrations | ||
|
||
import ( | ||
"net/http" | ||
"net/url" | ||
"testing" | ||
|
||
"github.com/PuerkitoBio/goquery" | ||
"github.com/Unknwon/i18n" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestViewBranches(t *testing.T) { | ||
prepareTestEnv(t) | ||
|
||
req := NewRequest(t, "GET", "/user2/repo1/branches") | ||
resp := MakeRequest(t, req, http.StatusOK) | ||
|
||
htmlDoc := NewHTMLParser(t, resp.Body) | ||
_, exists := htmlDoc.doc.Find(".delete-branch-button").Attr("data-url") | ||
assert.False(t, exists, "The template has changed") | ||
} | ||
|
||
func TestDeleteBranch(t *testing.T) { | ||
prepareTestEnv(t) | ||
|
||
deleteBranch(t) | ||
} | ||
|
||
func TestUndoDeleteBranch(t *testing.T) { | ||
prepareTestEnv(t) | ||
|
||
deleteBranch(t) | ||
htmlDoc, name := branchAction(t, ".undo-button") | ||
assert.Contains(t, | ||
htmlDoc.doc.Find(".ui.positive.message").Text(), | ||
i18n.Tr("en", "repo.branch.restore_success", name), | ||
) | ||
} | ||
|
||
func deleteBranch(t *testing.T) { | ||
htmlDoc, name := branchAction(t, ".delete-branch-button") | ||
assert.Contains(t, | ||
htmlDoc.doc.Find(".ui.positive.message").Text(), | ||
i18n.Tr("en", "repo.branch.deletion_success", name), | ||
) | ||
} | ||
|
||
func branchAction(t *testing.T, button string) (*HTMLDoc, string) { | ||
session := loginUser(t, "user2") | ||
req := NewRequest(t, "GET", "/user2/repo1/branches") | ||
resp := session.MakeRequest(t, req, http.StatusOK) | ||
|
||
htmlDoc := NewHTMLParser(t, resp.Body) | ||
link, exists := htmlDoc.doc.Find(button).Attr("data-url") | ||
assert.True(t, exists, "The template has changed") | ||
|
||
htmlDoc = NewHTMLParser(t, resp.Body) | ||
req = NewRequestWithValues(t, "POST", link, map[string]string{ | ||
"_csrf": getCsrf(htmlDoc.doc), | ||
}) | ||
resp = session.MakeRequest(t, req, http.StatusOK) | ||
|
||
url, err := url.Parse(link) | ||
assert.NoError(t, err) | ||
req = NewRequest(t, "GET", "/user2/repo1/branches") | ||
resp = session.MakeRequest(t, req, http.StatusOK) | ||
|
||
return NewHTMLParser(t, resp.Body), url.Query()["name"][0] | ||
} | ||
|
||
func getCsrf(doc *goquery.Document) string { | ||
csrf, _ := doc.Find("meta[name=\"_csrf\"]").Attr("content") | ||
return csrf | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// Copyright 2017 The Gitea Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package models | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
var firstBranch = DeletedBranch{ | ||
ID: 1, | ||
Name: "foo", | ||
Commit: "1213212312313213213132131", | ||
DeletedByID: int64(1), | ||
} | ||
|
||
var secondBranch = DeletedBranch{ | ||
ID: 2, | ||
Name: "bar", | ||
Commit: "5655464564554545466464655", | ||
DeletedByID: int64(99), | ||
} | ||
|
||
func TestAddDeletedBranch(t *testing.T) { | ||
assert.NoError(t, PrepareTestDatabase()) | ||
repo := AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository) | ||
assert.NoError(t, repo.AddDeletedBranch(firstBranch.Name, firstBranch.Commit, firstBranch.DeletedByID)) | ||
assert.Error(t, repo.AddDeletedBranch(firstBranch.Name, firstBranch.Commit, firstBranch.DeletedByID)) | ||
assert.NoError(t, repo.AddDeletedBranch(secondBranch.Name, secondBranch.Commit, secondBranch.DeletedByID)) | ||
} | ||
func TestGetDeletedBranches(t *testing.T) { | ||
assert.NoError(t, PrepareTestDatabase()) | ||
AssertExistsAndLoadBean(t, &DeletedBranch{ID: 1}) | ||
repo := AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository) | ||
|
||
branches, err := repo.GetDeletedBranches() | ||
assert.NoError(t, err) | ||
assert.Len(t, branches, 2) | ||
} | ||
|
||
func TestGetDeletedBranch(t *testing.T) { | ||
assert.NoError(t, PrepareTestDatabase()) | ||
assert.NotNil(t, getDeletedBranch(t, firstBranch)) | ||
} | ||
|
||
func TestDeletedBranchLoadUser(t *testing.T) { | ||
assert.NoError(t, PrepareTestDatabase()) | ||
branch := getDeletedBranch(t, firstBranch) | ||
assert.Nil(t, branch.DeletedBy) | ||
branch.LoadUser() | ||
assert.NotNil(t, branch.DeletedBy) | ||
assert.Equal(t, "user1", branch.DeletedBy.Name) | ||
|
||
branch = getDeletedBranch(t, secondBranch) | ||
assert.Nil(t, branch.DeletedBy) | ||
branch.LoadUser() | ||
assert.NotNil(t, branch.DeletedBy) | ||
assert.Equal(t, "Ghost", branch.DeletedBy.Name) | ||
} | ||
|
||
func TestRemoveDeletedBranch(t *testing.T) { | ||
assert.NoError(t, PrepareTestDatabase()) | ||
|
||
branch := DeletedBranch{ID: 1} | ||
AssertExistsAndLoadBean(t, &branch) | ||
repo := AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository) | ||
|
||
err := repo.RemoveDeletedBranch(1) | ||
assert.NoError(t, err) | ||
AssertNotExistsBean(t, &branch) | ||
AssertExistsAndLoadBean(t, &DeletedBranch{ID: 2}) | ||
} | ||
|
||
func getDeletedBranch(t *testing.T, branch DeletedBranch) *DeletedBranch { | ||
AssertExistsAndLoadBean(t, &DeletedBranch{ID: 1}) | ||
repo := AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository) | ||
|
||
deletedBranch, err := repo.GetDeletedBranchByID(branch.ID) | ||
assert.NoError(t, err) | ||
assert.Equal(t, branch.ID, deletedBranch.ID) | ||
assert.Equal(t, branch.Name, deletedBranch.Name) | ||
assert.Equal(t, branch.Commit, deletedBranch.Commit) | ||
assert.Equal(t, branch.DeletedByID, deletedBranch.DeletedByID) | ||
|
||
return deletedBranch | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright 2017 The Gitea Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package migrations | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/go-xorm/xorm" | ||
) | ||
|
||
func addDeletedBranch(x *xorm.Engine) (err error) { | ||
// DeletedBranch contains the deleted branch information | ||
type DeletedBranch struct { | ||
ID int64 `xorm:"pk autoincr"` | ||
RepoID int64 `xorm:"UNIQUE(s) INDEX NOT NULL"` | ||
Name string `xorm:"UNIQUE(s) NOT NULL"` | ||
Commit string `xorm:"UNIQUE(s) NOT NULL"` | ||
DeletedByID int64 `xorm:"INDEX NOT NULL"` | ||
DeletedUnix int64 `xorm:"INDEX"` | ||
} | ||
|
||
if err = x.Sync2(new(DeletedBranch)); err != nil { | ||
return fmt.Errorf("Sync2: %v", err) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.