Skip to content

Commit

Permalink
update resolver to match on repo and path
Browse files Browse the repository at this point in the history
  • Loading branch information
corymurphy committed Oct 15, 2024
1 parent ae098b0 commit fa520ea
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 66 deletions.
4 changes: 2 additions & 2 deletions charts/argobot/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ apiVersion: v2
name: argobot
description: Helm chart for the corymurphy/argobot app
type: application
version: 0.16.1
appVersion: 0.16.1
version: 0.16.2
appVersion: 0.16.2
2 changes: 1 addition & 1 deletion pkg/events/application_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (a *ApplicationResolver) FindApplicationNames(ctx context.Context, event gi
a.Log.Debug(fmt.Sprintf("name: %s | path: %s", name, path))

for _, file := range modified {
if strings.Contains(file, path) {
if strings.Contains(file, path) && app.Spec.Source.RepoURL == event.Repository.HtmlUrl() {
changedApps = append(changedApps, name)
}
}
Expand Down
66 changes: 4 additions & 62 deletions pkg/github/event_metadata.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package github

import (
"encoding/json"
"fmt"

"github.com/google/go-github/v53/github"
"github.com/palantir/go-githubapp/githubapp"
"github.com/pkg/errors"
)

type Action int
Expand All @@ -31,6 +28,10 @@ type Repository struct {
Owner string
}

func (r *Repository) HtmlUrl() string {
return fmt.Sprintf("https://github.com/%s/%s", r.Owner, r.Name)
}

type Actor struct {
Name string
}
Expand Down Expand Up @@ -67,65 +68,6 @@ func (e *Event) HasMessage() bool {
return e.Message != ""
}

func NewEvent(clientCreator githubapp.ClientCreator, eventType string, payload []byte) (Event, error) {
var event Event
var githubEvent GithubEvent
if err := json.Unmarshal(payload, &githubEvent); err != nil {
return event, errors.Wrap(err, "failed to parse event payload")
}

if eventType == "issue_comment" && *githubEvent.Action == "created" {
var comment github.IssueCommentEvent
if err := json.Unmarshal(payload, &comment); err != nil {
return event, errors.Wrap(err, "failed to parse issue comment event payload")
}
// comment.

// comment.GetChanges().Base.SHA.From
// comment.Re

return Event{
Actor: Actor{Name: comment.GetComment().GetUser().GetLogin()},
Action: Comment,
IsPullRequest: comment.GetIssue().IsPullRequest(),
Repository: Repository{
Name: comment.GetRepo().GetName(),
Owner: comment.GetRepo().GetOwner().GetLogin(),
},
PullRequest: PullRequest{
Number: comment.GetIssue().GetNumber(),
},
Message: *comment.GetComment().Body,
InstallationProvider: &comment,
}, nil
}

if eventType == "pull_request" && (*githubEvent.Action == "opened" || *githubEvent.Action == "reopened" || *githubEvent.Action == "ready_for_review") {
var pr github.PullRequestEvent
if err := json.Unmarshal(payload, &pr); err != nil {
return event, errors.Wrap(err, "failed to parse issue comment event payload")
}

return Event{
Actor: Actor{Name: pr.GetPullRequest().GetUser().GetLogin()},
Action: Opened,
IsPullRequest: true,
Revision: *pr.PullRequest.Head.SHA,
Repository: Repository{
Name: pr.GetRepo().GetName(),
Owner: pr.GetRepo().GetOwner().GetLogin(),
},
PullRequest: PullRequest{
Number: pr.GetPullRequest().GetNumber(),
},
Message: "",
InstallationProvider: &pr,
}, nil
}

return event, fmt.Errorf("unsupported event %s %s", eventType, *githubEvent.Action)
}

func InitializeFromIssueComment(source github.IssueCommentEvent, revision string) Event {
return Event{
Actor: Actor{Name: source.GetComment().GetUser().GetLogin()},
Expand Down
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.16.1
0.16.2

0 comments on commit fa520ea

Please sign in to comment.