Skip to content
This repository was archived by the owner on Nov 19, 2026. It is now read-only.
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
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
> [!WARNING]
> **Deprecated: this repository is no longer maintained and will be archived
> (made read-only).** Don't deploy it or build on it.
>
> Google now ingests GitHub webhook events through the GitHub Events Platform
> (GEP). Googlers should use GEP (go/github-events-platform) instead of this
> bridge. The open-source code behind GEP is
> [abcxyz/github-metrics-aggregator](https://github.com/abcxyz/github-metrics-aggregator).
>
> Earlier versions of this code hardcoded a webhook secret. Don't reuse it.
> If you deployed this code, rotate your GitHub webhook secret. The final
> version reads the secret from the `GITHUB_WEBHOOK_SECRET` environment
> variable and rejects every request if it isn't set.

# GitHub Webhook to Google Cloud PubSub Bridge

This does exactly what it says it does.
Expand Down
17 changes: 11 additions & 6 deletions event/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@ package event
import (
"fmt"
"net/http"
"os"
"strings"
"time"

"github.com/google/go-github/v57/github"
)

const (
// secretToken is the secret we currently use from GitHub that lets us verify
// that they actually sent us the request. It's a shared secret between us &
// GitHub.
secretToken = "wkp5H9YShwQkWmV"
// secretTokenEnv names the environment variable holding the webhook secret
// shared with GitHub. There is no default: if it is unset or empty, every
// request is rejected.
secretTokenEnv = "GITHUB_WEBHOOK_SECRET"
signatureHeader = "X-Hub-Signature"
)

Expand All @@ -37,7 +38,11 @@ type Event struct {

// ParseFromRequest returns a parsed Event from the incoming HTTP webhook payload.
func ParseFromRequest(r *http.Request, received time.Time) (*Event, error) {
payload, err := github.ValidatePayload(r, []byte(secretToken))
secret := os.Getenv(secretTokenEnv)
if secret == "" {
return nil, fmt.Errorf("%s is not set; refusing to accept webhooks", secretTokenEnv)
}
payload, err := github.ValidatePayload(r, []byte(secret))
if err != nil {
return nil, fmt.Errorf("error validating payload: %v", err)
}
Expand Down Expand Up @@ -84,7 +89,7 @@ func parseRepository(wht string, payload []byte) (*RepoInfo, error) {
switch ev := ev.(type) {
case *github.OrganizationEvent:
return &RepoInfo{
IsPrivate: false,
IsPrivate: true,
Name: "",
OwnerName: "",
OrganizationName: ev.GetOrganization().GetLogin(),
Expand Down
Loading