8000 Improve push update options by lunny · Pull Request #10105 · go-gitea/gitea · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Improve push update options #10105

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

Merged
merged 6 commits into from
Feb 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,6 @@ issues:
- linters:
- misspell
text: '`Unknwon` is a misspelling of `Unknown`'
- path: models/update.go
linters:
- unused
23 changes: 8 additions & 15 deletions modules/repofiles/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"encoding/json"
"fmt"
"html"
"strings"

"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/git"
Expand Down Expand Up @@ -151,12 +150,9 @@ func UpdateIssuesCommit(doer *models.User, repo *models.Repository, commits []*r

// CommitRepoActionOptions represent options of a new commit action.
type CommitRepoActionOptions struct {
PusherName string
PushUpdateOptions

RepoOwnerID int64
RepoName string
RefFullName string
OldCommitID string
NewCommitID string
Commits *repository.PushCommits
}

Expand Down Expand Up @@ -192,7 +188,7 @@ func CommitRepoAction(optsList ...*CommitRepoActionOptions) error {
refName := git.RefEndName(opts.RefFullName)

// Change default branch and empty status only if pushed ref is non-empty branch.
if repo.IsEmpty && opts.NewCommitID != git.EmptySHA && strings.HasPrefix(opts.RefFullName, git.BranchPrefix) {
if repo.IsEmpty && opts.IsBranch() && !opts.IsDelRef() {
repo.DefaultBranch = refName
repo.IsEmpty = false
if refName != "master" {
Expand All @@ -210,24 +206,21 @@ func CommitRepoAction(optsList ...*CommitRepoActionOptions) error {
}
}

isNewBranch := false
opType := models.ActionCommitRepo

// Check it's tag push or branch.
if strings.HasPrefix(opts.RefFullName, git.TagPrefix) {
if opts.IsTag() {
opType = models.ActionPushTag
if opts.NewCommitID == git.EmptySHA {
if opts.IsDelRef() {
opType = models.ActionDeleteTag
}
opts.Commits = &repository.PushCommits{}
} else if opts.NewCommitID == git.EmptySHA {
} else if opts.IsDelRef() {
opType = models.ActionDeleteBranch
opts.Commits = &repository.PushCommits{}
} else {
// if not the first commit, set the compare URL.
if opts.OldCommitID == git.EmptySHA {
isNewBranch = true
} else {
if !opts.IsNewRef() {
opts.Commits.CompareURL = repo.ComposeCompareURL(opts.OldCommitID, opts.NewCommitID)
}

Expand Down Expand Up @@ -259,7 +252,7 @@ func CommitRepoAction(optsList ...*CommitRepoActionOptions) error {
var isHookEventPush = true
switch opType {
case models.ActionCommitRepo: // Push
if isNewBranch {
if opts.IsNewBranch() {
notification.NotifyCreateRef(pusher, repo, "branch", opts.RefFullName)
}
case models.ActionDeleteBranch: // Delete Branch
Expand Down
38 changes: 23 additions & 15 deletions modules/repofiles/action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ func TestCommitRepoAction(t *testing.T) {
userID: 2,
repositoryID: 16,
commitRepoActionOptions: CommitRepoActionOptions{
RefFullName: "refName",
OldCommitID: "oldCommitID",
NewCommitID: "newCommitID",
PushUpdateOptions: PushUpdateOptions{
RefFullName: "refName",
OldCommitID: "oldCommitID",
NewCommitID: "newCommitID",
},
Commits: &repository.PushCommits{
Commits: []*repository.PushCommit{
{
Expand Down Expand Up @@ -66,10 +68,12 @@ func TestCommitRepoAction(t *testing.T) {
userID: 2,
repositoryID: 1,
commitRepoActionOptions: CommitRepoActionOptions{
RefFullName: git.TagPrefix + "v1.1",
OldCommitID: git.EmptySHA,
NewCommitID: "newCommitID",
Commits: &repository.PushCommits{},
PushUpdateOptions: PushUpdateOptions{
RefFullName: git.TagPrefix + "v1.1",
OldCommitID: git.EmptySHA,
NewCommitID: "newCommitID",
},
Commits: &repository.PushCommits{},
},
action: models.Action{
OpType: models.ActionPushTag,
Expand All @@ -80,10 +84,12 @@ func TestCommitRepoAction(t *testing.T) {
userID: 2,
repositoryID: 1,
commitRepoActionOptions: CommitRepoActionOptions{
RefFullName: git.TagPrefix + "v1.1",
OldCommitID: "oldCommitID",
NewCommitID: git.EmptySHA,
Commits: &repository.PushCommits{},
PushUpdateOptions: PushUpdateOptions{
RefFullName: git.TagPrefix + "v1.1",
OldCommitID: "oldCommitID",
NewCommitID: git.EmptySHA,
},
Commits: &repository.PushCommits{},
},
action: models.Action{
OpType: models.ActionDeleteTag,
Expand All @@ -94,10 +100,12 @@ func TestCommitRepoAction(t *testing.T) {
userID: 2,
repositoryID: 1,
commitRepoActionOptions: CommitRepoActionOptions{
RefFullName: git.BranchPrefix + "feature/1",
OldCommitID: "oldCommitID",
NewCommitID: git.EmptySHA,
Commits: &repository.PushCommits{},
PushUpdateOptions: PushUpdateOptions{
RefFullName: git.BranchPrefix + "feature/1",
OldCommitID: "oldCommitID",
NewCommitID: git.EmptySHA,
},
Commits: &repository.PushCommits{},
},
action: models.Action{
OpType: models.ActionDeleteBranch,
Expand Down
Loading
0