Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/bugfix/201-could-not-decorate-gi…
Browse files Browse the repository at this point in the history
…tlab-merge-request' into bugfix/91-html-tags-not-escaped-on-gitlab-pull-request-decoration
  • Loading branch information
PiekJ committed Jul 20, 2020
2 parents f35767e + 01dbf59 commit ae5af24
Show file tree
Hide file tree
Showing 43 changed files with 1,827 additions and 469 deletions.
109 changes: 41 additions & 68 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ on:
push:
branches:
- '**'
tags:
- '*'
paths-ignore:
- '**.md'
pull_request:
Expand All @@ -15,7 +13,29 @@ on:
- '**.md'

jobs:
prep:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.init.outputs.version }}
release: ${{ steps.init.outputs.release }}
steps:
-
name: Checkout
uses: actions/checkout@v2
-
name: Init
id: init
run: |
VERSION=$(grep "version" gradle.properties | cut -d'=' -f2)
echo ::set-output name=version::${VERSION}
if [[ $VERSION =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
echo ::set-output name=release::true
else
echo ::set-output name=release::false
fi
snapshot:
needs: prep
runs-on: ubuntu-latest
strategy:
fail-fast: false
Expand All @@ -27,11 +47,6 @@ jobs:
-
name: Checkout
uses: actions/checkout@v2
-
name: Dump GitHub context
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
run: echo "$GITHUB_CONTEXT"
-
name: Set up Java ${{ matrix.java }}
uses: actions/setup-java@v1
Expand Down Expand Up @@ -59,36 +74,20 @@ jobs:
path: build/libs/*.jar

release:
needs: prep
if: github.event_name != 'pull_request' && needs.prep.outputs.release == 'true'
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/')
strategy:
fail-fast: false
matrix:
java:
- 11
steps:
-
name: Checkout
uses: actions/checkout@v2
with:
ref: ${{ github.event.base_ref }}
-
name: Dump GitHub context
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
run: echo "$GITHUB_CONTEXT"
-
name: Prepare
id: prepare
run: |
if [[ $GITHUB_REF == refs/tags/* ]]; then
echo ::set-output name=tag_name::${GITHUB_REF#refs/tags/}
fi
fetch-depth: 0
-
name: Set up Java ${{ matrix.java }}
name: Set up Java
uses: actions/setup-java@v1
with:
java-version: ${{ matrix.java }}
java-version: 11
java-package: jdk
-
name: Cache deps
Expand All @@ -108,71 +107,47 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
-
name: Release
if: success() && github.event_name != 'pull_request' && startsWith(github.ref, 'refs/tags/')
if: success()
run: |
./gradlew clean release \
-Prelease.useAutomaticVersion=true \
-Prelease.releaseVersion=${{ steps.prepare.outputs.tag_name }} \
-x preTagCommit -x createReleaseTag
-Prelease.releaseVersion=${{ needs.prep.outputs.version }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
-
name: Archive artifact
if: success() && matrix.java == '11'
if: success()
uses: actions/upload-artifact@v2
with:
name: release
path: build/libs/*.jar
-
name: GitHub Release
uses: softprops/action-gh-release@v1
if: success() && github.event_name != 'pull_request' && startsWith(github.ref, 'refs/tags/')
if: success()
with:
name: ${{ needs.prep.outputs.version }}
tag_name: ${{ needs.prep.outputs.version }}
draft: true
files: |
build/libs/*.jar
name: ${{ steps.prepare.outputs.tag_name }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

sonar:
needs: prep
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
java:
- 11
steps:
-
name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
-
name: Dump GitHub context
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
run: echo "$GITHUB_CONTEXT"
-
name: Dump job context
env:
JOB_CONTEXT: ${{ toJson(job) }}
run: echo "$JOB_CONTEXT"
-
name: Dump steps context
env:
STEPS_CONTEXT: ${{ toJson(steps) }}
run: echo "$STEPS_CONTEXT"
-
name: Dump runner context
env:
RUNNER_CONTEXT: ${{ toJson(runner) }}
run: echo "$RUNNER_CONTEXT"
-
name: Set up Java ${{ matrix.java }}
name: Set up Java
uses: actions/setup-java@v1
with:
java-version: ${{ matrix.java }}
java-version: 11
java-package: jdk
-
name: Cache deps
Expand All @@ -186,25 +161,23 @@ jobs:
name: Sonar
if: ${{ env.SONAR_TOKEN != null }}
run: |
if [[ $GITHUB_REF == refs/tags/* ]]; then
if [ "${{ github.event_name }}" = "pull_request" ]; then
./gradlew sonarqube \
-Dsonar.pullrequest.provider=github \
-Dsonar.pullrequest.github.repository=${{ github.repository }} \
-Dsonar.host.url=https://sonarcloud.io \
-Dsonar.organization=${SONAR_ORG_KEY} \
-Dsonar.projectKey=${SONAR_PROJECT_KEY} \
-Dsonar.projectVersion=${GITHUB_REF#refs/tags/} \
-Dsonar.branch.name=master
elif [ "${{ github.event_name }}" = "pull_request" ]; then
PR_BRANCH=${{ github.head_ref }}
-Dsonar.pullrequest.key=${{ github.event.number }} \
-Dsonar.pullrequest.base=${{ github.base_ref }}
elif [ "${{ needs.prep.outputs.release }}" = 'true' ]; then
./gradlew sonarqube \
-Dsonar.pullrequest.provider=github \
-Dsonar.pullrequest.github.repository=${{ github.repository }} \
-Dsonar.host.url=https://sonarcloud.io \
-Dsonar.organization=${SONAR_ORG_KEY} \
-Dsonar.projectKey=${SONAR_PROJECT_KEY} \
-Dsonar.pullrequest.key=${{ github.event.number }} \
-Dsonar.pullrequest.base=${{ github.base_ref }}
-Dsonar.projectVersion=${{ needs.prep.outputs.version }}
else
./gradlew sonarqube \
-Dsonar.pullrequest.provider=github \
Expand Down
26 changes: 6 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ Use the following table to find the correct plugin version for each SonarQube ve

SonarQube Version | Plugin Version
------------------|---------------
7.8 - 8.0 | 1.3.1
8.1 | 1.4.0
7.8 - 8.0 | 1.3.2
7.4 - 7.7 | 1.0.2

# Features
The plugin is intended to support the [features and parameters specified in the SonarQube documentation](https://docs.sonarqube.org/latest/branches/overview/), with the following caveats
* __Pull Requests:__ Analysis of Pull Requests is fully supported, but the decoration of pull requests is only currently available for Github, Gitlab and Bitbucket Server
* __Pull Requests:__ Analysis of Pull Requests is fully supported, but the decoration of pull requests is only currently available for Github, Gitlab, Bitbucket Server and Bitbucket Cloud.

# Installation
Either build the project or [download a compatible release version of the plugin JAR](https://github.com/mc1arke/sonarqube-community-branch-plugin/releases). Copy the plugin JAR file to the `extensions/plugins/` **and** the `lib/common/` directories of your SonarQube instance and restart SonarQube.
Expand Down Expand Up @@ -66,30 +67,15 @@ services:

# Configuration
## Global configuration
If you can define the properties globally (e.g. the pull request provider) within your SonarQube instance go to
[/admin/settings?category=pull+request](http://localhost:9000/admin/settings?category=pull+request) and set the
properties as admin.

Set all other properties that you can define globally for all of your projects.

Make sure `sonar.core.serverBaseURL` in SonarQube [/admin/settings](http://localhost:9000/admin/settings) is properly
set in order to for the links in the comment to work.

## Project configuration
Override the global configuration on project level at [/project/settings?category=pull+request&id=PROJECT_KEY](http://localhost:9000/project/settings?category=pull+request&id=PROJECT_KEY) and set project specific
settings here.

# Configuration of Bitbucket Server
Set properties for Bitbucket Server either on Global configuration or Project configuration level as mentioned in the
Configuration section.
Set all other properties that you can define globally for all of your projects.

## How to decorate the PR
In order to decorate your short living branch (hotfixes, features, ...) pull-requests you need to analyze your long
living branches (master, development, release branches) first.

You can configure patterns for long living branches in SonarQube.
In order to decorate your Pull Request's source branch, you need to analyze your target branch first.

### Run analysis of long living branches
### Run analysis of branches

The analysis needs the following setting:
`sonar.branch.name = branch_name (e.g master)`
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=1.3.2-SNAPSHOT
version=1.4.1-SNAPSHOT
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@

import com.github.mc1arke.sonarqube.plugin.ce.pullrequest.PostAnalysisIssueVisitor;
import com.github.mc1arke.sonarqube.plugin.ce.pullrequest.PullRequestPostAnalysisTask;
import com.github.mc1arke.sonarqube.plugin.ce.pullrequest.bitbucket.BitbucketServerPullRequestDecorator;
import com.github.mc1arke.sonarqube.plugin.ce.pullrequest.bitbucket.client.BitbucketClient;
import com.github.mc1arke.sonarqube.plugin.ce.pullrequest.bitbucket.BitbucketPullRequestDecorator;
import com.github.mc1arke.sonarqube.plugin.ce.pullrequest.github.GithubPullRequestDecorator;
import com.github.mc1arke.sonarqube.plugin.ce.pullrequest.github.v3.DefaultLinkHeaderReader;
import com.github.mc1arke.sonarqube.plugin.ce.pullrequest.github.v3.RestApplicationAuthenticationProvider;
Expand All @@ -42,8 +41,7 @@ public List<Object> getComponents() {
return Arrays.asList(CommunityBranchLoaderDelegate.class, PullRequestPostAnalysisTask.class,
PostAnalysisIssueVisitor.class, GithubPullRequestDecorator.class,
GraphqlCheckRunProvider.class, DefaultLinkHeaderReader.class, RestApplicationAuthenticationProvider.class,
BitbucketServerPullRequestDecorator.class, BitbucketClient.class,
GitlabServerPullRequestDecorator.class);
BitbucketPullRequestDecorator.class, GitlabServerPullRequestDecorator.class);
}

}
Loading

0 comments on commit ae5af24

Please sign in to comment.