Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
d6e6be3
SonarQube plugin
martindstone Aug 26, 2024
f9a76ba
remove extra images, fix mistake in column defs
martindstone Aug 26, 2024
da76bf8
prettier
martindstone Aug 26, 2024
e6876ba
lint
martindstone Aug 26, 2024
ecf9c57
words +1
martindstone Aug 26, 2024
e53bc96
moar tests
martindstone Aug 26, 2024
ee8cfc7
prettier tests
martindstone Aug 26, 2024
72fefa5
move modal to new component, fix tests, better user feedback on comment
martindstone Nov 8, 2024
4c4eaf6
update readme
martindstone Nov 8, 2024
00f2b2c
take out hardcoded URL, fix tests and README
martindstone Nov 19, 2024
4e362ee
lint
martindstone Nov 19, 2024
cff5f0e
punctuation
martindstone Nov 19, 2024
80a8988
add entity type to message
martindstone Nov 19, 2024
fb06996
lint
martindstone Nov 19, 2024
12a731d
Merge branch 'sonarqube-issues' of https://github.com/cortexapps/cort…
jreock Nov 19, 2024
04bbe2f
Merge in without rebase
jreock Nov 19, 2024
4f4051b
Merge back in pre-merge no rebase changes
jreock Nov 19, 2024
cdea449
Merge linting changes back in, something is inconsistent between yarn…
jreock Nov 19, 2024
888bec0
Align linting in yarn, should fix build
jreock Nov 19, 2024
9d86d8e
Resolve yarn inconsistencies
jreock Nov 19, 2024
461e3c9
Merge branch 'master' into sonarqube-issues
jreock Nov 19, 2024
991c498
Merge branch 'sonarqube-issues' of https://github.com/cortexapps/cort…
jreock Nov 19, 2024
3f89742
fix review issues, add hooks, gently componentize
martindstone Nov 20, 2024
916e5d8
oops make the name match the screenshot
martindstone Nov 20, 2024
683a529
Merge branch 'sonarqube-issues' of https://github.com/cortexapps/cort…
jreock Nov 20, 2024
6e9848a
fix readme
martindstone Nov 20, 2024
a4fc0fc
Update README.md
martindstone Nov 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 24 additions & 10 deletions plugins/sonarqube-issues/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,41 @@ info:
This plugin requires a proxy to SonarQube. To set up:

- Create a token in SonarQube by clicking on your profile > My Account > Security
- In Cortex, define a secret whose value is your new token. Name it `sonarqube_plugin`.
- In Cortex, define a secret whose value is your new token. Name it `sonarqube_secret`.
- Create a proxy:

- Navigate to Plugins, then click on the Proxies tab, then click on Create Proxy
- Give the proxy a name, then click on Add URL
- For the URL Prefix, type in the base URL of your SonarQube instance. Default for cloud is `https://sonarcloud.io`. **This URL prefix should be exactly the same as the value of the baseURL variable in [SonarqubeIssues.tsx](src/components/SonarqubeIssues.tsx) - If you are self-hosting SonarQube, you will have to put your own base URL in both places!**
- Click on Add Header and add a header whose name is `Authorization` and whose value is `Bearer {{secrets.sonarqube_plugin}}` (include the curly braces!)
- For the URL Prefix, type in the API base URL of your SonarQube instance. Default for cloud is `https://sonarcloud.io`. If you are self-hosting SonarQube, you will have a different API base URL.
- Click on Add Header and add a header whose name is `Authorization` and whose value is `Bearer {{secrets.sonarqube_secret}}` (include the curly braces!)

- Once you are done, the proxy should look like the below:

<div align="center"><img src="img/sonarqube-proxy.png"></div>

### Self-Hosted setup

The plugin uses `https://sonarcloud.io` as its default API base URL. If you are self-hosting Sonarqube, then you will have a different URL. To configure the plugin to use that URL, you can create a Sonarqube plugin configuration entity in Cortex with your own API base URL.

