From c5441a94a7ef341cb8e9ec0c50982620639d75a2 Mon Sep 17 00:00:00 2001 From: David Hollinger Date: Thu, 27 Jun 2024 13:10:17 -0500 Subject: [PATCH] allow for branches with slashes in them --- lib/parsers/azure-devops.go | 4 ++-- lib/parsers/bitbucket-server.go | 4 ++-- lib/parsers/github.go | 4 ++-- lib/parsers/gitlab.go | 4 ++-- lib/parsers/parser.go | 2 ++ 5 files changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/parsers/azure-devops.go b/lib/parsers/azure-devops.go index e1ce6bd..e18f127 100644 --- a/lib/parsers/azure-devops.go +++ b/lib/parsers/azure-devops.go @@ -4,7 +4,7 @@ import ( "encoding/json" "fmt" "io/ioutil" - "path" + "strings" "github.com/gin-gonic/gin" "github.com/mcdafydd/go-azuredevops/azuredevops" @@ -59,5 +59,5 @@ func (d *Data) azureDevopsDeleted(e *azuredevops.GitPush) bool { } func (d *Data) parseBranch(e *azuredevops.GitPush) string { - return path.Base(*e.RefUpdates[0].Name) + return strings.TrimPrefix(*e.RefUpdates[0].Name, prefix) } diff --git a/lib/parsers/bitbucket-server.go b/lib/parsers/bitbucket-server.go index 645f145..98c3b92 100644 --- a/lib/parsers/bitbucket-server.go +++ b/lib/parsers/bitbucket-server.go @@ -2,7 +2,7 @@ package parsers import ( "fmt" - "path" + "strings" "github.com/gin-gonic/gin" bitbucketserver "github.com/go-playground/webhooks/v6/bitbucket-server" @@ -40,5 +40,5 @@ func (d *Data) bitbucketServerDeleted(c bitbucketserver.RepositoryReferenceChang } func (d *Data) bsParseBranch(e bitbucketserver.RepositoryReferenceChangedPayload) string { - return path.Base(e.Changes[0].ReferenceID) + return strings.TrimPrefix(e.Changes[0].ReferenceID, prefix) } diff --git a/lib/parsers/github.go b/lib/parsers/github.go index f6333a6..0f33ac5 100644 --- a/lib/parsers/github.go +++ b/lib/parsers/github.go @@ -3,7 +3,7 @@ package parsers import ( "fmt" "io/ioutil" - "path" + "strings" "github.com/gin-gonic/gin" "github.com/google/go-github/v39/github" @@ -23,7 +23,7 @@ func (d *Data) parseGithub(c *gin.Context) error { switch e := event.(type) { case *github.PushEvent: - d.Branch = path.Base(*e.Ref) + d.Branch = strings.TrimPrefix(*e.Ref, prefix) d.Deleted = *e.Deleted d.ModuleName = *e.Repo.Name d.RepoName = *e.Repo.FullName diff --git a/lib/parsers/gitlab.go b/lib/parsers/gitlab.go index 4409d8d..ab66fa9 100644 --- a/lib/parsers/gitlab.go +++ b/lib/parsers/gitlab.go @@ -3,7 +3,7 @@ package parsers import ( "fmt" "io/ioutil" - "path" + "strings" "github.com/gin-gonic/gin" "github.com/xanzy/go-gitlab" @@ -22,7 +22,7 @@ func (d *Data) parseGitlab(c *gin.Context) error { switch e := event.(type) { case *gitlab.PushEvent: - d.Branch = path.Base(e.Ref) + d.Branch = strings.TrimPrefix(e.Ref, prefix) d.Deleted = d.gitlabDeleted(e.After) d.ModuleName = e.Project.Name d.RepoName = e.Project.PathWithNamespace diff --git a/lib/parsers/parser.go b/lib/parsers/parser.go index 11ffac8..43ebd33 100644 --- a/lib/parsers/parser.go +++ b/lib/parsers/parser.go @@ -8,6 +8,8 @@ import ( "github.com/gin-gonic/gin" ) +const prefix = "refs/heads/" + type Data struct { Branch string Deleted bool