Skip to content

Commit bce1fb3

Browse files
martindstonejreock
andauthored
SonarQube issues plugin (#29)
Co-authored-by: Justin Reock <[email protected]>
1 parent b78f809 commit bce1fb3

32 files changed

+1271
-1
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules/
2+
dist/
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
module.exports = {
2+
env: {
3+
browser: true,
4+
es2021: true,
5+
},
6+
extends: [
7+
"plugin:react/jsx-runtime",
8+
"plugin:react-hooks/recommended",
9+
"standard-with-typescript",
10+
"prettier",
11+
],
12+
overrides: [],
13+
parserOptions: {
14+
ecmaVersion: "latest",
15+
project: "tsconfig.json",
16+
sourceType: "module",
17+
tsconfigRootDir: __dirname,
18+
},
19+
plugins: ["react"],
20+
rules: {
21+
// conflicts with no-extra-boolean-cast
22+
"@typescript-eslint/strict-boolean-expressions": "off",
23+
},
24+
settings: {
25+
react: {
26+
version: "detect",
27+
},
28+
},
29+
};
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# OSX
2+
*.DS_Store
3+
4+
# IDEs
5+
.idea
6+
*.iml
7+
.vscode
8+
9+
# This project
10+
node_modules/
11+
dist/
12+
yarn-error.log
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules/
2+
dist/

plugins/sonarqube-issues/README.md

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
# SonarQube Issues Cortex Plugin
2+
3+
View SonarQube Issues associated with your services!!
4+
5+
<div align="center"><img src="img/sonarqube-plugin.png" /></div>
6+
7+
The SonarQube Issues plugin shows open SonarQube issues associated with the SonarQube project specified in the entity's `cortex.yaml`. If the `cortex.yaml` has a [SonarQube Project key](https://docs.cortex.io/docs/reference/integrations/sonarqube#entity-descriptor) defined in its `x-cortex-static-analysis` configuration, it will query for issues pertaining to that project. For example:
8+
9+
```yaml
10+
openapi: 3.0.1
11+
info:
12+
title: Funrepo
13+
description: it is a fun repo
14+
x-cortex-git:
15+
github:
16+
alias: cortex
17+
repository: martindstone-org/funrepo
18+
x-cortex-tag: funrepo
19+
x-cortex-type: service
20+
x-cortex-static-analysis:
21+
sonarqube:
22+
project: martindstone-org_funrepo
23+
```
24+
25+
## Setup
26+
27+
This plugin requires a proxy to SonarQube. To set up:
28+
29+
- Create a token in SonarQube by clicking on your profile > My Account > Security
30+
- In Cortex, define a secret whose value is your new token. Name it `sonarqube_plugin`.
31+
- Create a proxy:
32+
33+
- Navigate to Plugins, then click on the Proxies tab, then click on Create Proxy
34+
- Give the proxy a name, like SonarQube Proxy, then click on Add URL.
35+
- For the URL Prefix, type in the API base URL of your SonarQube instance. The default for cloud is `https://sonarcloud.io`. **If you are self-hosting SonarQube, you will have to put in your own base URL instead.**
36+
- Click on Add Header and add a header whose name is `Authorization` and whose value is `Bearer {{{secrets.sonarqube_plugin}}}` (include the curly braces!)
37+
38+
- Once you are done, the proxy should look like the below:
39+
40+
<div align="center"><img src="img/sonarqube-proxy.png"></div>
41+
42+
### Self-Hosted setup
43+
44+
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.
45+
46+
- 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`
47+
- Create a new entity with the tag `sonarqube-plugin-config`
48+
- Set `x-cortex-definition.sonarqube-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:
49+
50+
```yaml
51+
openapi: 3.0.1
52+
info:
53+
title: Sonarqube Plugin Config
54+
description: ""
55+
x-cortex-tag: sonarqube-plugin-config
56+
x-cortex-type: plugin-configuration
57+
x-cortex-definition:
58+
sonarqube-url: https://sonarqube.martindstone.com
59+
```
60+
61+
Now, you can build and add the plugin.
62+
63+
- Build the plugin:
64+
- Make sure you have npm or yarn.
65+
- 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.
66+
- The compiled plugin will be created in `dist/ui.html`.
67+
- In Plugins > All, click **Register Plugin**.
68+
- Give the plugin a name, like SonarQube Issues. This is the name users will see in the plugin listing.
69+
- Under **Associated Proxy**, choose the proxy you just created.
70+
- Under **Plugin Context**, click on Add another context; choose Selection type: Include, and Entity types: service.
71+
- This plugin does not work in the Global context. Turn off the switch labeled **Include in global context**.
72+
- In The **Plugin code** section, upload the `dist/ui.html` file you just built.
73+
- Click on **Save plugin**.
74+
75+
### Create a plugin configuration entity (self-hosted only)
76+
77+
This plugin will connect to SonarQube's cloud instance out of the box, so if you are using SonarQube in the cloud, you should skip this step. If you are self-hosting SonarQube and need to direct the plugin to a different REST API endpoint, create a plugin configuration entity with your SonarQube REST API base URL as follows:
78+
79+
- Consider creating a new entity type, so that any existing scorecards are not affected by this configuration entity. In this example, we have created a new entity type called `plugin-configuration`
80+
- Create a new entity with the tag `sonarqube-plugin-config`
81+
- Set `x-cortex-definition.sonarqube-url` to the value of your SonarQube API base URL. For example, if my SonarQube API base URL was `https://sonarqube.martindstone.com`, my `sonarqube-plugin-config` entity would look like this:
82+
83+
```
84+
openapi: 3.0.1
85+
info:
86+
title: SonarQube Plugin Config
87+
description: ""
88+
x-cortex-tag: sonarqube-plugin-config
89+
x-cortex-type: plugin-configuration
90+
x-cortex-definition:
91+
sonarqube-url: https://sonarqube.martindstone.com
92+
```
93+
94+
Now, when you navigate to a Cortex service that has a SonarQube project 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.
95+
96+
## Troubleshooting
97+
98+
### Getting a message that "No SonarQube details were found for this entity"
99+
100+
If you get the following message:
101+
102+
<div align="center"><img src="img/sonarqube-no-project.png" width="540" /></div>
103+
104+
This means that the plugin did not find a SonarQube project defined as described [here](https://docs.cortex.io/docs/reference/integrations/sonarqube#entity-descriptor).
105+
106+
# Setting up your dev environment
107+
108+
SonarQube Issues Cortex Plugin is a [Cortex](https://www.cortex.io/) plugin. To see how to run the plugin inside of Cortex, see [our docs](https://docs.cortex.io/docs/plugins).
109+
110+
### Prerequisites
111+
112+
Developing and building this plugin requires either [yarn](https://classic.yarnpkg.com/lang/en/docs/install/) or [npm](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm).
113+
114+
## Getting started
115+
116+
1. Run `yarn` or `npm install` to download all dependencies
117+
2. Run `yarn build` or `npm run build` to compile the plugin code into `./dist/ui.html`
118+
3. Upload `ui.html` into Cortex on a create or edit plugin page
119+
4. Add or update the code and repeat steps 2-3 as necessary
120+
121+
### Notable scripts
122+
123+
The following commands come pre-configured in this repository. You can see all available commands in the `scripts` section of [package.json](./package.json). They can be run with npm via `npm run {script_name}` or with yarn via `yarn {script_name}`, depending on your package manager preference. For instance, the `build` command can be run with `npm run build` or `yarn build`.
124+
125+
- `build` - compiles the plugin. The compiled code root is `./src/index.tsx` (or as defined by [webpack.config.js](webpack.config.js)) and the output is generated into `dist/ui.html`.
126+
- `test` - runs all tests defined in the repository using [jest](https://jestjs.io/)
127+
- `lint` - runs lint and format checking on the repository using [prettier](https://prettier.io/) and [eslint](https://eslint.org/)
128+
- `lintfix` - runs eslint in fix mode to fix any linting errors that can be fixed automatically
129+
- `formatfix` - runs Prettier in fix mode to fix any formatting errors that can be fixed automatically
130+
131+
### Available React components
132+
133+
See available UI components via our [Storybook](https://cortexapps.github.io/plugin-core/).
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = "test-file-stub";
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = {};
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = {
2+
plugins: ["@babel/plugin-syntax-jsx"],
3+
presets: [
4+
["@babel/preset-env", { targets: { node: "current" } }],
5+
"@babel/preset-typescript",
6+
["@babel/preset-react", { runtime: "automatic" }],
7+
],
8+
};
29.9 KB
Loading
225 KB
Loading

0 commit comments

Comments
 (0)