Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SonarQube GA API for projects #1809

Merged
merged 11 commits into from
Dec 24, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,20 @@ To view and test the integration's mapping against examples of the third-party A
"icon": "Clock",
"title": "Last Analysis Date"
},
"qualityGateStatus": {
"title": "Quality Gate Status",
"type": "string",
"enum": [
"OK",
"WARN",
"ERROR"
],
"enumColors": {
"OK": "green",
"WARN": "yellow",
"ERROR": "red"
}
},
"numberOfBugs": {
"type": "number",
"title": "Number Of Bugs"
Expand Down Expand Up @@ -63,15 +77,73 @@ To view and test the integration's mapping against examples of the third-party A
"icon": "Git",
"title": "Main Branch"
},
"tags": {
"type": "array",
"title": "Tags"
"mainBranchLastAnalysisDate": {
"type": "string",
"format": "date-time",
"icon": "Clock",
"title": "Main Branch Last Analysis Date"
},
"revision": {
"type": "string",
"title": "Revision"
},
"managed": {
"type": "boolean",
"title": "Managed"
}
},
"required": []
},
"mirrorProperties": {},
"calculationProperties": {},
"aggregationProperties": {
"criticalOpenIssues": {
"title": "Number Of Open Critical Issues",
"type": "number",
"target": "sonarQubeIssue",
"query": {
"combinator": "and",
"rules": [
{
"property": "status",
"operator": "in",
"value": ["OPEN", "REOPENED"]
},
{
"property": "severity",
"operator": "=",
"value": "CRITICAL"
}
]
},
"calculationSpec": {
"calculationBy": "entities",
"func": "count"
}
},
"numberOfOpenIssues": {
"title": "Number Of Open Issues",
"type": "number",
"target": "sonarQubeIssue",
"query": {
"combinator": "and",
"rules": [
{
"property": "status",
"operator": "in",
"value": [
"OPEN",
"REOPENED"
]
}
]
},
"calculationSpec": {
"calculationBy": "entities",
"func": "count"
}
}
},
"relations": {}
}
```
Expand All @@ -82,7 +154,9 @@ To view and test the integration's mapping against examples of the third-party A
<summary><b>Integration configuration (Click to expand)</b></summary>

:::tip filter projects
The integration provides an option to filter the data that is retrieved from the SonarQube API using the following attributes:
The integration provides an option to filter the data that is retrieved from the SonarQube API depending on the integration version based on the following attributes:

<h3>SonarQube integration version `<=0.1.121`</h3>

1. `query`: Limits the search to component names that contain the supplied string
2. `alertStatus`: To filter a project's quality gate status. Accepts a list of values such as `OK`, `ERROR` and `WARN`
Expand All @@ -91,6 +165,17 @@ The integration provides an option to filter the data that is retrieved from the
5. `qualifier`: To filter on a component qualifier. Accepts values such as `TRK` (for projects only) and `APP` (for applications only)

These attributes can be enabled using the path: `selector.apiFilters.filter`. By default, the integration fetches only SonarQube projects using the `qualifier` attribute.

<h3>SonarQube integration version `>=0.1.122`</h3>
1. `analyzed_before`: To retrieve projects analyzed before the given date. Accepts date format like so `2017-10-19` or `2017-10-19T13:00:00+0200`

2. `on_provisioned_only`: To retrieve projects on provisioned only. Accepts boolean `true` or `false`.

3. `projects`: List of projects to retrieve only. Specify the projects as an array of keys.

4. `qualifier`: To filter based on the project's qualifier. Possible values are `TRK`, `VW` and `APP`. Defaults to `TRK`. Specify this as an array of values.

These attributes can be enabled using the `selector` path.
:::

:::tip Define your own metrics
Expand All @@ -101,6 +186,8 @@ Besides filtering the API data, the integration provides a mechanism to allow us
Please note that the API filters are supported on on-premise Sonar environments (SonarQube) only, and will not work on SonarCloud.
:::

<h3>Project mapping for integration version `<=0.1.121`</h3>

```yaml showLineNumbers
createMissingRelatedEntities: true
deleteDependentEntities: true
Expand Down Expand Up @@ -141,6 +228,53 @@ resources:
mainBranch: .__branch.name
tags: .tags
```


<h3>Project mapping for integratiion version `>= 0.1.115`</h3>

```yaml showLineNumbers
createMissingRelatedEntities: true
deleteDependentEntities: true
resources:
- kind: projects_ga
selector:
query: 'true'
apiFilters:
qualifier:
- TRK
metrics:
- code_smells
- coverage
- bugs
- vulnerabilities
- duplicated_files
- security_hotspots
- new_violations
- new_coverage
- new_duplicated_lines_density
port:
entity:
mappings:
blueprint: '"sonarQubeProject"'
identifier: .key
title: .name
properties:
organization: .organization
link: .__link
qualityGateStatus: .__branch.status.qualityGateStatus
lastAnalysisDate: .analysisDate
numberOfBugs: .__measures[]? | select(.metric == "bugs") | .value
numberOfCodeSmells: .__measures[]? | select(.metric == "code_smells") | .value
numberOfVulnerabilities: .__measures[]? | select(.metric == "vulnerabilities") | .value
numberOfHotSpots: .__measures[]? | select(.metric == "security_hotspots") | .value
numberOfDuplications: .__measures[]? | select(.metric == "duplicated_files") | .value
coverage: .__measures[]? | select(.metric == "coverage") | .value
mainBranch: .__branch.name
mainBranchLastAnalysisDate: .__branch.analysisDate
revision: .revision
managed: .managed
```

</details>

## Issue
Expand Down
Loading
Loading