Skip to content

Commit

Permalink
Simplify branch parsing in the parsers
Browse files Browse the repository at this point in the history
  • Loading branch information
dhollinger committed Aug 23, 2021
1 parent 43cdfb3 commit be8d7b5
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions lib/parsers/azure-devops.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"encoding/json"
"fmt"
"io/ioutil"
"strings"
"path"

"github.com/gin-gonic/gin"
"github.com/mcdafydd/go-azuredevops/azuredevops"
Expand Down Expand Up @@ -57,5 +57,5 @@ func (d *Data) AzureDevopsDeleted(e *azuredevops.GitPush) bool {
}

func (d *Data) ParseBranch(e *azuredevops.GitPush) string {
return strings.ReplaceAll(*e.RefUpdates[0].Name, "refs/heads/", "")
return path.Base(*e.RefUpdates[0].Name)
}
4 changes: 2 additions & 2 deletions lib/parsers/bitbucket-server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package parsers

import (
"fmt"
"strings"
"path"

"github.com/gin-gonic/gin"
bitbucketserver "github.com/go-playground/webhooks/v6/bitbucket-server"
Expand Down Expand Up @@ -38,5 +38,5 @@ func (d *Data) BitbucketServerDeleted(c bitbucketserver.RepositoryReferenceChang
}

func (d *Data) BsParseBranch(e bitbucketserver.RepositoryReferenceChangedPayload) string {
return strings.ReplaceAll(e.Changes[0].ReferenceID, "refs/heads/", "")
return path.Base(e.Changes[0].ReferenceID)
}
4 changes: 2 additions & 2 deletions lib/parsers/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package parsers
import (
"fmt"
"io/ioutil"
"strings"
"path"

"github.com/gin-gonic/gin"
"github.com/google/go-github/github"
Expand All @@ -23,7 +23,7 @@ func (d *Data) ParseGithub(c *gin.Context) error {

switch e := event.(type) {
case *github.PushEvent:
d.Branch = strings.ReplaceAll(*e.Ref, "refs/heads/", "")
d.Branch = path.Base(*e.Ref)
d.Deleted = *e.Deleted
d.ModuleName = *e.Repo.Name
d.RepoName = *e.Repo.FullName
Expand Down
4 changes: 2 additions & 2 deletions lib/parsers/gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package parsers
import (
"fmt"
"io/ioutil"
"strings"
"path"

"github.com/gin-gonic/gin"
"github.com/xanzy/go-gitlab"
Expand All @@ -22,7 +22,7 @@ func (d *Data) ParseGitlab(c *gin.Context) error {

switch e := event.(type) {
case *gitlab.PushEvent:
d.Branch = strings.ReplaceAll(e.Ref, "refs/heads/", "")
d.Branch = path.Base(e.Ref)
d.Deleted = d.GitlabDeleted(e)
d.ModuleName = e.Project.Name
d.RepoName = e.Project.PathWithNamespace
Expand Down

0 comments on commit be8d7b5

Please sign in to comment.