Skip to content

Commit

Permalink
Fix field naming
Browse files Browse the repository at this point in the history
Co-authored-by: Yahav Itzhak <[email protected]>
  • Loading branch information
RemiBou and yahavi committed Dec 7, 2021
1 parent e0b7f40 commit 01dc963
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 23 deletions.
4 changes: 2 additions & 2 deletions vcsutils/webhookparser/bitbucketcloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (webhook *BitbucketCloudWebhook) parseIncomingWebhook(payload []byte) (*Web
func (webhook *BitbucketCloudWebhook) parsePushEvent(bitbucketCloudWebHook *bitbucketCloudWebHook) *WebhookInfo {
return &WebhookInfo{
TargetRepositoryDetails: webhook.parseRepoFullName(bitbucketCloudWebHook.Repository.FullName),
Branch: bitbucketCloudWebHook.Push.Changes[0].New.Name,
TargetBranch: bitbucketCloudWebHook.Push.Changes[0].New.Name,
Timestamp: bitbucketCloudWebHook.Push.Changes[0].New.Target.Date.UTC().Unix(),
Event: vcsutils.Push,
}
Expand All @@ -67,7 +67,7 @@ func (webhook *BitbucketCloudWebhook) parsePrEvents(bitbucketCloudWebHook *bitbu
return &WebhookInfo{
PullRequestId: bitbucketCloudWebHook.PullRequest.Id,
TargetRepositoryDetails: webhook.parseRepoFullName(bitbucketCloudWebHook.PullRequest.Destination.Repository.FullName),
Branch: bitbucketCloudWebHook.PullRequest.Destination.Branch.Name,
TargetBranch: bitbucketCloudWebHook.PullRequest.Destination.Branch.Name,
SourceRepositoryDetails: webhook.parseRepoFullName(bitbucketCloudWebHook.PullRequest.Source.Repository.FullName),
SourceBranch: bitbucketCloudWebHook.PullRequest.Source.Branch.Name,
Timestamp: bitbucketCloudWebHook.PullRequest.UpdatedOn.UTC().Unix(),
Expand Down
6 changes: 3 additions & 3 deletions vcsutils/webhookparser/bitbucketcloud_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TestBitbucketCloudParseIncomingPushWebhook(t *testing.T) {
// Check values
assert.Equal(t, expectedRepoName, actual.TargetRepositoryDetails.Name)
assert.Equal(t, expectedOwner, actual.TargetRepositoryDetails.Owner)
assert.Equal(t, expectedBranch, actual.Branch)
assert.Equal(t, expectedBranch, actual.TargetBranch)
assert.Equal(t, bitbucketCloudPushExpectedTime, actual.Timestamp)
assert.Equal(t, vcsutils.Push, actual.Event)
}
Expand All @@ -55,7 +55,7 @@ func TestBitbucketCloudParseIncomingPrCreateWebhook(t *testing.T) {
assert.Equal(t, bitbucketCloudExpectedPrId, actual.PullRequestId)
assert.Equal(t, expectedRepoName, actual.TargetRepositoryDetails.Name)
assert.Equal(t, expectedOwner, actual.TargetRepositoryDetails.Owner)
assert.Equal(t, expectedBranch, actual.Branch)
assert.Equal(t, expectedBranch, actual.TargetBranch)
assert.Equal(t, bitbucketCloudPrCreateExpectedTime, actual.Timestamp)
assert.Equal(t, expectedRepoName, actual.SourceRepositoryDetails.Name)
assert.Equal(t, expectedOwner, actual.SourceRepositoryDetails.Owner)
Expand All @@ -80,7 +80,7 @@ func TestBitbucketCloudParseIncomingPrUpdateWebhook(t *testing.T) {
assert.Equal(t, bitbucketCloudExpectedPrId, actual.PullRequestId)
assert.Equal(t, expectedRepoName, actual.TargetRepositoryDetails.Name)
assert.Equal(t, expectedOwner, actual.TargetRepositoryDetails.Owner)
assert.Equal(t, expectedBranch, actual.Branch)
assert.Equal(t, expectedBranch, actual.TargetBranch)
assert.Equal(t, bitbucketCloudPrUpdateExpectedTime, actual.Timestamp)
assert.Equal(t, expectedRepoName, actual.SourceRepositoryDetails.Name)
assert.Equal(t, expectedOwner, actual.SourceRepositoryDetails.Owner)
Expand Down
4 changes: 2 additions & 2 deletions vcsutils/webhookparser/bitbucketserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (webhook *BitbucketServerWebhook) parsePushEvent(bitbucketCloudWebHook *bit
repository := bitbucketCloudWebHook.Repository
return &WebhookInfo{
TargetRepositoryDetails: webhook.getRepositoryDetails(repository),
Branch: strings.TrimPrefix(bitbucketCloudWebHook.Changes[0].RefId, "refs/heads/"),
TargetBranch: strings.TrimPrefix(bitbucketCloudWebHook.Changes[0].RefId, "refs/heads/"),
Timestamp: eventTime.UTC().Unix(),
Event: vcsutils.Push,
}, nil
Expand All @@ -98,7 +98,7 @@ func (webhook *BitbucketServerWebhook) parsePrEvents(bitbucketCloudWebHook *bitb
return &WebhookInfo{
PullRequestId: bitbucketCloudWebHook.PullRequest.ID,
TargetRepositoryDetails: webhook.getRepositoryDetails(bitbucketCloudWebHook.PullRequest.ToRef.Repository),
Branch: strings.TrimPrefix(bitbucketCloudWebHook.PullRequest.ToRef.ID, "refs/heads/"),
TargetBranch: strings.TrimPrefix(bitbucketCloudWebHook.PullRequest.ToRef.ID, "refs/heads/"),
SourceRepositoryDetails: webhook.getRepositoryDetails(bitbucketCloudWebHook.PullRequest.FromRef.Repository),
SourceBranch: strings.TrimPrefix(bitbucketCloudWebHook.PullRequest.FromRef.ID, "refs/heads/"),
Timestamp: eventTime.UTC().Unix(),
Expand Down
6 changes: 3 additions & 3 deletions vcsutils/webhookparser/bitbucketserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestBitbucketServerParseIncomingPushWebhook(t *testing.T) {
// Check values
assert.Equal(t, expectedRepoName, actual.TargetRepositoryDetails.Name)
assert.Equal(t, expectedOwner, actual.TargetRepositoryDetails.Owner)
assert.Equal(t, expectedBranch, actual.Branch)
assert.Equal(t, expectedBranch, actual.TargetBranch)
assert.Equal(t, bitbucketServerPushExpectedTime, actual.Timestamp)
assert.Equal(t, vcsutils.Push, actual.Event)
}
Expand All @@ -63,7 +63,7 @@ func TestBitbucketServerParseIncomingPrCreateWebhook(t *testing.T) {
assert.Equal(t, bitbucketServerExpectedPrId, actual.PullRequestId)
assert.Equal(t, expectedRepoName, actual.TargetRepositoryDetails.Name)
assert.Equal(t, expectedOwner, actual.TargetRepositoryDetails.Owner)
assert.Equal(t, expectedBranch, actual.Branch)
assert.Equal(t, expectedBranch, actual.TargetBranch)
assert.Equal(t, bitbucketServerPrCreateExpectedTime, actual.Timestamp)
assert.Equal(t, expectedRepoName, actual.SourceRepositoryDetails.Name)
assert.Equal(t, expectedOwner, actual.SourceRepositoryDetails.Owner)
Expand All @@ -89,7 +89,7 @@ func TestBitbucketServerParseIncomingPrUpdateWebhook(t *testing.T) {
assert.Equal(t, bitbucketServerExpectedPrId, actual.PullRequestId)
assert.Equal(t, expectedRepoName, actual.TargetRepositoryDetails.Name)
assert.Equal(t, expectedOwner, actual.TargetRepositoryDetails.Owner)
assert.Equal(t, expectedBranch, actual.Branch)
assert.Equal(t, expectedBranch, actual.TargetBranch)
assert.Equal(t, bitbucketServerPrUpdateExpectedTime, actual.Timestamp)
assert.Equal(t, expectedRepoName, actual.SourceRepositoryDetails.Name)
assert.Equal(t, expectedOwner, actual.SourceRepositoryDetails.Owner)
Expand Down
8 changes: 4 additions & 4 deletions vcsutils/webhookparser/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ func (webhook *GitHubWebhook) parsePushEvent(event *github.PushEvent) *WebhookIn
Name: *event.GetRepo().Name,
Owner: *event.GetRepo().Owner.Login,
},
Branch: strings.TrimPrefix(event.GetRef(), "refs/heads/"),
Timestamp: event.GetHeadCommit().GetTimestamp().UTC().Unix(),
Event: vcsutils.Push,
TargetBranch: strings.TrimPrefix(event.GetRef(), "refs/heads/"),
Timestamp: event.GetHeadCommit().GetTimestamp().UTC().Unix(),
Event: vcsutils.Push,
}
}

Expand All @@ -74,7 +74,7 @@ func (webhook *GitHubWebhook) parsePrEvents(event *github.PullRequestEvent) *Web
Name: *event.GetPullRequest().GetBase().GetRepo().Name,
Owner: *event.GetPullRequest().GetBase().GetRepo().Owner.Login,
},
Branch: event.GetPullRequest().GetBase().GetRef(),
TargetBranch: event.GetPullRequest().GetBase().GetRef(),
SourceRepositoryDetails: WebHookInfoRepoDetails{
Name: *event.GetPullRequest().GetHead().GetRepo().Name,
Owner: *event.GetPullRequest().GetHead().GetRepo().Owner.Login,
Expand Down
6 changes: 3 additions & 3 deletions vcsutils/webhookparser/github_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func TestGitHubParseIncomingPushWebhook(t *testing.T) {
// Check values
assert.Equal(t, expectedRepoName, actual.TargetRepositoryDetails.Name)
assert.Equal(t, expectedOwner, actual.TargetRepositoryDetails.Owner)
assert.Equal(t, expectedBranch, actual.Branch)
assert.Equal(t, expectedBranch, actual.TargetBranch)
assert.Equal(t, githubPushExpectedTime, actual.Timestamp)
assert.Equal(t, vcsutils.Push, actual.Event)
}
Expand All @@ -69,7 +69,7 @@ func TestGitHubParseIncomingPrCreateWebhook(t *testing.T) {
assert.Equal(t, gitHubExpectedPrId, actual.PullRequestId)
assert.Equal(t, expectedRepoName, actual.TargetRepositoryDetails.Name)
assert.Equal(t, expectedOwner, actual.TargetRepositoryDetails.Owner)
assert.Equal(t, expectedBranch, actual.Branch)
assert.Equal(t, expectedBranch, actual.TargetBranch)
assert.Equal(t, githubPrCreateExpectedTime, actual.Timestamp)
assert.Equal(t, expectedRepoName, actual.SourceRepositoryDetails.Name)
assert.Equal(t, expectedOwner, actual.SourceRepositoryDetails.Owner)
Expand All @@ -96,7 +96,7 @@ func TestGitHubParseIncomingPrUpdateWebhook(t *testing.T) {
assert.Equal(t, gitHubExpectedPrId, actual.PullRequestId)
assert.Equal(t, expectedRepoName, actual.TargetRepositoryDetails.Name)
assert.Equal(t, expectedOwner, actual.TargetRepositoryDetails.Owner)
assert.Equal(t, expectedBranch, actual.Branch)
assert.Equal(t, expectedBranch, actual.TargetBranch)
assert.Equal(t, githubPrUpdateExpectedTime, actual.Timestamp)
assert.Equal(t, expectedRepoName, actual.SourceRepositoryDetails.Name)
assert.Equal(t, expectedOwner, actual.SourceRepositoryDetails.Owner)
Expand Down
4 changes: 2 additions & 2 deletions vcsutils/webhookparser/gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (webhook *GitLabWebhook) parseIncomingWebhook(payload []byte) (*WebhookInfo
func (webhook *GitLabWebhook) parsePushEvent(event *gitlab.PushEvent) *WebhookInfo {
return &WebhookInfo{
TargetRepositoryDetails: webhook.parseRepoDetails(event.Project.PathWithNamespace),
Branch: strings.TrimPrefix(event.Ref, "refs/heads/"),
TargetBranch: strings.TrimPrefix(event.Ref, "refs/heads/"),
Timestamp: event.Commits[0].Timestamp.Local().Unix(),
Event: vcsutils.Push,
}
Expand Down Expand Up @@ -84,7 +84,7 @@ func (webhook *GitLabWebhook) parsePrEvents(event *gitlab.MergeEvent) (*WebhookI
SourceRepositoryDetails: webhook.parseRepoDetails(event.ObjectAttributes.Source.PathWithNamespace),
SourceBranch: event.ObjectAttributes.SourceBranch,
TargetRepositoryDetails: webhook.parseRepoDetails(event.ObjectAttributes.Target.PathWithNamespace),
Branch: event.ObjectAttributes.TargetBranch,
TargetBranch: event.ObjectAttributes.TargetBranch,
Timestamp: eventTime.UTC().Unix(),
Event: webhookEvent,
}, nil
Expand Down
6 changes: 3 additions & 3 deletions vcsutils/webhookparser/gitlab_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestGitLabParseIncomingPushWebhook(t *testing.T) {
// Check values
assert.Equal(t, expectedRepoName, actual.TargetRepositoryDetails.Name)
assert.Equal(t, expectedOwner, actual.TargetRepositoryDetails.Owner)
assert.Equal(t, expectedBranch, actual.Branch)
assert.Equal(t, expectedBranch, actual.TargetBranch)
assert.Equal(t, gitlabPushExpectedTime, actual.Timestamp)
assert.Equal(t, vcsutils.Push, actual.Event)
}
Expand All @@ -58,7 +58,7 @@ func TestGitLabParseIncomingPrCreateWebhook(t *testing.T) {
assert.Equal(t, gitlabExpectedPrId, actual.PullRequestId)
assert.Equal(t, expectedRepoName, actual.TargetRepositoryDetails.Name)
assert.Equal(t, expectedOwner, actual.TargetRepositoryDetails.Owner)
assert.Equal(t, expectedBranch, actual.Branch)
assert.Equal(t, expectedBranch, actual.TargetBranch)
assert.Equal(t, gitlabPrCreateExpectedTime, actual.Timestamp)
assert.Equal(t, expectedRepoName, actual.SourceRepositoryDetails.Name)
assert.Equal(t, expectedOwner, actual.SourceRepositoryDetails.Owner)
Expand All @@ -84,7 +84,7 @@ func TestGitLabParseIncomingPrUpdateWebhook(t *testing.T) {
assert.Equal(t, gitlabExpectedPrId, actual.PullRequestId)
assert.Equal(t, expectedRepoName, actual.TargetRepositoryDetails.Name)
assert.Equal(t, expectedOwner, actual.TargetRepositoryDetails.Owner)
assert.Equal(t, expectedBranch, actual.Branch)
assert.Equal(t, expectedBranch, actual.TargetBranch)
assert.Equal(t, gitlabPrUpdateExpectedTime, actual.Timestamp)
assert.Equal(t, expectedRepoName, actual.SourceRepositoryDetails.Name)
assert.Equal(t, expectedOwner, actual.SourceRepositoryDetails.Owner)
Expand Down
2 changes: 1 addition & 1 deletion vcsutils/webhookparser/webhookparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type WebhookInfo struct {
// The target repository for pull requests and push
TargetRepositoryDetails WebHookInfoRepoDetails `json:"target_repository_details,omitempty"`
// The target branch for pull requests and push
Branch string `json:"branch,omitempty"`
TargetBranch string `json:"branch,omitempty"`
// Pull request id
PullRequestId int `json:"pull_request_id,omitempty"`
// The source repository for pull requests
Expand Down

0 comments on commit 01dc963

Please sign in to comment.