Go to file
justusbunsi ce13a040b8
Introduce changelog
Signed-off-by: Steven Kriegler <sk.bunsenbrenner@gmail.com>
2022-05-22 14:25:03 +02:00
cmd/gitea-sonarqube-bot Improve configuration file flexibility 2022-05-22 14:03:23 +02:00
config Allow customizing metrics fetch from SonarQube 2021-10-12 13:14:17 +02:00
contrib Bump golang to 1.18 2022-05-14 01:42:42 +02:00
docker/usr/local/bin Add production Dockerfile 2021-10-11 08:42:11 +02:00
docs Add screenshots 2021-10-11 20:02:12 +02:00
helm Introduce changelog 2022-05-22 14:25:03 +02:00
internal Improve configuration file flexibility 2022-05-22 14:03:23 +02:00
.dockerignore Add production Dockerfile 2021-10-11 08:42:11 +02:00
.editorconfig Respect common go project structure 2021-06-20 15:14:26 +02:00
.gitignore Improve configuration file flexibility 2022-05-22 14:03:23 +02:00
CHANGELOG.md Introduce changelog 2022-05-22 14:25:03 +02:00
CONTRIBUTING.md Prepare Helm Chart release 2022-05-14 01:10:07 +02:00
DCO Follow advisory: Add license, DCO and contributing 2021-06-06 17:11:38 +02:00
Dockerfile Improve configuration file flexibility 2022-05-22 14:03:23 +02:00
go.mod Bump dependencies 2022-05-14 02:22:00 +02:00
go.sum Bump dependencies 2022-05-14 02:22:00 +02:00
LICENSE Follow advisory: Add license, DCO and contributing 2021-06-06 17:11:38 +02:00
Makefile Bump dependencies 2022-05-14 02:22:00 +02:00
package-lock.json Prepare Helm Chart release 2022-05-14 01:10:07 +02:00
package.json Prepare Helm Chart release 2022-05-14 01:10:07 +02:00
README.md Introduce changelog 2022-05-22 14:25:03 +02:00
sonar-project.properties Rewrite API entrypoint to be testable (#22) 2022-05-21 18:21:05 +02:00

Gitea SonarQube Bot

Quality Gate Status Docker Image Version (latest semver) Artifact Hub

Gitea SonarQube Bot is a bot that receives messages from both SonarQube and Gitea to help developers being productive. The idea behind this project is the missing ALM integration of Gitea in SonarQube. Unfortunately, this won't be added in near future. Gitea SonarQube Bot aims to fill the gap between working on pull requests and being notified on quality changes. Luckily, both endpoints have a proper REST API to communicate with each others.

Workflow

Workflow

Insights

  • Bot activities
    • Extract data from SonarQube
      • Read payload from hook post to receive project,branch/pr,quality-gate
      • Load "api/measures/component"
    • Comment PR in Gitea (/repos/{owner}/{repo}/issues/{index}/comments)
    • Updates status check (either failing/success)
    • Listen on "/sq-bot review" comments
      • Comment PR in Gitea (/repos/{owner}/{repo}/issues/{index}/comments)
      • Updates status check (either failing/success)

Requirements

This bot is designed to perform SonarQube/SonarCloud API requests specific for pull requests. This feature is available in the Community edition via Sonarqube Community Branch Plugin or natively in SonarQube Developer edition and above.

Bot configuration

See config.example.yaml for a full configuration specification and description.

Installation

Docker

Create a directory config and place your config.yaml inside it. Open a terminal next to this directory and execute the following (replace $TAG first):

docker run --rm -it -p 9000:3000 -v "$(pwd)/config/:/home/bot/config/" justusbunsi/gitea-sonarqube-bot:$TAG

Starting with v0.2.0

By default, the bot expects its configuration file under ./config/config.yaml next to the bot executable. Inside the Docker image the corresponding full path is /home/bot/config/config.yaml. If you prefer using a different location or even a different filename, you can also define the environment variable GITEA_SQ_BOT_CONFIG_PATH that allows for changing that full path.

Imagine having a ./config/sqbot.config.yml on your host that you want to populate inside /mnt/, the correct command to run a Docker container would be:

docker run --rm -it -p 9000:3000 -e "GITEA_SQ_BOT_CONFIG_PATH=/mnt/sqbot.config.yml" -v "$(pwd)/config/:/mnt/" justusbunsi/gitea-sonarqube-bot:$TAG

Helm Chart

See Helm Chart README for detailed instructions.

Setup

SonarQube

  • Create a user and grant permissions to "Browse on project" for the desired project
  • Create a token for this user that will be used by the bot
  • Create a webhook pointing to https://<bot-url>/hooks/sonarqube
  • Consider securing it with a secret

Gitea

  • Create a user and grant permissions to "Read project" for the desired projects including access to "Pull Requests"
  • Create a token for this user that will be used by the bot
  • Create a project/organization/system webhook pointing to https://<bot-url>/hooks/gitea
  • Consider securing the webhook with a secret

CI system

Some CI systems may emulate a merge and therefore produce another, not yet existing commit hash that is promoted to SonarQube. This would cause the bot to fail to set the commit status in Gitea because the webhook sent by SonarQube contains that commit hash. To mitigate that situation, the bot will look inside the properties object for the key sonar.analysis.sqbot. If available, this key can contain the actual commit hash to use for updating the status in Gitea.
See SonarQube docs for details.

Changelog

See CHANGELOG.md for a complete list of changes.

Contributing

Expected workflow is: Fork -> Patch -> Push -> Pull Request

NOTES:

License

This project is licensed under the MIT License. See the LICENSE file for the full license text.


Screenshots

Bot name and avatar depend on user configuration.

Comment Status