Convert github source to cloud events.#340
Conversation
|
|
||
| - dev.knative.github.pullrequest | ||
|
|
||
| Uses two images, the feedlet and the receive adapter. |
There was a problem hiding this comment.
Does the github source require any parameters to be set? If so, what do they mean?
| } | ||
| switch eventType { | ||
| case "pullrequest": | ||
| case pullrequestEvent: |
There was a problem hiding this comment.
This feels like it should be a map[string]string, or a map[string][]string, rather than a switch.
Using a map would also make it easier to report the known event types on line 462.
| source := pl.PullRequest.HTMLURL | ||
|
|
||
| var eventType string | ||
| if len(header["X-GitHub-Event"]) == 1 { |
There was a problem hiding this comment.
Try:
// global
ceTypes = map[string]string{"pull_request": github.PullrequestEvent, "": "unknown"}
...
eventType := ceTypes[header.Get("x-github-event")]|
|
||
| } | ||
|
|
||
| eventID := "unknown" |
|
|
||
| } | ||
|
|
||
| eventID := "unknown" |
There was a problem hiding this comment.
Also, should this be a UUID or something if not supplied, rather than a deterministic value?
| return err | ||
| } | ||
|
|
||
| func postMessage(target string, m *gh.PullRequestPayload, source, eventType, eventID string) error { |
There was a problem hiding this comment.
If you leave m as an interface{}, can you avoid the cast in 59 (which could panic), and support multiple payload types idiomatically? (This may not work, I haven't tested.)
| } | ||
| defer resp.Body.Close() | ||
| log.Printf("Error: response Status: %s", resp.Status) | ||
| log.Printf("response Status: %s", resp.Status) |
There was a problem hiding this comment.
Do we want to/should we log these?
There was a problem hiding this comment.
I moved it to only log on error.
|
/retest |
2 similar comments
|
/retest |
|
/retest |
|
|
||
| ``` | ||
|
|
||
| The Feedlet requires a ServiceAccount to run as a cluster admin for the targeted namespace: |
There was a problem hiding this comment.
It's unfortunate that we can't put this in a yaml file somewhere to happen at the same time as the controller is installed/the source is created.
| "": UnsupportedEvent, | ||
| } | ||
|
|
||
| var GithubEventType = map[string]string{ |
There was a problem hiding this comment.
Is this just the reverse of CloudEventType?
There was a problem hiding this comment.
yes, is there a better way?
There was a problem hiding this comment.
Build it automatically, like:
var GithubEventType map[string]string
for k, v := range(CloudEventType) {
GitHubEventType[v] = k
}| kind: EventType | ||
| metadata: | ||
| name: pullrequest | ||
| name: dev.knative.github.pullrequest |
There was a problem hiding this comment.
Self-registration would make it easier to make this name align with the one in events.go
| // TODO: Add more supported event types. | ||
| default: | ||
| event, ok := github.GithubEventType[eventType] | ||
| if !ok { |
There was a problem hiding this comment.
You may also be able to check if event == ""
| pl := payload.(github.PullRequestPayload) | ||
| postMessage(h.target, &pl) | ||
|
|
||
| hdr := http.Header(header) |
There was a problem hiding this comment.
I think a webhooks.Header is an http.Header, so it should already have .Get().
There was a problem hiding this comment.
I do not have access to .Get() from the webhooks.Header object for some reason, it was a compile error when I was trying.
There was a problem hiding this comment.
Aha -- http.Header is an http.Header, which is a map[string[]string. But since it has a different type name, methods which take an http.Header as a receiver don't apply to webhooks.Header.
So glad they "minimize imports": https://github.com/go-playground/webhooks/blob/v3.13.0/webhooks.go#L8
It looks like this declaration was removed in v5.
|
|
||
| source := pl.PullRequest.HTMLURL | ||
|
|
||
| eventType, ok := github.CloudEventType[hdr.Get("X-GitHub-Event")] |
There was a problem hiding this comment.
github.CloudEventType should map "" to UnsupportedEvent
There was a problem hiding this comment.
It does, this catches all other github events that have a real name but are not "" and "pull_request"
There was a problem hiding this comment.
Ah, right. I was thinking about the "header missing" case.
| // TODO: in general, receive adapters may have to be able to retry for error cases. | ||
| log.Printf("response Status: %s", resp.Status) | ||
| body, _ := ioutil.ReadAll(resp.Body) | ||
| log.Printf("response Body: %s", string(body)) |
There was a problem hiding this comment.
If this is a 500, should we return an error?
There was a problem hiding this comment.
/idk
There are some questions here that are bigger than this PR around what the Receive Adapter should do if it gets an error from the "action". Should it try again? How many times?...
|
Grant for LGTM: Evan for Approval: |
| "": UnsupportedEvent, | ||
| } | ||
|
|
||
| var GithubEventType = map[string]string{ |
There was a problem hiding this comment.
Build it automatically, like:
var GithubEventType map[string]string
for k, v := range(CloudEventType) {
GitHubEventType[v] = k
}| pl := payload.(github.PullRequestPayload) | ||
| postMessage(h.target, &pl) | ||
|
|
||
| hdr := http.Header(header) |
There was a problem hiding this comment.
Aha -- http.Header is an http.Header, which is a map[string[]string. But since it has a different type name, methods which take an http.Header as a receiver don't apply to webhooks.Header.
So glad they "minimize imports": https://github.com/go-playground/webhooks/blob/v3.13.0/webhooks.go#L8
It looks like this declaration was removed in v5.
|
|
||
| source := pl.PullRequest.HTMLURL | ||
|
|
||
| eventType, ok := github.CloudEventType[hdr.Get("X-GitHub-Event")] |
There was a problem hiding this comment.
Ah, right. I was thinking about the "header missing" case.
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: evankanderson, n3wscott The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
* Convert github source to cloud events. * Add more words to the readme. * Use cloud event map and updat the readme.
* Added hostnames to tls certificates * Update broker-filter-tls-certificate.yaml --------- Signed-off-by: Calum Murray <cmurray@redhat.com> Co-authored-by: Pierangelo Di Pilato <pierangelodipilato@gmail.com>
This is a followup to #276. The focus is to migrate the Source and Sample to use the cloudevent naming style and the eventing framework.
Fixes #334
Fixes #332