diff --git a/docs/getting-started/running.mdx b/docs/getting-started/running.mdx index ca603d063..44cdadce1 100644 --- a/docs/getting-started/running.mdx +++ b/docs/getting-started/running.mdx @@ -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 diff --git a/integration_tests/test-issue-tracker-config2.yaml b/integration_tests/test-issue-tracker-config2.yaml index af1da697c..04ef818ba 100644 --- a/integration_tests/test-issue-tracker-config2.yaml +++ b/integration_tests/test-issue-tracker-config2.yaml @@ -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: diff --git a/v2/pkg/reporting/trackers/gitlab/gitlab.go b/v2/pkg/reporting/trackers/gitlab/gitlab.go index b83b4052d..660c9b8e9 100644 --- a/v2/pkg/reporting/trackers/gitlab/gitlab.go +++ b/v2/pkg/reporting/trackers/gitlab/gitlab.go @@ -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,