Skip to content

Commit

Permalink
Change the label names for customizing org and/or repo
Browse files Browse the repository at this point in the history
The current label names used for customizing GitHub organization and/or
repository are `org` and `repo`, which are generic names that may be
unintentionally targeted by this feature. To avoid this, add the `atg_`
prefix and make it work only when intended.
  • Loading branch information
superbrothers committed Aug 23, 2022
1 parent 6ac76d5 commit 0e8af6a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ Issue title and body are rendered from [Go template](https://golang.org/pkg/text
- `json`: Marshal an object to JSON string
- `timeNow`: Get current time

## Customize organisation and repository
## Customize organization and repository

The organisation/repository where issues are raised can be customised per-alert by specifying the `owner` and/or `repo` labels on the alert.
The organization/repository where issues are raised can be customized per-alert by specifying the `atg_owner` label for the organization and/or the `atg_repo` label for the repository on the alert.

e.g.

Expand All @@ -101,8 +101,8 @@ e.g.
for: 10m
labels:
severity: page
org: my-alternative-org
repo: specific-service-repository
atg_owner: my-alternative-org
atg_repo: specific-service-repository
annotations:
summary: High request latency
```
Expand Down
13 changes: 9 additions & 4 deletions pkg/notifier/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ import (
"github.com/rs/zerolog/log"
)

const (
ownerLabelName = "atg_owner"
repoLabelName = "atg_repo"
)

var (
rateLimit = promauto.NewGaugeVec(
prometheus.GaugeOpts{
Expand Down Expand Up @@ -70,11 +75,11 @@ func resolveRepository(payload *types.WebhookPayload, queryParams url.Values) (e
owner := queryParams.Get("owner")
repo := queryParams.Get("repo")

if payload.CommonLabels["owner"] != "" {
owner = payload.CommonLabels["owner"]
if payload.CommonLabels[ownerLabelName] != "" {
owner = payload.CommonLabels[ownerLabelName]
}
if payload.CommonLabels["repo"] != "" {
repo = payload.CommonLabels["repo"]
if payload.CommonLabels[repoLabelName] != "" {
repo = payload.CommonLabels[repoLabelName]
}
if owner == "" {
return fmt.Errorf("owner was not specified in either the webhook URL, or the alert labels"), "", ""
Expand Down

0 comments on commit 0e8af6a

Please sign in to comment.