Compare commits

...

3 Commits

Author SHA1 Message Date
Svilen Markov e3f69864ac
Merge pull request #792 from hudsonbay/feature/repository-draft-prs-exclusion
Add option to exclude draft PRs from repository widget
2025-08-17 05:08:03 +07:00
Manuel Menendez Alfonso b6b4c84f55
Document option to exclude draft pull requests 2025-08-14 12:08:57 +07:00
Manuel Menendez Alfonso 7a2f82cdc6
Add option to exclude draft PRs from repository widget 2025-08-13 12:57:13 +07:00
2 changed files with 19 additions and 2 deletions

@ -2504,6 +2504,7 @@ Example:
pull-requests-limit: 5
issues-limit: 3
commits-limit: 3
exclude-draft-prs: true
```
Preview:
@ -2519,6 +2520,7 @@ Preview:
| pull-requests-limit | integer | no | 3 |
| issues-limit | integer | no | 3 |
| commits-limit | integer | no | -1 |
| exclude-draft-prs | boolean | no | false |
##### `repository`
The owner and repository name that will have their information displayed.
@ -2535,6 +2537,9 @@ The maximum number of latest open issues to show. Set to `-1` to not show any.
##### `commits-limit`
The maximum number of lastest commits to show from the default branch. Set to `-1` to not show any.
##### `exclude-draft-prs`
Wheter to exclude draft pull requests from the list. Set to `false` by default to include them.
### Bookmarks
Display a list of links which can be grouped.

@ -19,6 +19,7 @@ type repositoryWidget struct {
PullRequestsLimit int `yaml:"pull-requests-limit"`
IssuesLimit int `yaml:"issues-limit"`
CommitsLimit int `yaml:"commits-limit"`
ExcludeDraftPRs bool `yaml:"exclude-draft-prs"`
Repository repository `yaml:"-"`
}
@ -47,6 +48,7 @@ func (widget *repositoryWidget) update(ctx context.Context) {
widget.PullRequestsLimit,
widget.IssuesLimit,
widget.CommitsLimit,
widget.ExcludeDraftPRs,
)
if !widget.canContinueUpdateAfterHandlingErr(err) {
@ -111,13 +113,23 @@ type gitHubCommitResponseJson struct {
} `json:"commit"`
}
func fetchRepositoryDetailsFromGithub(repo string, token string, maxPRs int, maxIssues int, maxCommits int) (repository, error) {
func buildPRQuery(repo string, excludeDraftPRs bool) string {
query := fmt.Sprintf("is:pr+is:open+repo:%s", repo)
if excludeDraftPRs {
query += "+-is:draft"
}
return query
}
func fetchRepositoryDetailsFromGithub(repo string, token string, maxPRs int, maxIssues int, maxCommits int, excludeDraftPRs bool) (repository, error) {
repositoryRequest, err := http.NewRequest("GET", fmt.Sprintf("https://api.github.com/repos/%s", repo), nil)
if err != nil {
return repository{}, fmt.Errorf("%w: could not create request with repository: %v", errNoContent, err)
}
PRsRequest, _ := http.NewRequest("GET", fmt.Sprintf("https://api.github.com/search/issues?q=is:pr+is:open+repo:%s&per_page=%d", repo, maxPRs), nil)
prQuery := buildPRQuery(repo, excludeDraftPRs)
PRsRequest, _ := http.NewRequest("GET", fmt.Sprintf("https://api.github.com/search/issues?q=%s&per_page=%d", prQuery, maxPRs), nil)
issuesRequest, _ := http.NewRequest("GET", fmt.Sprintf("https://api.github.com/search/issues?q=is:issue+is:open+repo:%s&per_page=%d", repo, maxIssues), nil)
CommitsRequest, _ := http.NewRequest("GET", fmt.Sprintf("https://api.github.com/repos/%s/commits?per_page=%d", repo, maxCommits), nil)