- Consider creating a new entity type, so that any existing scorecards are not affected by ths configuration entity. In this example, we have created a new entity type called `plugin-configuration`
- Create a new entity with the tag `sonarqube-plugin-config`
- Set `x-cortex-definition.sonarqube-api-url` to the value of your ServiceNow Instance URL. For example, if my Sonarqube API base URL was `https://sonarqube.martindstone.com`, my `sonarqube-plugin-config` entity would look like this:

```yaml
openapi: 3.0.1
info:
title: Sonarqube Plugin Config
description: ""
x-cortex-tag: sonarqube-plugin-config
x-cortex-type: plugin-configuration
x-cortex-definition:
sonarqube-api-url: https://sonarqube.martindstone.com
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docs ask for the sonarqube-api-url key, but the code is checking for sonarqube-key:

image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more tweak and then I'm good to sign off! At the beginning, the README specifies:

If the cortex.yaml has a SonarQube Project defined in its x-cortex-static-analysis configuration, it will query for issues pertaining to that project. For example:

And the example shows:

openapi: 3.0.1 info: title: Funrepo description: it is a fun repo x-cortex-git: github: alias: cortex repository: martindstone-org/funrepo x-cortex-tag: funrepo x-cortex-type: service x-cortex-static-analysis: sonarqube: **project: martindstone-org_funrepo**

I think we need to call out specifically that the value in x-cortex-static-analysis.sonarqube.project needs to specifically match the project key in SonarQube and not the project name. That tripped me up once I got the authentication working, I started using the project name and it just wasn't retrieving issues, switched to project key and it works like a charm!!

image image

```

Now, you can build and add the plugin.

- Build the plugin:
- Make sure you have npm/yarn, and make sure you have put in your correct SonarQube Base URL in the baseURL variable in [SonarqubeIssues.tsx](src/components/SonarqubeIssues.tsx)
- Make sure you have npm/yarn
- In your terminal, in the `sonarqube-issues` directory, type `yarn` or `npm install` to install the dependencies; then type `npm run build` or `yarn build` to build the plugin
- The compiled plugin will be created in `dist/ui.html`
- In Plugins > All, click **Register Plugin**
Expand All @@ -55,12 +74,7 @@ Now, you can build and add the plugin.

Now, when you navigate to a Service that has a SonarQube associated with it, you should be able to click on Plugins > SonarQube Issues and see the SonarQube Issues associated with the project that is linked to the service.

**Note: This plugin will connect to SonarQube's cloud instance out of the box.** If you are self-hosting SonarQube and need to direct the plugin to a different API endpoint, update the following section of the [SonarqubeIssues.tsx](src/components/SonarqubeIssues.tsx) file:

```ts
// Set your SonarQube url. Cloud is https://sonarcloud.io
const baseURL = "https://sonarcloud.io";
```
**Note: This plugin will connect to Sonarqube's cloud API service out of the box.** If you are self-hosting SonarQube and need to direct the plugin to a different API base URL, make sure you follow the **Self-hosted setup** instructions above.

## Troubleshooting

Expand Down
6 changes: 3 additions & 3 deletions plugins/sonarqube-issues/src/components/SonarqubeIssues.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ const SonarqubeIssues: React.FC<SonarqubeIssuesProps> = ({ entityYaml }) => {
}
const getSonarqubePluginConfig = async (): Promise<void> => {
setIsLoading(true);
let newSnowUrl = "https://sonarcloud.io";
let newApiBaseUrl = "https://sonarcloud.io";
try {
const response = await fetch(
`${apiBaseUrl}/catalog/sonarqube-plugin-config/openapi`
);
const data = await response.json();
newSnowUrl = data.info["x-cortex-definition"]["sonarqube-api-url"];
newApiBaseUrl = data.info["x-cortex-definition"]["sonarqube-api-url"];
} catch (e) {}
setSonarqubeApiBaseUrl(newSnowUrl);
setSonarqubeApiBaseUrl(newApiBaseUrl);
setIsLoading(false);
};
void getSonarqubePluginConfig();
Expand Down