Skip to content

Commit

Permalink
github-events: set repo name as event subject (chainguard-dev#464)
Browse files Browse the repository at this point in the history
Signed-off-by: Jason Hall <jason@chainguard.dev>
  • Loading branch information
imjasonh authored Jul 25, 2024
1 parent 5eed651 commit 03789aa
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions modules/github-events/cmd/trampoline/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,23 @@ func main() {
log = log.With("event-type", t)
log.Debugf("forwarding event: %s", t)

// Extract the organization and repo name from the request body, to set in the subject.
// This enables subscribers to filter on the subject if they only care about certain repos.
var body struct {
Repo struct {
FullName string `json:"full_name"`
} `json:"repository"`
}
if err := json.Unmarshal(payload, &body); err != nil {
log.Errorf("failed to unmarshal payload: %v", err)
w.WriteHeader(http.StatusBadRequest)
return
}

event := cloudevents.NewEvent()
event.SetType(t)
event.SetSource(r.Host)
// TODO: Extract organization and repo to set in subject, for better filtering.
// event.SetSubject(fmt.Sprintf("%s/%s", org, repo))
event.SetSubject(body.Repo.FullName)
if err := event.SetData(cloudevents.ApplicationJSON, struct {
When time.Time `json:"when"`
Body json.RawMessage `json:"body"`
Expand Down

0 comments on commit 03789aa

Please sign in to comment.