Gitlab tracker: Duplicate issues (#4152)

* Added initial API docs

* dark mode fixes!

* gitlab tracker duplicate check

* integration test

* added In to search to restrict to title match

* added example GitLab yaml

---------

Co-authored-by: sandeep <8293321+ehsandeep@users.noreply.github.com>
dev
Stefan Kahn 2023-09-26 06:25:12 +13:00 committed by GitHub
parent 5ffe890c00
commit 0137a40a35
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 48 additions and 0 deletions

View File

@ -690,6 +690,21 @@ github:
issue-label: 'Nuclei'
```
Alternatively if you use GitLab, create a config file following content and replace the appropriate values:
```yaml
# GitLab contains configuration options for GitLab issue tracker
gitlab:
username: '$user'
base-url: 'gitlab.com'
token: '$token'
project-name: 'testing-project'
issue-label: 'nuclei-label'
severity-as-label: true
duplicate-issue-check: true
```
To store results in Elasticsearch, create a config file with the following content and replace the appropriate values:
```yaml

View File

@ -32,6 +32,8 @@ gitLab:
project-name: "1234"
# issue-label is the label of the created issue type
issue-label: bug
# duplicate-issue-check flag to enable duplicate tracking issue check.
duplicate-issue-check: true
# Jira contains configuration options for Jira issue tracker
jira:

View File

@ -33,6 +33,8 @@ type Options struct {
// SeverityAsLabel (optional) sends the severity as the label of the created
// issue.
SeverityAsLabel bool `yaml:"severity-as-label"`
// DuplicateIssueCheck is a bool to enable duplicate tracking issue check and update the newest
DuplicateIssueCheck bool `yaml:"duplicate-issue-check" default:"false"`
HttpClient *retryablehttp.Client `yaml:"-"`
}
@ -71,6 +73,35 @@ func (i *Integration) CreateIssue(event *output.ResultEvent) error {
}
customLabels := gitlab.Labels(labels)
assigneeIDs := []int{i.userID}
if i.options.DuplicateIssueCheck {
searchIn := "title"
searchState := "all"
issues, _, err := i.client.Issues.ListProjectIssues(i.options.ProjectName, &gitlab.ListProjectIssuesOptions{
In: &searchIn,
State: &searchState,
Search: &summary,
})
if err != nil {
return err
}
if len(issues) > 0 {
issue := issues[0]
_, _, err := i.client.Notes.CreateIssueNote(i.options.ProjectName, issue.IID, &gitlab.CreateIssueNoteOptions{
Body: &description,
})
if err != nil {
return err
}
if issue.State == "closed" {
reopen := "reopen"
_, resp, err := i.client.Issues.UpdateIssue(i.options.ProjectName, issue.IID, &gitlab.UpdateIssueOptions{
StateEvent: &reopen,
})
fmt.Sprintln(resp, err)
}
return err
}
}
_, _, err := i.client.Issues.CreateIssue(i.options.ProjectName, &gitlab.CreateIssueOptions{
Title: &summary,
Description: &description,