mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-12-06 08:16:19 +02:00
Remove /refs/tags or /refs/heads from Gogs remote File() when using build.Ref
This commit is contained in:
parent
342530772f
commit
3884e589a9
@ -30,12 +30,13 @@ func getRepo(c *gin.Context) {
|
||||
}
|
||||
|
||||
func getRepoFile(c *gin.Context) {
|
||||
switch c.Param("file") {
|
||||
case "file_not_found":
|
||||
c.String(404, "")
|
||||
default:
|
||||
c.String(200, repoFilePayload)
|
||||
}
|
||||
if c.Param("file") == "file_not_found" {
|
||||
c.String(404, "")
|
||||
}
|
||||
if c.Param("commit") == "v1.0.0" || c.Param("commit") == "9ecad50" {
|
||||
c.String(200, repoFilePayload)
|
||||
}
|
||||
c.String(404, "")
|
||||
}
|
||||
|
||||
func createRepoHook(c *gin.Context) {
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
"github.com/drone/drone/model"
|
||||
"github.com/drone/drone/remote"
|
||||
@ -177,6 +178,12 @@ func (c *client) File(u *model.User, r *model.Repo, b *model.Build, f string) ([
|
||||
buildRef := b.Commit
|
||||
if buildRef == "" {
|
||||
buildRef = b.Ref
|
||||
|
||||
// Remove refs/tags or refs/heads, Gogs needs a short ref
|
||||
refPath := strings.SplitAfterN(b.Ref, "/", 3)
|
||||
if len(refPath) > 0 {
|
||||
buildRef = refPath[len(refPath)-1]
|
||||
}
|
||||
}
|
||||
cfg, err := client.GetFile(r.Owner, r.Name, buildRef, f)
|
||||
return cfg, err
|
||||
|
@ -128,6 +128,12 @@ func Test_gogs(t *testing.T) {
|
||||
g.Assert(string(raw)).Equal("{ platform: linux/amd64 }")
|
||||
})
|
||||
|
||||
g.It("Should return a repository file from a ref", func() {
|
||||
raw, err := c.File(fakeUser, fakeRepo, fakeBuildWithRef, ".drone.yml")
|
||||
g.Assert(err == nil).IsTrue()
|
||||
g.Assert(string(raw)).Equal("{ platform: linux/amd64 }")
|
||||
})
|
||||
|
||||
g.Describe("Given an authentication request", func() {
|
||||
g.It("Should redirect to login form")
|
||||
g.It("Should create an access token")
|
||||
@ -178,4 +184,8 @@ var (
|
||||
fakeBuild = &model.Build{
|
||||
Commit: "9ecad50",
|
||||
}
|
||||
|
||||
fakeBuildWithRef = &model.Build{
|
||||
Ref: "refs/tags/v1.0.0",
|
||||
}
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user