Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: seprate webhook payload from specific git provider impl - RK-19326 #100

Merged
merged 1 commit into from
Jul 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading