Skip to content

Commit a7df697

Browse files
authored
fix(trackers): paginate gitea to find all issues when searching for duplicates (#6707)
* (fix) paginate to find all issues when searching for duplicates * (feat) add configurable limits for perpage and total pages
1 parent 746a05d commit a7df697

File tree

2 files changed

+45
-12
lines changed

2 files changed

+45
-12
lines changed

cmd/nuclei/issue-tracker-config.yaml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@
8181
# severity: low
8282
# # duplicate-issue-check (optional) flag to enable duplicate tracking issue check
8383
# duplicate-issue-check: false
84+
# # duplicate-issue-page-size (optional) controls how many issues to fetch per page when searching for duplicates
85+
# duplicate-issue-page-size: 100
86+
# # duplicate-issue-max-pages (optional) limits how many pages to fetch when searching for duplicates (0 = no limit)
87+
# duplicate-issue-max-pages: 0
8488
#
8589
# Jira contains configuration options for Jira issue tracker
8690
#jira:
@@ -118,10 +122,10 @@
118122
# status-not: Closed
119123
# # Customfield supports name, id and freeform. name and id are to be used when the custom field is a dropdown.
120124
# # freeform can be used if the custom field is just a text entry
121-
# # Variables can be used to pull various pieces of data from the finding itself.
125+
# # Variables can be used to pull various pieces of data from the finding itself.
122126
# # Supported variables: $CVSSMetrics, $CVEID, $CWEID, $Host, $Severity, $CVSSScore, $Name
123127
# custom-fields:
124-
# customfield_00001:
128+
# customfield_00001:
125129
# name: "Nuclei"
126130
# customfield_00002:
127131
# freeform: $CVSSMetrics
@@ -172,4 +176,4 @@
172176
# omit-raw: false
173177
# # determines the number of results to be kept in memory before writing it to the database or 0 to
174178
# # persist all in memory and write all results at the end (default)
175-
# batch-size: 0
179+
# batch-size: 0

pkg/reporting/trackers/gitea/gitea.go

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ type Options struct {
4242
DenyList *filters.Filter `yaml:"deny-list"`
4343
// DuplicateIssueCheck is a bool to enable duplicate tracking issue check and update the newest
4444
DuplicateIssueCheck bool `yaml:"duplicate-issue-check" default:"false"`
45+
// DuplicateIssuePageSize controls how many issues are fetched per page when searching for duplicates.
46+
// If unset or <=0, a default of 100 is used.
47+
DuplicateIssuePageSize int `yaml:"duplicate-issue-page-size" default:"100"`
48+
// DuplicateIssueMaxPages limits how many pages are fetched when searching for duplicates.
49+
// If unset or <=0, all pages are fetched until exhaustion.
50+
DuplicateIssueMaxPages int `yaml:"duplicate-issue-max-pages" default:"0"`
4551

4652
HttpClient *retryablehttp.Client `yaml:"-"`
4753
OmitRaw bool `yaml:"-"`
@@ -151,21 +157,44 @@ func (i *Integration) ShouldFilter(event *output.ResultEvent) bool {
151157
}
152158

153159
func (i *Integration) findIssueByTitle(title string) (*gitea.Issue, error) {
160+
// Fetch issues in pages to ensure older issues are also checked for duplicates.
161+
pageSize := i.options.DuplicateIssuePageSize
162+
if pageSize <= 0 {
163+
pageSize = 100
164+
}
165+
maxPages := i.options.DuplicateIssueMaxPages
154166

155-
issueList, _, err := i.client.ListRepoIssues(i.options.ProjectOwner, i.options.ProjectName, gitea.ListIssueOption{
167+
opts := gitea.ListIssueOption{
156168
State: "all",
157-
})
158-
if err != nil {
159-
return nil, err
169+
ListOptions: gitea.ListOptions{
170+
Page: 1,
171+
PageSize: pageSize,
172+
},
160173
}
161174

162-
for _, issue := range issueList {
163-
if issue.Title == title {
164-
return issue, nil
175+
for {
176+
if maxPages > 0 && opts.Page > maxPages {
177+
return nil, nil
165178
}
166-
}
167179

168-
return nil, nil
180+
issueList, _, err := i.client.ListRepoIssues(i.options.ProjectOwner, i.options.ProjectName, opts)
181+
if err != nil {
182+
return nil, err
183+
}
184+
185+
for _, issue := range issueList {
186+
if issue.Title == title {
187+
return issue, nil
188+
}
189+
}
190+
191+
if len(issueList) < opts.PageSize {
192+
// Last page reached.
193+
return nil, nil
194+
}
195+
196+
opts.Page++
197+
}
169198
}
170199

171200
func (i *Integration) getLabelIDsByNames(labels []string) ([]int64, error) {

0 commit comments

Comments
 (0)