Skip to content

Commit 635e46e

Browse files
committed
support link to branch
1 parent 0d1ea63 commit 635e46e

File tree

12 files changed

+43
-2
lines changed

12 files changed

+43
-2
lines changed

scm/driver/bitbucket/linker.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ func (l *linker) Resource(ctx context.Context, repo string, ref scm.Reference) (
2424
case scm.IsPullRequest(ref.Path):
2525
d := scm.ExtractPullRequest(ref.Path)
2626
return fmt.Sprintf("%s%s/pull-requests/%d", l.base, repo, d), nil
27+
case ref.Sha == "":
28+
t := scm.TrimRef(ref.Path)
29+
return fmt.Sprintf("%s%s/src/%s", l.base, repo, t), nil
2730
default:
2831
return fmt.Sprintf("%s%s/commits/%s", l.base, repo, ref.Sha), nil
2932
}

scm/driver/bitbucket/linker_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ func TestLink(t *testing.T) {
3131
path: "refs/tags/v1.0.0",
3232
want: "https://bitbucket.org/octocat/hello-world/src/v1.0.0",
3333
},
34+
{
35+
path: "refs/heads/master",
36+
want: "https://bitbucket.org/octocat/hello-world/src/master",
37+
},
3438
}
3539

3640
for _, test := range tests {

scm/driver/gitea/linker.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ func (l *linker) Resource(ctx context.Context, repo string, ref scm.Reference) (
2424
case scm.IsPullRequest(ref.Path):
2525
d := scm.ExtractPullRequest(ref.Path)
2626
return fmt.Sprintf("%s%s/pulls/%d", l.base, repo, d), nil
27+
case ref.Sha == "":
28+
t := scm.TrimRef(ref.Path)
29+
return fmt.Sprintf("%s%s/src/branch/%s", l.base, repo, t), nil
2730
default:
2831
return fmt.Sprintf("%s%s/commit/%s", l.base, repo, ref.Sha), nil
2932
}

scm/driver/gitea/linker_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ func TestLink(t *testing.T) {
3131
path: "refs/tags/v1.0.0",
3232
want: "https://try.gitea.io/octocat/hello-world/tag/v1.0.0",
3333
},
34+
{
35+
path: "refs/heads/master",
36+
want: "https://try.gitea.io/octocat/hello-world/src/branch/master",
37+
},
3438
}
3539

3640
for _, test := range tests {

scm/driver/github/linker.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ func (l *linker) Resource(ctx context.Context, repo string, ref scm.Reference) (
2424
case scm.IsPullRequest(ref.Path):
2525
d := scm.ExtractPullRequest(ref.Path)
2626
return fmt.Sprintf("%s%s/pull/%d", l.base, repo, d), nil
27+
case ref.Sha == "":
28+
t := scm.TrimRef(ref.Path)
29+
return fmt.Sprintf("%s%s/tree/%s", l.base, repo, t), nil
2730
default:
2831
return fmt.Sprintf("%s%s/commit/%s", l.base, repo, ref.Sha), nil
2932
}

scm/driver/github/linker_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ func TestLink(t *testing.T) {
3131
path: "refs/tags/v1.0.0",
3232
want: "https://github.com/octocat/hello-world/tree/v1.0.0",
3333
},
34+
{
35+
path: "refs/heads/master",
36+
want: "https://github.com/octocat/hello-world/tree/master",
37+
},
3438
}
3539

3640
for _, test := range tests {

scm/driver/gitlab/linker.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ func (l *linker) Resource(ctx context.Context, repo string, ref scm.Reference) (
2424
case scm.IsPullRequest(ref.Path):
2525
d := scm.ExtractPullRequest(ref.Path)
2626
return fmt.Sprintf("%s%s/merge_requests/%d", l.base, repo, d), nil
27+
case ref.Sha == "":
28+
t := scm.TrimRef(ref.Path)
29+
return fmt.Sprintf("%s%s/tree/%s", l.base, repo, t), nil
2730
default:
2831
return fmt.Sprintf("%s%s/commit/%s", l.base, repo, ref.Sha), nil
2932
}

scm/driver/gitlab/linker_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ func TestLink(t *testing.T) {
3131
path: "refs/tags/v1.0.0",
3232
want: "https://gitlab.com/octocat/hello-world/-/tags/v1.0.0",
3333
},
34+
{
35+
path: "refs/heads/master",
36+
want: "https://gitlab.com/octocat/hello-world/tree/master",
37+
},
3438
}
3539

3640
for _, test := range tests {

scm/driver/gogs/linker.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,13 @@ func (l *linker) Resource(ctx context.Context, repo string, ref scm.Reference) (
2020
switch {
2121
case scm.IsTag(ref.Path):
2222
t := scm.TrimRef(ref.Path)
23-
return fmt.Sprintf("%s%s/tag/%s", l.base, repo, t), nil
23+
return fmt.Sprintf("%s%s/src/%s", l.base, repo, t), nil
2424
case scm.IsPullRequest(ref.Path):
2525
d := scm.ExtractPullRequest(ref.Path)
2626
return fmt.Sprintf("%s%s/pulls/%d", l.base, repo, d), nil
27+
case ref.Sha == "":
28+
t := scm.TrimRef(ref.Path)
29+
return fmt.Sprintf("%s%s/src/%s", l.base, repo, t), nil
2730
default:
2831
return fmt.Sprintf("%s%s/commit/%s", l.base, repo, ref.Sha), nil
2932
}

scm/driver/gogs/linker_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@ func TestLink(t *testing.T) {
2929
},
3030
{
3131
path: "refs/tags/v1.0.0",
32-
want: "https://try.gogs.io/octocat/hello-world/tag/v1.0.0",
32+
want: "https://try.gogs.io/octocat/hello-world/src/v1.0.0",
33+
},
34+
{
35+
path: "refs/heads/master",
36+
want: "https://try.gogs.io/octocat/hello-world/src/master",
3337
},
3438
}
3539

0 commit comments

Comments
 (0)