Skip to content

Commit

Permalink
fix go-gitea#8576 create pull request on current repository by default
Browse files Browse the repository at this point in the history
  • Loading branch information
blueworrybear committed Oct 24, 2019
1 parent 13bf498 commit 74a4d01
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 46 deletions.
28 changes: 28 additions & 0 deletions routers/repo/compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,12 +339,40 @@ func PrepareCompareDiff(
return false
}

// parseBaseRepoInfo parse base repository if current repo is forked.
// The "base" here means the repository where current repo forks from,
// not the repository fetch from current URL.
func parseBaseRepoInfo(ctx *context.Context, repo *models.Repository) error {
if !repo.IsFork {
return nil
}
if err := repo.GetBaseRepo(); err != nil {
return err
}
if err := repo.BaseRepo.GetOwnerName(); err != nil {
return err
}
baseGitRepo, err := git.OpenRepository(models.RepoPath(repo.BaseRepo.OwnerName, repo.BaseRepo.Name))
if err != nil {
return err
}
ctx.Data["BaseRepoBranches"], err = baseGitRepo.GetBranches()
if err != nil {
return err
}
return nil
}

// CompareDiff show different from one commit to another commit
func CompareDiff(ctx *context.Context) {
headUser, headRepo, headGitRepo, compareInfo, baseBranch, headBranch := ParseCompareInfo(ctx)
if ctx.Written() {
return
}
if err := parseBaseRepoInfo(ctx, headRepo); err != nil {
ctx.ServerError("parseBaseRepoInfo", err)
return
}

nothingToCompare := PrepareCompareDiff(ctx, headUser, headRepo, headGitRepo, compareInfo, baseBranch, headBranch)
if ctx.Written() {
Expand Down
44 changes: 0 additions & 44 deletions services/release/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/process"
"code.gitea.io/gitea/modules/setting"
api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/timeutil"
)
Expand All @@ -38,49 +37,6 @@ func createTag(gitRepo *git.Repository, rel *models.Release) error {
return err
}
rel.LowerTagName = strings.ToLower(rel.TagName)

// Prepare Webhook
if err := rel.LoadAttributes(); err != nil {
log.Error("LoadAttributes: %v", err)
} else {

defer func() {
go models.HookQueue.Add(rel.Repo.ID)
}()

var shaSum string
mode, _ := models.AccessLevel(rel.Publisher, rel.Repo)
apiRepo := rel.Repo.APIFormat(mode)
apiPusher := rel.Publisher.APIFormat()
shaSum, err = gitRepo.GetTagCommitID(rel.TagName)
if err != nil {
log.Error("GetTagCommitID[%s]: %v", rel.TagName, err)
}

// Tag Create
if err = models.PrepareWebhooks(rel.Repo, models.HookEventCreate, &api.CreatePayload{
Ref: git.TagPrefix + rel.TagName,
Sha: shaSum,
RefType: "tag",
Repo: apiRepo,
Sender: apiPusher,
}); err != nil {
return fmt.Errorf("PrepareWebhooks: %v", err)
}
// Tag Push
if err = models.PrepareWebhooks(rel.Repo, models.HookEventPush, &api.PushPayload{
Ref: git.TagPrefix + rel.TagName,
Before: git.EmptySHA,
After: shaSum,
CompareURL: setting.AppURL,
Commits: make([]*api.PayloadCommit, 0),
Repo: apiRepo,
Pusher: apiPusher,
Sender: apiPusher,
}); err != nil {
return fmt.Errorf("PrepareWebhooks: %v", err)
}
}
}
commit, err := gitRepo.GetTagCommit(rel.TagName)
if err != nil {
Expand Down
7 changes: 6 additions & 1 deletion templates/repo/diff/compare.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@
{{range .Branches}}
<div class="item {{if eq $.BaseBranch .}}selected{{end}}" data-url="{{$.RepoLink}}/compare/{{EscapePound .}}...{{if not $.PullRequestCtx.SameRepo}}{{$.HeadUser.Name}}:{{end}}{{EscapePound $.HeadBranch}}">{{$.BaseName}}:{{.}}</div>
{{end}}
{{if .Repository.IsFork}}
{{range .BaseRepoBranches}}
<div class="item" data-url="{{$.PullRequestCtx.BaseRepo.Link}}/compare/{{EscapePound .}}...{{$.HeadUser.Name}}:{{EscapePound $.HeadBranch}}">{{$.PullRequestCtx.BaseRepo.OwnerName}}:{{.}}</div>
{{end}}
{{end}}
</div>
</div>
</div>
Expand All @@ -54,7 +59,7 @@

{{if .IsNothingToCompare}}
<div class="ui segment">{{.i18n.Tr "repo.pulls.nothing_to_compare"}}</div>
{{else if .PageIsComparePull}}
{{else if .PageIsComparePull}}
{{if .HasPullRequest}}
<div class="ui segment">
{{.i18n.Tr "repo.pulls.has_pull_request" $.RepoLink $.RepoRelPath .PullRequest.Index | Safe}}
Expand Down
2 changes: 1 addition & 1 deletion templates/repo/issue/list.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
{{if .PageIsIssueList}}
<a class="ui green button" href="{{.RepoLink}}/issues/new">{{.i18n.Tr "repo.issues.new"}}</a>
{{else}}
<a class="ui green button {{if not .PullRequestCtx.Allowed}}disabled{{end}}" href="{{if .PullRequestCtx.Allowed}}{{.PullRequestCtx.BaseRepo.Link}}/compare/{{.PullRequestCtx.BaseRepo.DefaultBranch | EscapePound}}...{{if ne .Repository.Owner.Name .PullRequestCtx.BaseRepo.Owner.Name}}{{.Repository.Owner.Name}}:{{end}}{{.Repository.DefaultBranch | EscapePound}}{{end}}">{{.i18n.Tr "repo.pulls.new"}}</a>
<a class="ui green button {{if not .PullRequestCtx.Allowed}}disabled{{end}}" href="{{if .PullRequestCtx.Allowed}}{{.Repository.Link}}/compare/{{.Repository.DefaultBranch | EscapePound}}...{{if ne .Repository.Owner.Name .PullRequestCtx.BaseRepo.Owner.Name}}{{.Repository.Owner.Name}}:{{end}}{{.Repository.DefaultBranch | EscapePound}}{{end}}">{{.i18n.Tr "repo.pulls.new"}}</a>
{{end}}
</div>
{{else}}
Expand Down

0 comments on commit 74a4d01

Please sign in to comment.