Skip to content
This repository was archived by the owner on Jun 12, 2022. It is now read-only.

Commit 17d9b1d

Browse files
committed
Document
1 parent 0fd0d96 commit 17d9b1d

File tree

10 files changed

+98
-3
lines changed

10 files changed

+98
-3
lines changed

README.md

Lines changed: 98 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,99 @@
1-
SonarQube Custom Plugin Example [![Build Status](https://travis-ci.org/SonarSource/sonar-custom-plugin-example.svg?branch=master)](https://travis-ci.org/SonarSource/sonar-custom-plugin-example)
2-
==========
1+
# Phabricator Differential Plugin
32

4-
Shows how to write a SonarQube plugin compatible with SonarQube 5.6 LTS
3+
The Phabricator Differential plugin provides integration with Phabricator. It allows SonarQube to analytic and report issues on differential revision without pushing results to SonarQube. Any issues that are found are published as comments on the revision.
4+
The plugin performs the following operations:
5+
1. Add a global comment that gives a summary of the analysis
6+
![no-issue.png](docs/images/no-issue.png)
7+
![global-comment.png](docs/images/global-comment.png)
8+
9+
2. Add an inline comment for each issue
10+
11+
![inline-comments.png](docs/images/inline-comments.png)
12+
13+
### Configuration
14+
- **Requirements**
15+
- SonarQube Server must be up and running.
16+
- Minimal SonarQube Version: 5.6
17+
- The Phabricator Differential plugin is installed on SonarQube Server.
18+
Phabricator configure
19+
- A Jenkins server is installed
20+
21+
- **Create SonarQube bot**
22+
1. Navigate to `https://phabricator.example/people` with your base Phabricator URL in place of `phabricator.example`.
23+
2. Click the **Create New User** button in the top right corner of the page
24+
3. Choose **Create Bot User** for the **Account Type** option and click **Continue** button
25+
4. Enter **Username** field by `sonarqube`, **Real Name** field by `SonarQube`, **Email Address** field by `sonarqube-bot@noreply.example.com`
26+
27+
![SonarQube bot](docs/images/sonarqube-bot.png)
28+
5. Click **Create User** button
29+
6. Go to **SonarQube** bot user profile and click **Manage** at the left of page, then click **Edit Settings** link at the right of page
30+
7. Click **Conduit API Tokens**, then click **Generate API Token** button in the top right corner of the page, click **Generate Token**
31+
8. Copy token and store somewhere to use for later steps
32+
33+
![SonarQube token](docs/images/sonarqube-bot-token.png)
34+
35+
- **SonarQube**
36+
1. Navigate to `https://sonarqube.example/settings?category=phabricator+differential` with your base Phabricator URL in place of `sonarqube.example`
37+
2. Enter `token` that was generated from create sonarqube bot steps above into **Conduit token** filed
38+
3. Enter Phabricator URL into **Phabricator URL** field
39+
4. Click **Save Phabricator Differential Settings** button
40+
5. Navigate to the **Post-build Actions** section.
41+
6. Click the **Add post-build action** button and select **Post to Phabricator**.
42+
43+
![Phabricator Differential Settings](docs/images/sonarqube-global-config.png)
44+
45+
**Note:** These setting can override for each project at Project Administration Settings page.
46+
47+
![sonarqube-project](docs/images/sonarqube-project-config.png)
48+
49+
- **Jenkins job**
50+
1. Navigate to the Jenkins job you want to integrate with Phabricator.
51+
2. Click the **Configure** button.
52+
3. Click the **Add Parameter** button and select **String Parrameter**.
53+
4. Enter `DIFF_ID` in the **Name** field of the parameter.
54+
5. Navigate to the **Build** section.
55+
6. Click the **Add build step** button and select Maven or Gradle.
56+
7. Enter these options: `-Dsonar.analysis.mode=preview -Dsonar.phdiff.diffId=${DIFF_ID}`
57+
58+
**Note:** You can combined this jenkins job with [Phabricator Jenkins plugin](https://github.com/uber/phabricator-jenkins-plugin) job to do two things in one job
59+
60+
- **Harbormaster**
61+
- With Phabricator, Jenkins, and your Jenkins jobs configured it's time to configure a new Harbormaster build plan. This build plan will trigger the Jenkins job using a Herald rule that will be configured in the next section.
62+
1. Navigate to `https://phabricator.example/harbormaster/plan/` with your base Phabricator URL in place of `phabricator.example`.
63+
2. Click the **Create Build Plan** button in the top right corner of the page.
64+
3. Enter a name for the build plan in the **Name** field. For these instructions, we'll use "test-example" as the build name.
65+
4. Click the **Create Build Plan** button.
66+
5. Click the **Add Build Step** button.
67+
6. Click the **Make HTTP Request** step.
68+
7. Use this template URI to fill in the URI field for the build plan: `https://ci.example.com/job/job-name/buildWithParameters?DIFF_ID=${buildable.diff}`.
69+
Be sure to replace `https://ci.example.com` with the URI of your Jenkins instance and `test-example` with the name of your Jenkins job.
70+
If your Jenkins instance is exposed to the internet, make sure to install the [Build Token Root Plugin](https://wiki.jenkins-ci.org/display/JENKINS/Build+Token+Root+Plugin) and fill in the `token` parameter.
71+
8. Click the **When Complete** dropdown menu and select **Continue Build Normally**.
72+
9. Click the **Create Build Step** button.
73+
![Harbormaster plan](docs/images/habormaster.png)
74+
75+
- **Herald**
76+
- With the build plans created it's time to create a Herald Rule to trigger the plans. The steps below will configure a Herald Rule to trigger the build plans on Differential Revisions to your repository.
77+
78+
1. Navigate to `https://phabricator.example/herald/` with your base Phabricator URL in place of `phabricator.example`.
79+
2. Click the **Create Herald Rule** button in the top right corner of the page.
80+
3. Select the **Differential Revisions** checkbox and click **Continue**.
81+
4. Select the **Global** checkbox and click **Continue**.
82+
5. Enter a name for the Herald Rule in the **Rule Name** field.
83+
6. In the **Conditions** section, click the dropdown menu that says "Author" and select "Repository".
84+
7. Enter your repository name in to the blank field in the **Conditions** section.
85+
8. In the **Actions** section, click the dropdown menu that says "Add blocking reviewers" and select "Run build plans".
86+
9. Enter the build plans that were created in the previous section in to the blank field in the **Action** section.
87+
![Herald rule](docs/images/herald.png)
88+
10. Click **Save Rule**.
89+
90+
91+
### Manually analytic revision
92+
- Gradle: `gradle sonarqube -Dsonar.analysis.mode=preview -Dsonar.phdiff.diffId=<your-diff-id>`
93+
- Maven: `mvn sonar:sonar -Dsonar.analysis.mode=preview -Dsonar.phdiff.diffId=<your-diff-id>`
94+
95+
### Contribute
96+
Please open all pull requests and issues against [https://github.com/thienan93/phdiff](https://github.com/thienan93/phdiff)
97+
98+
### License
99+
[Apache License, Version 2.0](LICENSE)

docs/images/global-comment.png

34 KB
Loading

docs/images/habormaster.png

29.5 KB
Loading

docs/images/herald.png

21 KB
Loading

docs/images/inline-comments.png

18.3 KB
Loading

docs/images/no-issue.png

7.12 KB
Loading
3.97 KB
Loading

docs/images/sonarqube-bot.png

8.49 KB
Loading
18.3 KB
Loading
18.5 KB
Loading

0 commit comments

Comments
 (0)