Go to file
justusbunsi a51520382e
Add production Dockerfile
Signed-off-by: Steven Kriegler <61625851+justusbunsi@users.noreply.github.com>
2021-10-11 08:42:11 +02:00
cmd/gitea-sonarqube-bot Rename webhook_handler to api 2021-10-10 16:18:14 +02:00
config Fix endpoint documentation 2021-07-11 15:16:18 +02:00
contrib Bump go version to 1.17 2021-10-09 21:26:47 +02:00
docker/usr/local/bin Add production Dockerfile 2021-10-11 08:42:11 +02:00
docs Add missing SQ communication in docs 2021-06-24 11:13:42 +02:00
internal Prevent bot from interpreting unknown actions 2021-10-10 19:45:57 +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 Fix failing tests 2021-10-03 17:49:23 +02:00
CONTRIBUTING.md Switch to another default port 2021-10-09 21:23:40 +02:00
DCO Follow advisory: Add license, DCO and contributing 2021-06-06 17:11:38 +02:00
Dockerfile Add production Dockerfile 2021-10-11 08:42:11 +02:00
go.mod Update dependencies 2021-10-09 21:50:58 +02:00
go.sum Update dependencies 2021-10-09 21:50:58 +02:00
LICENSE Follow advisory: Add license, DCO and contributing 2021-06-06 17:11:38 +02:00
README.md Update bot insights 2021-10-10 19:47:54 +02:00

Gitea SonarQube PR Bot

Gitea SonarQube PR 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 PR 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)

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>/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>/gitea. Consider securing it with a secret.

Bot configuration

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

Contributing

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

NOTES:

TODOs

  • Validate configuration on startup
  • Verify webhook secrets
  • Only post status-check (Opt-in/out)
  • Maybe drop PRBOT_CONFIG_PATH environment variable in favor of --config path/to/config.yaml cli attribute
  • Configure SonarQube PR branch naming pattern for more flexibility (currently focused on Jenkins with Gitea Plugin)
  • Configuration live reloading
  • Caching of outgoing requests in case the target is not available
  • Parsable logging for monitoring
  • Official image for containerized hosting
  • Helm chart for Kubernetes

Possible improvements

  • Reuse existing posted comment for updates via SonarQube webhook or /sq-bot comments
    Therefore storing or dynamically retrieving the previous comment id and modify content (/repos/{owner}/{repo}/issues/comments/{id})
  • Add more information to posted comment
    • Read "api/project_pull_requests" to get current issue counts and current state
    • Load "api/issues/search" to get detailed information for unresolved issues
  • Maybe directly show issues via review comments

License

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