Skip to content

Commit

Permalink
Add github/pull_author_login as a property for PRs (#4535)
Browse files Browse the repository at this point in the history
This allows us to write selectors like:
```
selection:
  - entity: pull_request
    selector: pull_request.properties['github/pull_author_login'] != 'jhrozek'
    comment: "We trust Jakub. Don't check his PRs"
```
  • Loading branch information
jhrozek authored Sep 18, 2024
1 parent 4666fb5 commit 8a591d6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
15 changes: 8 additions & 7 deletions docs/docs/how-to/profile_selectors.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,14 @@ Selectors for repositories allow you to filter and manage repositories based on

## Pull request properties set by the GitHub provider

| Field | Description | Type |
|-------------------------|-----------------------------------------|--------|
| `github/pull_url` | The URL of the pull request | string |
| `github/pull_number` | The number of the pull request | string |
| `github/pull_author_id` | The author of the pull request | string |
| `github/repo_name` | The github repo name (e.g. `stacklok`). | string |
| `github/repo_owner` | The github repo owner (e.g. `minder`). | string |
| Field | Description | Type |
|----------------------------|----------------------------------------------------|--------|
| `github/pull_url` | The URL of the pull request | string |
| `github/pull_number` | The number of the pull request | string |
| `github/pull_author_id` | The numerical ID of the author of the pull request | int |
| `github/pull_author_login` | The github login of the author of the pull request | string |
| `github/repo_name` | The github repo name (e.g. `stacklok`). | string |
| `github/repo_owner` | The github repo owner (e.g. `minder`). | string |

## Entity provider selectors

Expand Down
14 changes: 9 additions & 5 deletions internal/providers/github/properties/pull_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ const (
PullPropertyRepoName = "github/repo_name"
// PullPropertyAuthorID is the ID of the author of the pull request
PullPropertyAuthorID = "github/pull_author_id"
// PullPropertyAuthorLogin is the login of the author of the pull request
PullPropertyAuthorLogin = "github/pull_author_login"
// PullPropertyAction is an operational property that represents the action that was taken on the pull request
PullPropertyAction = "github/pull_action"
)
Expand All @@ -61,6 +63,7 @@ var prPropertyDefinitions = []propertyOrigin{
PullPropertyRepoOwner,
PullPropertyRepoName,
PullPropertyAuthorID,
PullPropertyAuthorLogin,
PullPropertyAction,
},
wrapper: getPrWrapper,
Expand Down Expand Up @@ -152,11 +155,12 @@ func getPrWrapper(
// github-specific
PullPropertyURL: prReply.GetHTMLURL(),
// our proto representation uses int64 for the number but GH uses int
PullPropertyNumber: int64(prReply.GetNumber()),
PullPropertySha: prReply.GetHead().GetSHA(),
PullPropertyRepoOwner: owner,
PullPropertyRepoName: name,
PullPropertyAuthorID: prReply.GetUser().GetID(),
PullPropertyNumber: int64(prReply.GetNumber()),
PullPropertySha: prReply.GetHead().GetSHA(),
PullPropertyRepoOwner: owner,
PullPropertyRepoName: name,
PullPropertyAuthorID: prReply.GetUser().GetID(),
PullPropertyAuthorLogin: prReply.GetUser().GetLogin(),
}

return prProps, nil
Expand Down

0 comments on commit 8a591d6

Please sign in to comment.