Skip to content

Commit

Permalink
fix: seprate webhook payload from specific git provider impl (#100)
Browse files Browse the repository at this point in the history
Signed-off-by: Gosha <[email protected]>
  • Loading branch information
gosharo authored Jul 16, 2023
1 parent 2076dfb commit 98aa885
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 19 deletions.
10 changes: 9 additions & 1 deletion pkg/git_provider/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ func (c *GithubClientImpl) HandlePayload(request *http.Request, secret []byte) (
PullRequestTitle: e.GetPullRequest().GetTitle(),
PullRequestURL: e.GetPullRequest().GetHTMLURL(),
DestBranch: e.GetPullRequest().GetBase().GetRef(),
Labels: e.GetPullRequest().Labels,
Labels: c.extractLabelNames(e.GetPullRequest().Labels),
}
case *github.CreateEvent:
webhookPayload = &WebhookPayload{
Expand Down Expand Up @@ -297,3 +297,11 @@ func (c *GithubClientImpl) SetStatus(ctx *context.Context, repo *string, commit
log.Printf("successfully set status on repo:%s commit: %s to status: %s\n", *repo, *commit, *status)
return nil
}

func (c *GithubClientImpl) extractLabelNames(labels []*github.Label) []string {
var returnLabelsList []string
for _, label := range labels {
returnLabelsList = append(returnLabelsList, *label.Name)
}
return returnLabelsList
}
23 changes: 11 additions & 12 deletions pkg/git_provider/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package git_provider

import (
"context"
"github.com/google/go-github/v52/github"
"net/http"
)

Expand All @@ -12,17 +11,17 @@ type CommitFile struct {
}

type WebhookPayload struct {
Event string `json:"event"`
Action string `json:"action"`
Repo string `json:"repoName"`
Branch string `json:"branch"`
Commit string `json:"commit"`
User string `json:"user"`
UserEmail string `json:"user_email"`
PullRequestURL string `json:"pull_request_url"`
PullRequestTitle string `json:"pull_request_title"`
DestBranch string `json:"dest_branch"`
Labels []*github.Label `json:"Labels"`
Event string `json:"event"`
Action string `json:"action"`
Repo string `json:"repoName"`
Branch string `json:"branch"`
Commit string `json:"commit"`
User string `json:"user"`
UserEmail string `json:"user_email"`
PullRequestURL string `json:"pull_request_url"`
PullRequestTitle string `json:"pull_request_title"`
DestBranch string `json:"dest_branch"`
Labels []string `json:"Labels"`
}

type Client interface {
Expand Down
7 changes: 1 addition & 6 deletions pkg/workflow_handler/workflows.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,6 @@ func (wfc *WorkflowsClientImpl) HandleWorkflowBatch(ctx *context.Context, workfl
}
}

var prLabels []string
for _, label := range workflowsBatch.Payload.Labels {
prLabels = append(prLabels, label.GetName())
}

globalParams := []v1alpha1.Parameter{
{Name: "event", Value: v1alpha1.AnyStringPtr(workflowsBatch.Payload.Event)},
{Name: "action", Value: v1alpha1.AnyStringPtr(workflowsBatch.Payload.Action)},
Expand All @@ -190,7 +185,7 @@ func (wfc *WorkflowsClientImpl) HandleWorkflowBatch(ctx *context.Context, workfl
{Name: "pull_request_url", Value: v1alpha1.AnyStringPtr(workflowsBatch.Payload.PullRequestURL)},
{Name: "pull_request_title", Value: v1alpha1.AnyStringPtr(workflowsBatch.Payload.PullRequestTitle)},
{Name: "dest_branch", Value: v1alpha1.AnyStringPtr(workflowsBatch.Payload.DestBranch)},
{Name: "pull_request_labels", Value: v1alpha1.AnyStringPtr(strings.Join(prLabels, ","))},
{Name: "pull_request_labels", Value: v1alpha1.AnyStringPtr(strings.Join(workflowsBatch.Payload.Labels, ","))},
}

params = append(params, globalParams...)
Expand Down

0 comments on commit 98aa885

Please sign in to comment.