Skip to content

Commit

Permalink
fix gitlab namepsace resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
bradrydzewski committed Nov 13, 2018
1 parent ce73161 commit e4326a4
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"Ref": "refs/heads/feature",
"Repo": {
"ID": "4861503",
"Namespace": "sytses",
"Namespace": "gitlab-org",
"Name": "hello-world",
"Perm": null,
"Branch": "master",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"Action": "closed",
"Repo": {
"ID": "4861503",
"Namespace": "sytses",
"Namespace": "gitlab-org",
"Name": "hello-world",
"Perm": null,
"Branch": "master",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"Action": "opened",
"Repo": {
"ID": "4861503",
"Namespace": "sytses",
"Namespace": "gitlab-org",
"Name": "hello-world",
"Perm": null,
"Branch": "master",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"Action": "merged",
"Repo": {
"ID": "4861503",
"Namespace": "sytses",
"Namespace": "gitlab-org",
"Name": "hello-world",
"Perm": null,
"Branch": "master",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"Action": "reopened",
"Repo": {
"ID": "4861503",
"Namespace": "sytses",
"Namespace": "gitlab-org",
"Name": "hello-world",
"Perm": null,
"Branch": "master",
Expand Down
2 changes: 1 addition & 1 deletion scm/driver/gitlab/testdata/webhooks/push.json.golden
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"Ref": "refs/heads/master",
"Repo": {
"ID": "4861503",
"Namespace": "sytses",
"Namespace": "gitlab-org",
"Name": "hello-world",
"Perm": null,
"Branch": "master",
Expand Down
2 changes: 1 addition & 1 deletion scm/driver/gitlab/testdata/webhooks/tag_create.json.golden
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"Ref": "refs/tags/v1.0.0",
"Repo": {
"ID": "4861503",
"Namespace": "sytses",
"Namespace": "gitlab-org",
"Name": "hello-world",
"Perm": null,
"Branch": "master",
Expand Down
2 changes: 1 addition & 1 deletion scm/driver/gitlab/testdata/webhooks/tag_delete.json.golden
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
},
"Repo": {
"ID": "4861503",
"Namespace": "sytses",
"Namespace": "gitlab-org",
"Name": "hello-world",
"Perm": null,
"Branch": "master",
Expand Down
20 changes: 12 additions & 8 deletions scm/driver/gitlab/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,13 @@ func parsePullRequestHook(data []byte) (scm.Webhook, error) {
}

func convertPushHook(src *pushHook) *scm.PushHook {
namespace, name := scm.Split(src.Project.PathWithNamespace)
dst := &scm.PushHook{
Ref: scm.ExpandRef(src.Ref, "refs/heads/"),
Repo: scm.Repository{
ID: strconv.Itoa(src.Project.ID),
Namespace: src.Project.Namespace,
Name: src.Project.Name,
Namespace: namespace,
Name: name,
Clone: src.Project.GitHTTPURL,
CloneSSH: src.Project.GitSSHURL,
Link: src.Project.WebURL,
Expand Down Expand Up @@ -154,6 +155,7 @@ func converBranchHook(src *pushHook) *scm.BranchHook {
action = scm.ActionDelete
commit = src.Before
}
namespace, name := scm.Split(src.Project.PathWithNamespace)
return &scm.BranchHook{
Action: action,
Ref: scm.Reference{
Expand All @@ -162,8 +164,8 @@ func converBranchHook(src *pushHook) *scm.BranchHook {
},
Repo: scm.Repository{
ID: strconv.Itoa(src.Project.ID),
Namespace: src.Project.Namespace,
Name: src.Project.Name,
Namespace: namespace,
Name: name,
Clone: src.Project.GitHTTPURL,
CloneSSH: src.Project.GitSSHURL,
Link: src.Project.WebURL,
Expand All @@ -186,6 +188,7 @@ func convertTagHook(src *pushHook) *scm.TagHook {
action = scm.ActionDelete
commit = src.Before
}
namespace, name := scm.Split(src.Project.PathWithNamespace)
return &scm.TagHook{
Action: action,
Ref: scm.Reference{
Expand All @@ -194,8 +197,8 @@ func convertTagHook(src *pushHook) *scm.TagHook {
},
Repo: scm.Repository{
ID: strconv.Itoa(src.Project.ID),
Namespace: src.Project.Namespace,
Name: src.Project.Name,
Namespace: namespace,
Name: name,
Clone: src.Project.GitHTTPURL,
CloneSSH: src.Project.GitSSHURL,
Link: src.Project.WebURL,
Expand Down Expand Up @@ -229,6 +232,7 @@ func convertPullRequestHook(src *pullRequestHook) *scm.PullRequestHook {
src.ObjectAttributes.Source.Namespace,
src.ObjectAttributes.Source.Name,
)
namespace, name := scm.Split(src.Project.PathWithNamespace)
return &scm.PullRequestHook{
Action: action,
PullRequest: scm.PullRequest{
Expand All @@ -254,8 +258,8 @@ func convertPullRequestHook(src *pullRequestHook) *scm.PullRequestHook {
},
Repo: scm.Repository{
ID: strconv.Itoa(src.Project.ID),
Namespace: src.Project.Namespace,
Name: src.Project.Name,
Namespace: namespace,
Name: name,
Clone: src.Project.GitHTTPURL,
CloneSSH: src.Project.GitSSHURL,
Link: src.Project.WebURL,
Expand Down

0 comments on commit e4326a4

Please sign in to comment.