-
-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Branches management UI #2464
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Branches management UI #2464
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
---|---|---|
@@ -1,32 +1,144 @@ | ||
// Copyright 2014 The Gogs Authors. All rights reserved. | ||
// 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 repo | ||
|
||
import ( | ||
"code.gitea.io/gitea/modules/base" | ||
"time" | ||
|
||
"code.gitea.io/git" | ||
"code.gitea.io/gitea/modules/context" | ||
"code.gitea.io/gitea/modules/log" | ||
) | ||
|
||
const ( | ||
tplBranch base.TplName = "repo/branch" | ||
tplBranchOverview = "repo/branches/overview" | ||
tplBranchAll = "repo/branches/all" | ||
) | ||
|
||
// Branch branch information on UI | ||
type Branch struct { | ||
Name string | ||
Commit *git.Commit | ||
IsProtected bool | ||
} | ||
|
||
func loadBranches(ctx *context.Context) []*Branch { | ||
rawBranches, err := ctx.Repo.Repository.GetBranches() | ||
if err != nil { | ||
ctx.Handle(500, "GetBranches", err) | ||
return nil | ||
} | ||
|
||
protectBranches, err := ctx.Repo.Repository.GetProtectedBranches() | ||
if err != nil { | ||
ctx.Handle(500, "GetProtectedBranches", err) | ||
return nil | ||
} | ||
|
||
branches := make([]*Branch, len(rawBranches)) | ||
for i := range rawBranches { | ||
commit, err := rawBranches[i].GetCommit() | ||
if err != nil { | ||
ctx.Handle(500, "GetCommit", err) | ||
return nil | ||
} | ||
|
||
branches[i] = &Branch{ | ||
Name: rawBranches[i].Name, | ||
Commit: commit, | ||
} | ||
|
||
for j := range protectBranches { | ||
if branches[i].Name == protectBranches[j].BranchName { | ||
branches[i].IsProtected = true | ||
break | ||
} | ||
} | ||
} | ||
|
||
ctx.Data["AllowPullRequest"] = ctx.Repo.Repository.AllowsPulls() | ||
return branches | ||
} | ||
|
||
// Branches render repository branch page | ||
func Branches(ctx *context.Context) { | ||
ctx.Data["Title"] = "Branches" | ||
ctx.Data["IsRepoToolbarBranches"] = true | ||
ctx.Data["Title"] = ctx.Tr("repo.git_branches") | ||
ctx.Data["PageIsBranchesOverview"] = true | ||
|
||
brs, err := ctx.Repo.GitRepo.GetBranches() | ||
if err != nil { | ||
ctx.Handle(500, "repo.Branches(GetBranches)", err) | ||
branches := loadBranches(ctx) | ||
if ctx.Written() { | ||
return | ||
} | ||
|
||
now := time.Now() | ||
activeBranches := make([]*Branch, 0, 3) | ||
staleBranches := make([]*Branch, 0, 3) | ||
for i := range branches { | ||
switch { | ||
case branches[i].Name == ctx.Repo.BranchName: | ||
ctx.Data["DefaultBranch"] = branches[i] | ||
case branches[i].Commit.Committer.When.Add(30 * 24 * time.Hour).After(now): // 30 days | ||
activeBranches = append(activeBranches, branches[i]) | ||
case branches[i].Commit.Committer.When.Add(3 * 30 * 24 * time.Hour).Before(now): // 90 days | ||
staleBranches = append(staleBranches, branches[i]) | ||
} | ||
} | ||
|
||
ctx.Data["ActiveBranches"] = activeBranches | ||
ctx.Data["StaleBranches"] = staleBranches | ||
ctx.HTML(200, tplBranchOverview) | ||
} | ||
|
||
// AllBranches all branches UI | ||
func AllBranches(ctx *context.Context) { | ||
ctx.Data["Title"] = ctx.Tr("repo.git_branches") | ||
ctx.Data["PageIsBranchesAll"] = true | ||
|
||
branches := loadBranches(ctx) | ||
if ctx.Written() { | ||
return | ||
} else if len(brs) == 0 { | ||
ctx.Handle(404, "repo.Branches(GetBranches)", nil) | ||
} | ||
ctx.Data["Branches"] = branches | ||
|
||
ctx.HTML(200, tplBranchAll) | ||
} | ||
|
||
// DeleteBranchPost executes branch deletation operation | ||
func DeleteBranchPost(ctx *context.Context) { | ||
branchName := ctx.Params("*") | ||
commitID := ctx.Query("commit") | ||
|
||
defer func() { | ||
redirectTo := ctx.Query("redirect_to") | ||
if len(redirectTo) == 0 { | ||
redirectTo = ctx.Repo.RepoLink | ||
} | ||
ctx.Redirect(redirectTo) | ||
}() | ||
|
||
if !ctx.Repo.GitRepo.IsBranchExist(branchName) { | ||
return | ||
} | ||
if len(commitID) > 0 { | ||
branchCommitID, err := ctx.Repo.GitRepo.GetBranchCommitID(branchName) | ||
if err != nil { | ||
log.Error(2, "GetBranchCommitID: %v", err) | ||
return | ||
} | ||
|
||
ctx.Data["Branches"] = brs | ||
ctx.HTML(200, tplBranch) | ||
if branchCommitID != commitID { | ||
ctx.Flash.Error(ctx.Tr("repo.pulls.delete_branch_has_new_commits")) | ||
return | ||
} | ||
} | ||
|
||
if err := ctx.Repo.GitRepo.DeleteBranch(branchName, git.DeleteBranchOptions{ | ||
Force: true, | ||
}); err != nil { | ||
log.Error(2, "DeleteBranch '%s': %v", branchName, err) | ||
return | ||
} | ||
} |
This file contains hidden or 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 hidden or 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,31 @@ | ||
{{template "base/head" .}} | ||
<div class="repository branches all"> | ||
{{template "repo/header" .}} | ||
<div class="ui container"> | ||
<div class="navbar"> | ||
{{template "repo/branches/navbar" .}} | ||
</div> | ||
<div class="ui top attached header"> | ||
{{.i18n.Tr "repo.branches.all"}} | ||
</div> | ||
<div class="ui attached segment list"> | ||
{{range .Branches}} | ||
<div class="item ui grid"> | ||
<div class="ui eleven wide column"> | ||
{{if .IsProtected}}<i class="octicon octicon-shield"></i> {{end}}<a class="markdown" href="{{$.RepoLink}}/src/{{.Name}}"><code>{{.Name}}</code></a> | ||
{{$timeSince := TimeSince .Commit.Committer.When $.Lang}} | ||
<span class="ui text light grey">{{$.i18n.Tr "repo.branches.updated_by" $timeSince .Commit.Committer.Name | Safe}}</span> | ||
</div> | ||
<div class="ui four wide column"> | ||
{{if and (and (eq $.BranchName .Name) $.IsRepositoryAdmin) (not $.Repository.IsMirror)}} | ||
<a class="ui basic blue button" href="{{$.RepoLink}}/settings/branches">{{$.i18n.Tr "repo.branches.change_default_branch"}}</a> | ||
{{else if and $.IsRepositoryWriter $.AllowPullRequest}} | ||
<a class="ui basic button" href="{{$.RepoLink}}/compare/{{$.BranchName}}...{{.Name}}"><i class="octicon octicon-git-pull-request"></i> {{$.i18n.Tr "repo.pulls.new"}}</a> | ||
{{end}} | ||
</div> | ||
</div> | ||
{{end}} | ||
</div> | ||
</div> | ||
</div> | ||
{{template "base/footer" .}} |
This file contains hidden or 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,4 @@ | ||
<div class="ui compact small menu"> | ||
<a class="{{if .PageIsBranchesOverview}}active{{end}} item" href="{{.RepoLink}}/branches">{{.i18n.Tr "repo.branches.overview"}}</a> | ||
<a class="{{if .PageIsBranchesAll}}active{{end}} item" href="{{.RepoLink}}/branches/all">{{.i18n.Tr "repo.branches.all"}}</a> | ||
</div> |
This file contains hidden or 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,71 @@ | ||
{{template "base/head" .}} | ||
<div class="repository branches overview"> | ||
{{template "repo/header" .}} | ||
<div class="ui container"> | ||
<div class="navbar"> | ||
{{template "repo/branches/navbar" .}} | ||
</div> | ||
<div class="ui top attached header"> | ||
{{.i18n.Tr "repo.default_branch"}} | ||
</div> | ||
<div class="ui attached segment list"> | ||
<div class="item ui grid"> | ||
<div class="ui eleven wide column"> | ||
{{if .DefaultBranch.IsProtected}}<i class="octicon octicon-shield"></i> {{end}}<a class="markdown" href="{{$.RepoLink}}/src/{{.DefaultBranch.Name}}"><code>{{.DefaultBranch.Name}}</code></a> | ||
{{$timeSince := TimeSince .DefaultBranch.Commit.Committer.When $.Lang}} | ||
<span class="ui text light grey">{{$.i18n.Tr "repo.branches.updated_by" $timeSince .DefaultBranch.Commit.Committer.Name | Safe}}</span> | ||
</div> | ||
{{if and $.IsRepositoryAdmin (not $.Repository.IsMirror)}} | ||
<div class="ui four wide column"> | ||
<a class="ui basic blue button" href="{{$.RepoLink}}/settings/branches">{{.i18n.Tr "repo.branches.change_default_branch"}}</a> | ||
</div> | ||
{{end}} | ||
</div> | ||
</div> | ||
|
||
{{if .ActiveBranches}} | ||
<div class="ui top attached header"> | ||
{{.i18n.Tr "repo.branches.active_branches"}} | ||
</div> | ||
<div class="ui attached segment list"> | ||
{{range .ActiveBranches}} | ||
<div class="item ui grid"> | ||
<div class="ui eleven wide column"> | ||
{{if .IsProtected}}<i class="octicon octicon-shield"></i> {{end}}<a class="markdown" href="{{$.RepoLink}}/src/{{.Name}}"><code>{{.Name}}</code></a> | ||
{{$timeSince := TimeSince .Commit.Committer.When $.Lang}} | ||
<span class="ui text light grey">{{$.i18n.Tr "repo.branches.updated_by" $timeSince .Commit.Committer.Name | Safe}}</span> | ||
</div> | ||
{{if and $.IsRepositoryWriter $.AllowPullRequest}} | ||
<div class="ui four wide column"> | ||
<a class="ui basic button" href="{{$.RepoLink}}/compare/{{$.BranchName}}...{{.Name}}"><i class="octicon octicon-git-pull-request"></i> {{$.i18n.Tr "repo.pulls.new"}}</a> | ||
</div> | ||
{{end}} | ||
</div> | ||
{{end}} | ||
</div> | ||
{{end}} | ||
|
||
{{if .StaleBranches}} | ||
<div class="ui top attached header"> | ||
{{.i18n.Tr "repo.branches.stale_branches"}} | ||
</div> | ||
<div class="ui attached segment list"> | ||
{{range .StaleBranches}} | ||
<div class="item ui grid"> | ||
<div class="ui eleven wide column"> | ||
{{if .IsProtected}}<i class="octicon octicon-shield"></i> {{end}}<a class="markdown" href="{{$.RepoLink}}/src/{{.Name}}"><code>{{.Name}}</code></a> | ||
{{$timeSince := TimeSince .Commit.Committer.When $.Lang}} | ||
<span class="ui text light grey">{{$.i18n.Tr "repo.branches.updated_by" $timeSince .Commit.Committer.Name | Safe}}</span> | ||
</div> | ||
{{if and $.IsRepositoryWriter $.AllowPullRequest}} | ||
<div class="ui four wide column"> | ||
<a class="ui basic button" href="{{$.RepoLink}}/compare/{{$.BranchName}}...{{.Name}}"><i class="octicon octicon-git-pull-request"></i> {{$.i18n.Tr "repo.pulls.new"}}</a> | ||
</div> | ||
{{end}} | ||
</div> | ||
{{end}} | ||
</div> | ||
{{end}} | ||
</div> | ||
</div> | ||
{{template "base/footer" .}} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this group needs
context.CheckUnit(models.UnitTypeCode)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.