Skip to content

Commit

Permalink
feat(labels): added ability to add labels (#56)
Browse files Browse the repository at this point in the history
* feat(labels): added ability to add labels

* feat(labels): added ability to add labels

* feat(labels): added ability to add labels

* feat(labels): added ability to add labels
  • Loading branch information
maira-samtek authored Oct 2, 2024
1 parent 5f916c5 commit 9d670ab
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 4 deletions.
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

2. Creates Jira issues for findings that do not already have a Jira issue

- To avoid creating duplicate issues, the search criteria use the custom label configuration as well as default configuration for three identifying search labels: region, AWS account ID, and "security-hub."
- **To avoid creating duplicate issues**, the search criteria use the custom label configuration as well as default configuration for three identifying search labels: region, AWS account ID, and "security-hub."

- each Security Hub Finding type (by title) is represented as a single issue, e.g. if there are three resources that have violated the 'S3.8' rule there will be a single S3.8 Jira issue created
- Each Security Hub Finding type (by title) is represented as a single issue, e.g. if there are three resources that have violated the 'S3.8' rule there will be a single S3.8 Jira issue created

3. Closes existing Jira issues in the target project if their underlying findings are no longer active

Expand Down Expand Up @@ -269,6 +269,14 @@ Execute a sync but only log API calls to Jira which would create/modify Jira Iss

**Description:** Comma separated list of User Emails for Atlassion Jira or User EUA IDs for Enterprise Jira.

### `jira-watchers`

**Required: No**

**Default Value: ''**

**Description:** Comma separated list of Labels to be added on newly created issues.

## Local Testing

See test-infrastructure/jira-container/README.md for instructions on how to run against local Jira container
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ inputs:
description: 'Comma separated list of Emails for Atlassion Jira and User EUA IDs for Enterprise Jira '
required: false
default: ''
jira-add-labels:
description: 'Comma separated list of labels to add in newly created tickets'
default: ''
# AWS
aws-region:
description: 'Target AWS region for Security Hub findings'
Expand Down
11 changes: 10 additions & 1 deletion dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dist/libs/jira-lib.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dist/macfc-security-hub-sync.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ async function run(): Promise<void> {
'Done, Closed, Resolved'
),
jiraWatchers: getDefaultInputOrEnv('jira-watchers', 'JIRA_WATCHERS', ''),
jiraAddLabels: getDefaultInputOrEnv(
'jira-add-labels',
'JIRA_ADD_LABELS',
''
),
jiraAssignee: getInputOrEnv('jira-assignee', 'JIRA_ASSIGNEE'),
transitionMap: transitionMap,
dryRun: getInputOrEnvAndConvertToBool('dry-run', 'DRY_RUN', false),
Expand Down
3 changes: 2 additions & 1 deletion src/libs/jira-lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface JiraConfig {
jiraIgnoreStatuses: string
jiraAssignee?: string
jiraWatchers?: string
jiraAddLabels?: string
transitionMap: Array<{status: string; transition: string}>
dryRun: boolean
jiraLinkId?: string
Expand Down Expand Up @@ -371,7 +372,7 @@ export class Jira {
.map(label => Jira.formatLabelQuery(label))
.join(' AND ')
if (searchQuery) {
finalLabelQuery = `(${finalLabelQuery}) OR (${searchQuery})`
finalLabelQuery = `((${finalLabelQuery}) OR (${searchQuery}))`
}
}
const projectQuery = `project = '${this.jiraProject}'`
Expand Down
8 changes: 8 additions & 0 deletions src/macfc-security-hub-sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export class SecurityHubJiraSync {
private jiraLinkType?: string
private jiraLinkDirection?: string
private jiraLabelsConfig?: LabelConfig[]
private jiraAddLabels?: string[]
constructor(
jiraConfig: JiraConfig,
securityHubConfig: SecurityHubJiraSyncConfig,
Expand All @@ -58,6 +59,9 @@ export class SecurityHubJiraSync {
this.jiraLinkId = jiraConfig.jiraLinkId
this.jiraLinkType = jiraConfig.jiraLinkType
this.jiraLinkDirection = jiraConfig.jiraLinkDirection
this.jiraAddLabels = jiraConfig.jiraAddLabels
?.split(',')
.map(label => label.trim())
if (jiraConfig.jiraLabelsConfig) {
this.jiraLabelsConfig = JSON.parse(jiraConfig.jiraLabelsConfig)
}
Expand Down Expand Up @@ -418,6 +422,10 @@ export class SecurityHubJiraSync {
console.log('Invalid labels config - going with default labels')
}
}
if (this.jiraAddLabels) {
const prevLabels = newIssueData.fields.labels ?? []
newIssueData.fields.labels = [...prevLabels, ...this.jiraAddLabels]
}
let newIssueInfo
try {
newIssueInfo = await this.jira.createNewIssue(newIssueData)
Expand Down

0 comments on commit 9d670ab

Please sign in to comment.