From c2703ff89c1b4c99041bacc2c93ab13f3ab65853 Mon Sep 17 00:00:00 2001 From: Michael de Wit Date: Thu, 22 Dec 2016 14:24:05 +0100 Subject: [PATCH] Optimize performance --- remote/gogs/gogs.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/remote/gogs/gogs.go b/remote/gogs/gogs.go index cbf2e81f9..98cc6f231 100644 --- a/remote/gogs/gogs.go +++ b/remote/gogs/gogs.go @@ -177,13 +177,14 @@ func (c *client) File(u *model.User, r *model.Repo, b *model.Build, f string) ([ client := c.newClientToken(u.Token) 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] - } + buildRef = strings.TrimPrefix( + strings.TrimPrefix( + b.Ref, + "refs/heads/", + ), + "refs/tags/", + ) } cfg, err := client.GetFile(r.Owner, r.Name, buildRef, f) return cfg, err