diff --git a/README.md b/README.md index 1d0ed7d..ec0f0d6 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,8 @@ Use the binaries from [the release page](https://github.com/snyk-tech-services/j -severity= // Optional. Severity threshold to open tickets for. Defaults to low. -maturityFilter=[mature,proof-of-concept,no-known-exploit,no-data] // Optional. include only maturity level(s). Separated by commas -type= // Optional. Issue type to open tickets for. Defaults to all. - -assigneeId=<123abc456def789> // Optional. Jira ID of user to assign tickets to. + -assigneeId=<123abc456def789> // Optional. Jira ID of user to assign tickets to. Note: Do not use assigneeName and assigneeId at the same time + -assigneeName= // Optional. Jira Name of user to assign tickets to. Note: Do not use assigneeName and assigneeId at the same time -priorityIsSeverity // Optional. Set the ticket priority to be based on severity (defaults: Low|Medium|High|Critical=>Low|Medium|High|Highest) -labels=,IssueLabel2 // Optional. Set JIRA ticket labels -priorityScoreThreshold=[0-1000] // Optional. Your min priority score threshold diff --git a/fixtures/results/jiraTicketWithCustomPriorityMapping.json b/fixtures/results/jiraTicketWithCustomPriorityMapping.json index ce3d3cb..2e6888a 100644 --- a/fixtures/results/jiraTicketWithCustomPriorityMapping.json +++ b/fixtures/results/jiraTicketWithCustomPriorityMapping.json @@ -1 +1 @@ -{"fields":{"project":{"id":"123"},"summary":"snyk-playground/typescript:package.json - Remote Code Execution (RCE)","description":"*Impacted Paths:*\n\\- \"snyk\"@\"1.228.3\" =\u003e \"proxy\\-agent\"@\"3.1.0\" =\u003e \"pac\\-proxy\\-agent\"@\"3.0.0\" =\u003e \"pac\\-resolver\"@\"3.0.0\"\n\n[See this issue on Snyk|https://app.snyk.io/org/playground/project/12345678-1234-1234-1234-123456789012]\n\n[More About this issue|https://snyk.io/vuln/SNYK-JS-MINIMIST-559764]\n\n","issuetype":{"name":"Bug"},"assignee":{},"priority":{"name":"not too bad"}}} \ No newline at end of file +{"fields":{"project":{"id":"123"},"summary":"snyk-playground/typescript:package.json - Remote Code Execution (RCE)","description":"*Impacted Paths:*\n\\- \"snyk\"@\"1.228.3\" =\u003e \"proxy\\-agent\"@\"3.1.0\" =\u003e \"pac\\-proxy\\-agent\"@\"3.0.0\" =\u003e \"pac\\-resolver\"@\"3.0.0\"\n\n[See this issue on Snyk|https://app.snyk.io/org/playground/project/12345678-1234-1234-1234-123456789012]\n\n[More About this issue|https://snyk.io/vuln/SNYK-JS-MINIMIST-559764]\n\n","issuetype":{"name":"Bug"},"priority":{"name":"not too bad"}}} \ No newline at end of file diff --git a/fixtures/results/jiraTicketWithLabels.json b/fixtures/results/jiraTicketWithLabels.json index 1b64816..064e6f2 100644 --- a/fixtures/results/jiraTicketWithLabels.json +++ b/fixtures/results/jiraTicketWithLabels.json @@ -1 +1 @@ -{"fields":{"project":{"id":"123"},"summary":"snyk-playground/typescript:package.json - Remote Code Execution (RCE)","description":"*Impacted Paths:*\n\\- \"snyk\"@\"1.228.3\" =\u003e \"proxy\\-agent\"@\"3.1.0\" =\u003e \"pac\\-proxy\\-agent\"@\"3.0.0\" =\u003e \"pac\\-resolver\"@\"3.0.0\"\n\n[See this issue on Snyk|https://app.snyk.io/org/playground/project/12345678-1234-1234-1234-123456789012]\n\n[More About this issue|https://snyk.io/vuln/SNYK-JS-MINIMIST-559764]\n\n","issuetype":{"name":"Bug"},"assignee":{},"labels":["Label1","Label2"]}} \ No newline at end of file +{"fields":{"project":{"id":"123"},"summary":"snyk-playground/typescript:package.json - Remote Code Execution (RCE)","description":"*Impacted Paths:*\n\\- \"snyk\"@\"1.228.3\" =\u003e \"proxy\\-agent\"@\"3.1.0\" =\u003e \"pac\\-proxy\\-agent\"@\"3.0.0\" =\u003e \"pac\\-resolver\"@\"3.0.0\"\n\n[See this issue on Snyk|https://app.snyk.io/org/playground/project/12345678-1234-1234-1234-123456789012]\n\n[More About this issue|https://snyk.io/vuln/SNYK-JS-MINIMIST-559764]\n\n","issuetype":{"name":"Bug"},"labels":["Label1","Label2"]}} \ No newline at end of file diff --git a/fixtures/results/jiraTicketWithPriorityMapping.json b/fixtures/results/jiraTicketWithPriorityMapping.json index a854b15..f8fda3a 100644 --- a/fixtures/results/jiraTicketWithPriorityMapping.json +++ b/fixtures/results/jiraTicketWithPriorityMapping.json @@ -1 +1 @@ -{"fields":{"project":{"id":"123"},"summary":"snyk-playground/typescript:package.json - Remote Code Execution (RCE)","description":"*Impacted Paths:*\n\\- \"snyk\"@\"1.228.3\" =\u003e \"proxy\\-agent\"@\"3.1.0\" =\u003e \"pac\\-proxy\\-agent\"@\"3.0.0\" =\u003e \"pac\\-resolver\"@\"3.0.0\"\n\n[See this issue on Snyk|https://app.snyk.io/org/playground/project/12345678-1234-1234-1234-123456789012]\n\n[More About this issue|https://snyk.io/vuln/SNYK-JS-MINIMIST-559764]\n\n","issuetype":{"name":"Bug"},"assignee":{},"priority":{"name":"Medium"}}} \ No newline at end of file +{"fields":{"project":{"id":"123"},"summary":"snyk-playground/typescript:package.json - Remote Code Execution (RCE)","description":"*Impacted Paths:*\n\\- \"snyk\"@\"1.228.3\" =\u003e \"proxy\\-agent\"@\"3.1.0\" =\u003e \"pac\\-proxy\\-agent\"@\"3.0.0\" =\u003e \"pac\\-resolver\"@\"3.0.0\"\n\n[See this issue on Snyk|https://app.snyk.io/org/playground/project/12345678-1234-1234-1234-123456789012]\n\n[More About this issue|https://snyk.io/vuln/SNYK-JS-MINIMIST-559764]\n\n","issuetype":{"name":"Bug"},"priority":{"name":"Medium"}}} \ No newline at end of file diff --git a/fixtures/results/jiraTicketWithoutLabels.json b/fixtures/results/jiraTicketWithoutLabels.json index 5ee878f..680e0d2 100644 --- a/fixtures/results/jiraTicketWithoutLabels.json +++ b/fixtures/results/jiraTicketWithoutLabels.json @@ -1 +1 @@ -{"fields":{"project":{"id":"123"},"summary":"snyk-playground/typescript:package.json - Remote Code Execution (RCE)","description":"*Impacted Paths:*\n\\- \"snyk\"@\"1.228.3\" =\u003e \"proxy\\-agent\"@\"3.1.0\" =\u003e \"pac\\-proxy\\-agent\"@\"3.0.0\" =\u003e \"pac\\-resolver\"@\"3.0.0\"\n\n[See this issue on Snyk|https://app.snyk.io/org/playground/project/12345678-1234-1234-1234-123456789012]\n\n[More About this issue|https://snyk.io/vuln/SNYK-JS-MINIMIST-559764]\n\n","issuetype":{"name":"Bug"},"assignee":{}}} \ No newline at end of file +{"fields":{"project":{"id":"123"},"summary":"snyk-playground/typescript:package.json - Remote Code Execution (RCE)","description":"*Impacted Paths:*\n\\- \"snyk\"@\"1.228.3\" =\u003e \"proxy\\-agent\"@\"3.1.0\" =\u003e \"pac\\-proxy\\-agent\"@\"3.0.0\" =\u003e \"pac\\-resolver\"@\"3.0.0\"\n\n[See this issue on Snyk|https://app.snyk.io/org/playground/project/12345678-1234-1234-1234-123456789012]\n\n[More About this issue|https://snyk.io/vuln/SNYK-JS-MINIMIST-559764]\n\n","issuetype":{"name":"Bug"}}} \ No newline at end of file diff --git a/fixtures/results/jiraTicketWithoutLabelsWithAssigneeID.json b/fixtures/results/jiraTicketWithoutLabelsWithAssigneeID.json new file mode 100644 index 0000000..ff5c6f4 --- /dev/null +++ b/fixtures/results/jiraTicketWithoutLabelsWithAssigneeID.json @@ -0,0 +1 @@ +{"fields":{"project":{"id":"123"},"summary":"snyk-playground/typescript:package.json - Remote Code Execution (RCE)","description":"*Impacted Paths:*\n\\- \"snyk\"@\"1.228.3\" =\u003e \"proxy\\-agent\"@\"3.1.0\" =\u003e \"pac\\-proxy\\-agent\"@\"3.0.0\" =\u003e \"pac\\-resolver\"@\"3.0.0\"\n\n[See this issue on Snyk|https://app.snyk.io/org/playground/project/12345678-1234-1234-1234-123456789012]\n\n[More About this issue|https://snyk.io/vuln/SNYK-JS-MINIMIST-559764]\n\n","issuetype":{"name":"Bug"},"assignee":{"accountId":"12345"}}} \ No newline at end of file diff --git a/fixtures/results/jiraTicketWithoutLabelsWithAssigneeName.json b/fixtures/results/jiraTicketWithoutLabelsWithAssigneeName.json new file mode 100644 index 0000000..7b45d6b --- /dev/null +++ b/fixtures/results/jiraTicketWithoutLabelsWithAssigneeName.json @@ -0,0 +1 @@ +{"fields":{"project":{"id":"123"},"summary":"snyk-playground/typescript:package.json - Remote Code Execution (RCE)","description":"*Impacted Paths:*\n\\- \"snyk\"@\"1.228.3\" =\u003e \"proxy\\-agent\"@\"3.1.0\" =\u003e \"pac\\-proxy\\-agent\"@\"3.0.0\" =\u003e \"pac\\-resolver\"@\"3.0.0\"\n\n[See this issue on Snyk|https://app.snyk.io/org/playground/project/12345678-1234-1234-1234-123456789012]\n\n[More About this issue|https://snyk.io/vuln/SNYK-JS-MINIMIST-559764]\n\n","issuetype":{"name":"Bug"},"assignee":{"name":"admin"}}} \ No newline at end of file diff --git a/jira.go b/jira.go index a0d8625..5d44422 100644 --- a/jira.go +++ b/jira.go @@ -17,6 +17,7 @@ type JiraIssue struct { Fields Field `json:"fields"` } +// Some info on ommit : https://www.sohamkamani.com/golang/omitempty/#values-that-cannot-be-omitted type PriorityType struct { Name string `json:"name,omitempty"` } @@ -27,14 +28,15 @@ type Field struct { Summary string `json:"summary"` Description string `json:"description"` IssueTypes IssueType `json:"issuetype"` - Assignees Assignee `json:"assignee,omitempty"` + Assignees *Assignee `json:"assignee,omitempty"` Priority *PriorityType `json:"priority,omitempty"` Labels []string `json:"labels,omitempty"` } // Assignee is the account ID of the JIRA user to assign tickets to type Assignee struct { - ID string `json:"accountId,omitempty"` + Name string `json:"name,omitempty"` + AccountId string `json:"accountId,omitempty"` } // Project is the JIRA project ID @@ -68,7 +70,7 @@ func getJiraTickets(endpointAPI string, orgID string, projectID string, token st return tickRefs } -func openJiraTicket(endpointAPI string, orgID string, token string, jiraProjectID string, jiraTicketType string, assigneeID string, labels string, projectInfo jsn.Json, vulnForJira interface{}, priorityIsSeverity bool) ([]byte, error) { +func openJiraTicket(endpointAPI string, orgID string, token string, jiraProjectID string, jiraTicketType string, assigneeName string, assigneeID string, labels string, projectInfo jsn.Json, vulnForJira interface{}, priorityIsSeverity bool) ([]byte, error) { jsonVuln, _ := jsn.NewJson(vulnForJira) vulnID := jsonVuln.K("id").String().Value @@ -77,7 +79,6 @@ func openJiraTicket(endpointAPI string, orgID string, token string, jiraProjectI jiraTicket.Fields.Projects.ID = jiraProjectID jiraTicket.Fields.IssueTypes.Name = jiraTicketType - jiraTicket.Fields.Assignees.ID = assigneeID projectInfoId := projectInfo.K("id").String().Value @@ -88,6 +89,17 @@ func openJiraTicket(endpointAPI string, orgID string, token string, jiraProjectI if labels != "" { jiraTicket.Fields.Labels = strings.Split(labels, ",") } + + if assigneeName != "" { + var assignee Assignee + assignee.Name = assigneeName + jiraTicket.Fields.Assignees = &assignee + } else if assigneeID != "" { + var assignee Assignee + assignee.AccountId = assigneeID + jiraTicket.Fields.Assignees = &assignee + } + if priorityIsSeverity { var priority PriorityType jiraMappingEnvVarName := fmt.Sprintf("SNYK_JIRA_PRIORITY_FOR_%s_VULN", strings.ToUpper(jsonVuln.K("issueData").K("severity").String().Value)) @@ -139,7 +151,7 @@ func displayErrorForIssue(vulnForJira interface{}, endpointAPI string) string { return vulnID + "\n" } -func openJiraTickets(endpointAPI string, orgID string, token string, jiraProjectID string, jiraTicketType string, assigneeID string, labels string, projectInfo jsn.Json, vulnsForJira map[string]interface{}, priorityIsSeverity bool) (int, string, string) { +func openJiraTickets(endpointAPI string, orgID string, token string, jiraProjectID string, jiraTicketType string, assigneeName string, assigneeID string, labels string, projectInfo jsn.Json, vulnsForJira map[string]interface{}, priorityIsSeverity bool) (int, string, string) { fullResponseDataAggregated := "" fullListNotCreatedIssue := "" RequestFailed := false @@ -148,7 +160,7 @@ func openJiraTickets(endpointAPI string, orgID string, token string, jiraProject for _, vulnForJira := range vulnsForJira { RequestFailed = false - responseDataAggregatedByte, err := openJiraTicket(endpointAPI, orgID, token, jiraProjectID, jiraTicketType, assigneeID, labels, projectInfo, vulnForJira, priorityIsSeverity) + responseDataAggregatedByte, err := openJiraTicket(endpointAPI, orgID, token, jiraProjectID, jiraTicketType, assigneeName, assigneeID, labels, projectInfo, vulnForJira, priorityIsSeverity) if err != nil { fmt.Printf("Request to %s failed\n", endpointAPI) @@ -159,7 +171,7 @@ func openJiraTickets(endpointAPI string, orgID string, token string, jiraProject for numberOfRetries := 0; numberOfRetries < MaxNumberOfRetry; numberOfRetries++ { fmt.Println("Retrying with priorityIsSeverity set to false, max retry ", MaxNumberOfRetry) priorityIsSeverity = false - responseDataAggregatedByte, err = openJiraTicket(endpointAPI, orgID, token, jiraProjectID, jiraTicketType, assigneeID, labels, projectInfo, vulnForJira, priorityIsSeverity) + responseDataAggregatedByte, err = openJiraTicket(endpointAPI, orgID, token, jiraProjectID, jiraTicketType, assigneeName, assigneeID, labels, projectInfo, vulnForJira, priorityIsSeverity) if err != nil { fullListNotCreatedIssue += displayErrorForIssue(vulnForJira, endpointAPI) } else { diff --git a/jira_labels_test.go b/jira_labels_test.go index bb76aa5..f7a6500 100644 --- a/jira_labels_test.go +++ b/jira_labels_test.go @@ -42,7 +42,7 @@ func TestOpenJiraTicketWithLabelsFunc(t *testing.T) { if err != nil { panic(err) } - numberIssueCreated, jiraResponse, NotCreatedIssueId := openJiraTickets(server.URL, "123", "123", "123", "Bug", "", "Label1,Label2", projectInfo, vulnsForJira, false) + numberIssueCreated, jiraResponse, NotCreatedIssueId := openJiraTickets(server.URL, "123", "123", "123", "Bug", "", "", "Label1,Label2", projectInfo, vulnsForJira, false) var mirroredResponse mirroredResponse if err := json.Unmarshal([]byte(jiraResponse), &mirroredResponse); err != nil { @@ -67,7 +67,7 @@ func TestOpenJiraTicketWithoutLabelsFunc(t *testing.T) { if err != nil { panic(err) } - numberIssueCreated, jiraResponse, NotCreatedIssueId := openJiraTickets(server.URL, "123", "123", "123", "Bug", "", "", projectInfo, vulnsForJira, false) + numberIssueCreated, jiraResponse, NotCreatedIssueId := openJiraTickets(server.URL, "123", "123", "123", "Bug", "", "", "", projectInfo, vulnsForJira, false) var mirroredResponse mirroredResponse if err := json.Unmarshal([]byte(jiraResponse), &mirroredResponse); err != nil { diff --git a/jira_prioritymapping_test.go b/jira_prioritymapping_test.go index 0d1b351..c9bfc38 100644 --- a/jira_prioritymapping_test.go +++ b/jira_prioritymapping_test.go @@ -24,7 +24,7 @@ func TestOpenJiraTicketWithPriorityMappingFunc(t *testing.T) { if err != nil { panic(err) } - NumberIssueCreated, jiraResponse, NotCreatedIssueId := openJiraTickets(server.URL, "123", "123", "123", "Bug", "", "", projectInfo, vulnsForJira, true) + NumberIssueCreated, jiraResponse, NotCreatedIssueId := openJiraTickets(server.URL, "123", "123", "123", "Bug", "", "", "", projectInfo, vulnsForJira, true) var mirroredResponse mirroredResponse if err := json.Unmarshal([]byte(jiraResponse), &mirroredResponse); err != nil { @@ -49,7 +49,7 @@ func TestOpenJiraTicketWithoutPriorityMappingFunc(t *testing.T) { if err != nil { panic(err) } - NumberIssueCreated, jiraResponse, NotCreatedIssueId := openJiraTickets(server.URL, "123", "123", "123", "Bug", "", "", projectInfo, vulnsForJira, false) + NumberIssueCreated, jiraResponse, NotCreatedIssueId := openJiraTickets(server.URL, "123", "123", "123", "Bug", "", "", "", projectInfo, vulnsForJira, false) var mirroredResponse mirroredResponse if err := json.Unmarshal([]byte(jiraResponse), &mirroredResponse); err != nil { @@ -75,7 +75,7 @@ func TestOpenJiraTicketWithCustomPriorityMappingFunc(t *testing.T) { panic(err) } os.Setenv("SNYK_JIRA_PRIORITY_FOR_MEDIUM_VULN", "not too bad") - NumberIssueCreated, jiraResponse, NotCreatedIssueId := openJiraTickets(server.URL, "123", "123", "123", "Bug", "", "", projectInfo, vulnsForJira, true) + NumberIssueCreated, jiraResponse, NotCreatedIssueId := openJiraTickets(server.URL, "123", "123", "123", "Bug", "", "", "", projectInfo, vulnsForJira, true) var mirroredResponse mirroredResponse if err := json.Unmarshal([]byte(jiraResponse), &mirroredResponse); err != nil { diff --git a/jira_test.go b/jira_test.go index 5e9bade..68c1627 100644 --- a/jira_test.go +++ b/jira_test.go @@ -25,7 +25,7 @@ func TestOpenJiraTicketFunc(t *testing.T) { if err != nil { panic(err) } - NumberIssueCreated, jiraResponse, NotCreatedIssueId := openJiraTickets(server.URL, "123", "123", "123", "Bug", "", "", projectInfo, vulnsForJira, false) + NumberIssueCreated, jiraResponse, NotCreatedIssueId := openJiraTickets(server.URL, "123", "123", "123", "Bug", "", "", "", projectInfo, vulnsForJira, false) assert.Equal("", NotCreatedIssueId) assert.Equal(string(readFixture("./fixtures/results/jiraTicketsOpeningResults")), jiraResponse) @@ -46,7 +46,7 @@ func TestOpenJiraTicketErrorAndRetryFunc(t *testing.T) { if err != nil { panic(err) } - NumberIssueCreated, jiraResponse, NotCreatedIssueId := openJiraTickets(server.URL, "123", "123", "123", "Bug", "", "", projectInfo, vulnsForJira, true) + NumberIssueCreated, jiraResponse, NotCreatedIssueId := openJiraTickets(server.URL, "123", "123", "123", "Bug", "", "", "", projectInfo, vulnsForJira, true) assert.Equal("", NotCreatedIssueId) assert.Equal(string(readFixture("./fixtures/results/jiraTicketsOpeningResults")), jiraResponse) @@ -68,7 +68,7 @@ func TestOpenJiraMultipleTicketsErrorAndRetryFunc(t *testing.T) { panic(err) } - NumberIssueCreated, jiraResponse, NotCreatedIssueId := openJiraTickets(server.URL, "123", "123", "123", "Bug", "", "", projectInfo, vulnsForJira, true) + NumberIssueCreated, jiraResponse, NotCreatedIssueId := openJiraTickets(server.URL, "123", "123", "123", "Bug", "", "", "", projectInfo, vulnsForJira, true) assert.Equal("", NotCreatedIssueId) fmt.Println(NumberIssueCreated) @@ -106,7 +106,7 @@ func TestOpenJiraMultipleTicketsErrorAndRetryAndFailFunc(t *testing.T) { panic(err) } - NumberIssueCreated, jiraResponse, NotCreatedIssueId := openJiraTickets(server.URL, "123", "123", "123", "Bug", "", "", projectInfo, vulnsForJira, true) + NumberIssueCreated, jiraResponse, NotCreatedIssueId := openJiraTickets(server.URL, "123", "123", "123", "Bug", "", "", "", projectInfo, vulnsForJira, true) assert.Equal(string(readFixture("./fixtures/results/NotCreatedIssueIdSingle")), NotCreatedIssueId) fmt.Println(NumberIssueCreated) @@ -145,7 +145,7 @@ func TestOpenJiraMultipleTicketsFailureFunc(t *testing.T) { panic(err) } - NumberIssueCreated, jiraResponse, NotCreatedIssueId := openJiraTickets(server.URL, "123", "123", "123", "Bug", "", "", projectInfo, vulnsForJira, true) + NumberIssueCreated, jiraResponse, NotCreatedIssueId := openJiraTickets(server.URL, "123", "123", "123", "Bug", "", "", "", projectInfo, vulnsForJira, true) fmt.Println(NumberIssueCreated) @@ -170,3 +170,53 @@ func TestOpenJiraMultipleTicketsFailureFunc(t *testing.T) { return } + +func TestOpenJiraTicketWithAssigneeNameFunc(t *testing.T) { + assert := assert.New(t) + server := HTTPResponseStubAndMirrorRequest("/v1/org/123/project/12345678-1234-1234-1234-123456789012/issue/SNYK-JS-MINIMIST-559764/jira-issue", "", "") + + defer server.Close() + + projectInfo, _ := jsn.NewJson(readFixture("./fixtures/project.json")) + vulnsForJira := make(map[string]interface{}) + err := json.Unmarshal(readFixture("./fixtures/vulnForJiraAggregatedWithPath.json"), &vulnsForJira) + if err != nil { + panic(err) + } + numberIssueCreated, jiraResponse, NotCreatedIssueId := openJiraTickets(server.URL, "123", "123", "123", "Bug", "admin", "", "", projectInfo, vulnsForJira, false) + + var mirroredResponse mirroredResponse + if err := json.Unmarshal([]byte(jiraResponse), &mirroredResponse); err != nil { + panic(err) + } + assert.Equal(NotCreatedIssueId, "") + assert.Equal(string(readFixture("./fixtures/results/jiraTicketWithoutLabelsWithAssigneeName.json")), string(mirroredResponse.Body)) + fmt.Println("NumberIssueCreated :", numberIssueCreated) + + return +} + +func TestOpenJiraTicketWithAssigneeIDFunc(t *testing.T) { + assert := assert.New(t) + server := HTTPResponseStubAndMirrorRequest("/v1/org/123/project/12345678-1234-1234-1234-123456789012/issue/SNYK-JS-MINIMIST-559764/jira-issue", "", "") + + defer server.Close() + + projectInfo, _ := jsn.NewJson(readFixture("./fixtures/project.json")) + vulnsForJira := make(map[string]interface{}) + err := json.Unmarshal(readFixture("./fixtures/vulnForJiraAggregatedWithPath.json"), &vulnsForJira) + if err != nil { + panic(err) + } + numberIssueCreated, jiraResponse, NotCreatedIssueId := openJiraTickets(server.URL, "123", "123", "123", "Bug", "", "12345", "", projectInfo, vulnsForJira, false) + + var mirroredResponse mirroredResponse + if err := json.Unmarshal([]byte(jiraResponse), &mirroredResponse); err != nil { + panic(err) + } + assert.Equal(NotCreatedIssueId, "") + assert.Equal(string(readFixture("./fixtures/results/jiraTicketWithoutLabelsWithAssigneeID.json")), string(mirroredResponse.Body)) + fmt.Println("NumberIssueCreated :", numberIssueCreated) + + return +} diff --git a/main.go b/main.go index 06c2ddf..3cc112e 100644 --- a/main.go +++ b/main.go @@ -38,7 +38,8 @@ Open Source, so feel free to contribute ! severityPtr := flag.String("severity", "low", "Optional. Your severity threshold") maturityFilterPtr := flag.String("maturityFilter", "", "Optional. include only maturity level(s) separated by commas [mature,proof-of-concept,no-known-exploit,no-data]") typePtr := flag.String("type", "all", "Optional. Your issue type (all|vuln|license)") - assigneeIDPtr := flag.String("assigneeId", "", "Optional. The Jira user ID to assign issues to") + assigneeNamePtr := flag.String("assigneeName", "", "Optional. The Jira user ID to assign issues to. Note: Do not use assigneeName and assigneeId at the same time") + assigneeIDPtr := flag.String("assigneeId", "", "Optional. The Jira user ID to assign issues to. Note: Do not use assigneeName and assigneeId at the same time") labelsPtr := flag.String("labels", "", "Optional. Jira ticket labels") priorityIsSeverityPtr := flag.Bool("priorityIsSeverity", false, "Use issue severity as priority") priorityScorePtr := flag.Int("priorityScoreThreshold", 0, "Optional. Your min priority score threshold [INT between 0 and 1000]") @@ -54,6 +55,7 @@ Open Source, so feel free to contribute ! var issueType string = *typePtr var maturityFilterString string = *maturityFilterPtr var assigneeID string = *assigneeIDPtr + var assigneeName string = *assigneeNamePtr var labels string = *labelsPtr var priorityIsSeverity bool = *priorityIsSeverityPtr var priorityScoreThreshold int = *priorityScorePtr @@ -73,6 +75,10 @@ Open Source, so feel free to contribute ! log.Fatalf("INPUT ERROR: %d is not a valid score. Must be between 0-1000.", priorityScoreThreshold) } + if assigneeName != "" && assigneeID != "" { + log.Fatalf(("INPUT ERROR: You passed both assigneeID and assigneeName in parameters\n Please, Use assigneeID OR assigneeName, not both")) + } + maturityFilter := createMaturityFilter(strings.Split(maturityFilterString, ",")) numberIssueCreated := 0 notCreatedJiraIssues := "" @@ -93,7 +99,7 @@ Open Source, so feel free to contribute ! fmt.Println("4/4 - No new JIRA ticket required") } else { fmt.Println("4/4 - Opening JIRA Tickets") - numberIssueCreated, jiraResponse, notCreatedJiraIssues = openJiraTickets(endpointAPI, orgID, apiToken, jiraProjectID, jiraTicketType, assigneeID, labels, projectInfo, vulnsPerPath, priorityIsSeverity) + numberIssueCreated, jiraResponse, notCreatedJiraIssues = openJiraTickets(endpointAPI, orgID, apiToken, jiraProjectID, jiraTicketType, assigneeName, assigneeID, labels, projectInfo, vulnsPerPath, priorityIsSeverity) if jiraResponse == "" { fmt.Println("Failure to create a ticket(s)")