Skip to content

Commit 45a610f

Browse files
add group id to file comparison urls
1 parent 78c67fe commit 45a610f

File tree

3 files changed

+23
-14
lines changed

3 files changed

+23
-14
lines changed

routers/web/repo/commit.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ func Diff(ctx *context.Context) {
275275

276276
userName := ctx.Repo.Owner.Name
277277
repoName := ctx.Repo.Repository.Name
278+
repoGroup := ctx.Repo.Repository.GroupID
278279
commitID := ctx.PathParam("sha")
279280

280281
diffBlobExcerptData := &gitdiff.DiffBlobExcerptData{
@@ -360,7 +361,7 @@ func Diff(ctx *context.Context) {
360361
}
361362
parentCommitID = parentCommit.ID.String()
362363
}
363-
setCompareContext(ctx, parentCommit, commit, userName, repoName)
364+
setCompareContext(ctx, parentCommit, commit, userName, repoName, repoGroup)
364365
ctx.Data["Title"] = commit.Summary() + " · " + base.ShortSha(commitID)
365366
ctx.Data["Commit"] = commit
366367
ctx.Data["Diff"] = diff

routers/web/repo/compare.go

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ const (
5454
)
5555

5656
// setCompareContext sets context data.
57-
func setCompareContext(ctx *context.Context, before, head *git.Commit, headOwner, headName string) {
57+
func setCompareContext(ctx *context.Context, before, head *git.Commit, headOwner, headName string, headGID int64) {
5858
ctx.Data["BeforeCommit"] = before
5959
ctx.Data["HeadCommit"] = head
6060

@@ -85,28 +85,36 @@ func setCompareContext(ctx *context.Context, before, head *git.Commit, headOwner
8585
return st
8686
}
8787

88-
setPathsCompareContext(ctx, before, head, headOwner, headName)
88+
setPathsCompareContext(ctx, before, head, headOwner, headName, headGID)
8989
setImageCompareContext(ctx)
9090
setCsvCompareContext(ctx)
9191
}
9292

9393
// SourceCommitURL creates a relative URL for a commit in the given repository
94-
func SourceCommitURL(owner, name string, commit *git.Commit) string {
95-
return setting.AppSubURL + "/" + url.PathEscape(owner) + "/" + url.PathEscape(name) + "/src/commit/" + url.PathEscape(commit.ID.String())
94+
func SourceCommitURL(owner, name string, gid int64, commit *git.Commit) string {
95+
var groupSegment string
96+
if gid > 0 {
97+
groupSegment = fmt.Sprintf("group/%d/", gid)
98+
}
99+
return setting.AppSubURL + "/" + url.PathEscape(owner) + "/" + groupSegment + url.PathEscape(name) + "/src/commit/" + url.PathEscape(commit.ID.String())
96100
}
97101

98102
// RawCommitURL creates a relative URL for the raw commit in the given repository
99-
func RawCommitURL(owner, name string, commit *git.Commit) string {
100-
return setting.AppSubURL + "/" + url.PathEscape(owner) + "/" + url.PathEscape(name) + "/raw/commit/" + url.PathEscape(commit.ID.String())
103+
func RawCommitURL(owner, name string, gid int64, commit *git.Commit) string {
104+
var groupSegment string
105+
if gid > 0 {
106+
groupSegment = fmt.Sprintf("group/%d/", gid)
107+
}
108+
return setting.AppSubURL + "/" + url.PathEscape(owner) + "/" + groupSegment + url.PathEscape(name) + "/raw/commit/" + url.PathEscape(commit.ID.String())
101109
}
102110

103111
// setPathsCompareContext sets context data for source and raw paths
104-
func setPathsCompareContext(ctx *context.Context, base, head *git.Commit, headOwner, headName string) {
105-
ctx.Data["SourcePath"] = SourceCommitURL(headOwner, headName, head)
106-
ctx.Data["RawPath"] = RawCommitURL(headOwner, headName, head)
112+
func setPathsCompareContext(ctx *context.Context, base, head *git.Commit, headOwner, headName string, headGID int64) {
113+
ctx.Data["SourcePath"] = SourceCommitURL(headOwner, headName, headGID, head)
114+
ctx.Data["RawPath"] = RawCommitURL(headOwner, headName, headGID, head)
107115
if base != nil {
108-
ctx.Data["BeforeSourcePath"] = SourceCommitURL(headOwner, headName, base)
109-
ctx.Data["BeforeRawPath"] = RawCommitURL(headOwner, headName, base)
116+
ctx.Data["BeforeSourcePath"] = SourceCommitURL(headOwner, headName, headGID, base)
117+
ctx.Data["BeforeRawPath"] = RawCommitURL(headOwner, headName, headGID, base)
110118
}
111119
}
112120

@@ -718,7 +726,7 @@ func PrepareCompareDiff(
718726
ctx.Data["Username"] = ci.HeadUser.Name
719727
ctx.Data["Reponame"] = ci.HeadRepo.Name
720728

721-
setCompareContext(ctx, beforeCommit, headCommit, ci.HeadUser.Name, repo.Name)
729+
setCompareContext(ctx, beforeCommit, headCommit, ci.HeadUser.Name, repo.Name, repo.GroupID)
722730

723731
return false
724732
}

routers/web/repo/pull.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -875,7 +875,7 @@ func viewPullFiles(ctx *context.Context, beforeCommitID, afterCommitID string) {
875875
}
876876
}
877877

878-
setCompareContext(ctx, beforeCommit, afterCommit, ctx.Repo.Owner.Name, ctx.Repo.Repository.Name)
878+
setCompareContext(ctx, beforeCommit, afterCommit, ctx.Repo.Owner.Name, ctx.Repo.Repository.Name, ctx.Repo.Repository.GroupID)
879879

880880
assigneeUsers, err := repo_model.GetRepoAssignees(ctx, ctx.Repo.Repository)
881881
if err != nil {

0 commit comments

Comments
 (0)