mirror of
https://github.com/projectdiscovery/nuclei.git
synced 2026-02-13 05:53:25 +08:00
feat: issue tracker URLs in JSON + misc fixes (#4855)
* feat: issue tracker URLs in JSON + misc fixes * misc changes * feat: status update support for issues * feat: report metadata generation hook support * feat: added CLI summary of tickets created * misc changes
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/google/go-github/github"
|
||||
@@ -85,7 +86,7 @@ func New(options *Options) (*Integration, error) {
|
||||
}
|
||||
|
||||
// CreateIssue creates an issue in the tracker
|
||||
func (i *Integration) CreateIssue(event *output.ResultEvent) (err error) {
|
||||
func (i *Integration) CreateIssue(event *output.ResultEvent) (*filters.CreateIssueResponse, error) {
|
||||
summary := format.Summary(event)
|
||||
description := format.CreateReportDescription(event, util.MarkdownFormatter{}, i.options.OmitRaw)
|
||||
labels := []string{}
|
||||
@@ -99,11 +100,12 @@ func (i *Integration) CreateIssue(event *output.ResultEvent) (err error) {
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
var err error
|
||||
var existingIssue *github.Issue
|
||||
if i.options.DuplicateIssueCheck {
|
||||
existingIssue, err = i.findIssueByTitle(ctx, summary)
|
||||
if err != nil && !errors.Is(err, io.EOF) {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,15 +116,21 @@ func (i *Integration) CreateIssue(event *output.ResultEvent) (err error) {
|
||||
Labels: &labels,
|
||||
Assignees: &[]string{i.options.Username},
|
||||
}
|
||||
_, _, err = i.client.Issues.Create(ctx, i.options.Owner, i.options.ProjectName, req)
|
||||
return err
|
||||
createdIssue, _, err := i.client.Issues.Create(ctx, i.options.Owner, i.options.ProjectName, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &filters.CreateIssueResponse{
|
||||
IssueID: strconv.FormatInt(createdIssue.GetID(), 10),
|
||||
IssueURL: createdIssue.GetHTMLURL(),
|
||||
}, nil
|
||||
} else {
|
||||
if existingIssue.GetState() == "closed" {
|
||||
stateOpen := "open"
|
||||
if _, _, err := i.client.Issues.Edit(ctx, i.options.Owner, i.options.ProjectName, *existingIssue.Number, &github.IssueRequest{
|
||||
State: &stateOpen,
|
||||
}); err != nil {
|
||||
return fmt.Errorf("error reopening issue %d: %s", *existingIssue.Number, err)
|
||||
return nil, fmt.Errorf("error reopening issue %d: %s", *existingIssue.Number, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,8 +138,39 @@ func (i *Integration) CreateIssue(event *output.ResultEvent) (err error) {
|
||||
Body: &description,
|
||||
}
|
||||
_, _, err = i.client.Issues.CreateComment(ctx, i.options.Owner, i.options.ProjectName, *existingIssue.Number, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &filters.CreateIssueResponse{
|
||||
IssueID: strconv.FormatInt(existingIssue.GetID(), 10),
|
||||
IssueURL: existingIssue.GetHTMLURL(),
|
||||
}, nil
|
||||
}
|
||||
}
|
||||
|
||||
func (i *Integration) CloseIssue(event *output.ResultEvent) error {
|
||||
ctx := context.Background()
|
||||
summary := format.Summary(event)
|
||||
|
||||
existingIssue, err := i.findIssueByTitle(ctx, summary)
|
||||
if err != nil && !errors.Is(err, io.EOF) {
|
||||
return err
|
||||
}
|
||||
if existingIssue == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
stateClosed := "closed"
|
||||
if _, _, err := i.client.Issues.Edit(ctx, i.options.Owner, i.options.ProjectName, *existingIssue.Number, &github.IssueRequest{
|
||||
State: &stateClosed,
|
||||
}); err != nil {
|
||||
return fmt.Errorf("error closing issue %d: %s", *existingIssue.Number, err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (i *Integration) Name() string {
|
||||
return "github"
|
||||
}
|
||||
|
||||
// ShouldFilter determines if an issue should be logged to this tracker
|
||||
|
||||
Reference in New Issue
Block a user