Commit graph

70 commits

Author SHA1 Message Date
justusbunsi b632381c90
Write tests for Gitea client
Signed-off-by: Steven Kriegler <sk.bunsenbrenner@gmail.com>
Reviewed-on: https://codeberg.org/justusbunsi/gitea-sonarqube-bot/pulls/36
2022-07-12 18:31:25 +02:00
justusbunsi f808a58177
Refactor internal name to url-like one
Signed-off-by: Steven Kriegler <sk.bunsenbrenner@gmail.com>
2022-07-12 16:57:12 +02:00
justusbunsi b6b9087651
Initialize SonarQube SDK with its settings
Instead of using global settings. This is important for validated
configuration reloads.

Signed-off-by: Steven Kriegler <sk.bunsenbrenner@gmail.com>
2022-07-12 12:26:10 +02:00
justusbunsi 54beca9c25
Introduce better test case structure
Signed-off-by: Steven Kriegler <sk.bunsenbrenner@gmail.com>
2022-07-12 11:20:08 +02:00
justusbunsi 51211d77cd
Change internal name
Signed-off-by: Steven Kriegler <sk.bunsenbrenner@gmail.com>
2022-07-11 17:39:22 +02:00
justusbunsi d943a7f420
Add tests for GetRevision
Signed-off-by: Steven Kriegler <sk.bunsenbrenner@gmail.com>
2022-07-11 15:53:28 +02:00
justusbunsi 525fa03065
Centralize API response handling
Currently, all API handler functions take care of response code and
message on their own. This leads to a huge injection chain for HTTP
related objects.

This refactors the API to consistently return response code and message
to the API main entrypoint where the response is created and sent.

Now, SonarQube and Gitea will get a response at the very end of any bot
action for one request. SonarQube has a timeout of 10 seconds, which may
be reached due to network latency. We'll see.

Signed-off-by: Steven Kriegler <sk.bunsenbrenner@gmail.com>
2022-07-11 15:24:43 +02:00
justusbunsi 685c834b61
Allow pull request naming pattern customization (#28)
Fixes: #3

Signed-off-by: Steven Kriegler <sk.bunsenbrenner@gmail.com>
2022-06-18 14:03:56 +02:00
justusbunsi 02ad0c0bf0
Improve error handling of SonarQube client
Due to unhandled errors within the SonarQube client, users may be
presented with Go panics or just don't know what the root cause of a
non-working bot is.

Now it is possible to identify network errors, authentication issues or
an incorrect bot configuration regarding SonarQube.

Fixes: #20

Signed-off-by: Steven Kriegler <sk.bunsenbrenner@gmail.com>
2022-06-17 20:19:59 +02:00
justusbunsi 471b25e682
Remove debug logging
Signed-off-by: Steven Kriegler <sk.bunsenbrenner@gmail.com>
2022-06-12 13:28:31 +02:00
justusbunsi dc3969cd05
Improve configuration file flexibility
Instead of re-inventing the wheel regarding configuration location
handling and validation, this introduces a new command flag `--config`
allowing for full flexibility of configuration filename and location.
This flag can also be defined via environment variable which allows
an easy way of starting the bot from command line, inside a Docker
container or using the Helm Chart.

It makes the custom environment lookup unnecessary and reduces some
complexity during startup and for writing tests.

Resolves: #10

Signed-off-by: Steven Kriegler <sk.bunsenbrenner@gmail.com>
2022-05-22 14:03:23 +02:00
justusbunsi 5cb3daab60
Add webhook secret validation
Resolves: #4

Signed-off-by: Steven Kriegler <sk.bunsenbrenner@gmail.com>
2022-05-21 19:05:09 +02:00
justusbunsi e203034228 Rewrite API entrypoint to be testable (#22)
The current code base regarding API entrypoint is not testable as it
directly connects to Gitea when creating the API endpoints. This
prevented my from writing tests in the past for that part.

As the SonarQube quality gate broke due to changes in the API entrypoint
logic, tests are now required to satisfy the quality gate.

Therefore, the instantiation of the API handlers is now decoupled from
building the bot API endpoints and follows the same interface wrapper
strategy as used for the Gitea API client. This makes it testable.

Now, tests are written for the most parts of the API entrypoint. I've
also noticed that there was much overhead within the tests for a
non-implemented function `fetchDetails`. So I dropped that function for
now.

Signed-off-by: Steven Kriegler <sk.bunsenbrenner@gmail.com>

Co-authored-by: justusbunsi <sk.bunsenbrenner@gmail.com>
Reviewed-on: https://codeberg.org/justusbunsi/gitea-sonarqube-bot/pulls/22
2022-05-21 18:21:05 +02:00
justusbunsi 7f5c3390c4
Add tests for Gitea API
Signed-off-by: Steven Kriegler <sk.bunsenbrenner@gmail.com>
2022-05-21 13:50:58 +02:00
justusbunsi 4d28133b12
Extract test api test helpers
Signed-off-by: Steven Kriegler <sk.bunsenbrenner@gmail.com>
2022-05-21 12:23:57 +02:00
justusbunsi 34e2783cb1
Skip logging non-api routes
Signed-off-by: Steven Kriegler <sk.bunsenbrenner@gmail.com>
2022-05-15 16:03:19 +02:00
justusbunsi 21837f9b25
Export webhook and token struct
Signed-off-by: Steven Kriegler <sk.bunsenbrenner@gmail.com>
2021-10-17 16:01:15 +02:00
justusbunsi e01096a7fe
Eliminate viper references from token and webhook
Signed-off-by: Steven Kriegler <sk.bunsenbrenner@gmail.com>
2021-10-17 15:57:45 +02:00
justusbunsi 021d01b5fb
Remove useless types
Signed-off-by: Steven Kriegler <sk.bunsenbrenner@gmail.com>
2021-10-17 15:43:25 +02:00
justusbunsi 8a7e9f83fa
Refactor action validation
Signed-off-by: Steven Kriegler <sk.bunsenbrenner@gmail.com>
2021-10-17 11:12:50 +02:00
justusbunsi 90581744ff
Set analysis status on PR creation
Signed-off-by: Steven Kriegler <sk.bunsenbrenner@gmail.com>
2021-10-13 08:54:21 +02:00
justusbunsi dfffd17223
Open comment link in new tab
Signed-off-by: Steven Kriegler <sk.bunsenbrenner@gmail.com>
2021-10-12 14:09:24 +02:00
justusbunsi f187d4f8c6
Allow customizing metrics fetch from SonarQube
Signed-off-by: Steven Kriegler <sk.bunsenbrenner@gmail.com>
2021-10-12 13:14:17 +02:00
justusbunsi 0bd65d8a1d
Allow override the provided revision
Signed-off-by: Steven Kriegler <61625851+justusbunsi@users.noreply.github.com>
2021-10-11 14:21:17 +02:00
justusbunsi bb156f95bf
Log response code for non-working status update
Signed-off-by: Steven Kriegler <61625851+justusbunsi@users.noreply.github.com>
2021-10-11 11:28:32 +02:00
justusbunsi 48cb8a0ede
Handle favicon requests
Signed-off-by: Steven Kriegler <61625851+justusbunsi@users.noreply.github.com>
2021-10-11 08:50:50 +02:00
justusbunsi ae55eaf97c
Prevent bot from interpreting unknown actions
Signed-off-by: Steven Kriegler <61625851+justusbunsi@users.noreply.github.com>
2021-10-10 19:45:57 +02:00
justusbunsi e28e524456
Post analysis details on bot action comment
Signed-off-by: Steven Kriegler <61625851+justusbunsi@users.noreply.github.com>
2021-10-10 19:39:33 +02:00
justusbunsi 369edfcfae
Fetch actual quality gate status on bot comment
Signed-off-by: Steven Kriegler <61625851+justusbunsi@users.noreply.github.com>
2021-10-10 19:01:48 +02:00
justusbunsi 895dfe92e0
Add pending status on PR synchronize event
Signed-off-by: Steven Kriegler <61625851+justusbunsi@users.noreply.github.com>
2021-10-10 17:59:28 +02:00
justusbunsi 56f7a1081b
Implement skeleton for different webhook handler
Signed-off-by: Steven Kriegler <61625851+justusbunsi@users.noreply.github.com>
2021-10-10 17:32:25 +02:00
justusbunsi 5b72ee7bc0
Differ between several gitea events
Signed-off-by: Steven Kriegler <61625851+justusbunsi@users.noreply.github.com>
2021-10-10 17:17:29 +02:00
justusbunsi de575605f9
Move sonarqube sdk files
Signed-off-by: Steven Kriegler <61625851+justusbunsi@users.noreply.github.com>
2021-10-10 16:43:37 +02:00
justusbunsi bf453c6c43
Centralize bot actions
Signed-off-by: Steven Kriegler <61625851+justusbunsi@users.noreply.github.com>
2021-10-10 16:39:26 +02:00
justusbunsi c99925abb3
Fix URL for status
Signed-off-by: Steven Kriegler <61625851+justusbunsi@users.noreply.github.com>
2021-10-10 16:29:29 +02:00
justusbunsi c6bc0d71ff
Move gitea sdk files
Signed-off-by: Steven Kriegler <61625851+justusbunsi@users.noreply.github.com>
2021-10-10 16:28:59 +02:00
justusbunsi 46c5ab2aec
Rename webhook_handler to api
Signed-off-by: Steven Kriegler <61625851+justusbunsi@users.noreply.github.com>
2021-10-10 16:18:14 +02:00
justusbunsi e20b1469d3
Reduce UpdateStatus parameter mess
Signed-off-by: Steven Kriegler <61625851+justusbunsi@users.noreply.github.com>
2021-10-10 16:14:09 +02:00
justusbunsi 57fc8054b2
Bot listens to actions via Gitea comments
Signed-off-by: Steven Kriegler <61625851+justusbunsi@users.noreply.github.com>
2021-10-10 15:58:03 +02:00
justusbunsi 3bab05bb71
Fix required header for SonarQube endpoint
Signed-off-by: Steven Kriegler <61625851+justusbunsi@users.noreply.github.com>
2021-10-10 13:07:10 +02:00
justusbunsi 2873eb5159
Switch to gin-gonic as server
Signed-off-by: Steven Kriegler <61625851+justusbunsi@users.noreply.github.com>
2021-10-09 21:48:51 +02:00
justusbunsi 758e3c75cc
Switch to another default port
Signed-off-by: Steven Kriegler <61625851+justusbunsi@users.noreply.github.com>
2021-10-09 21:23:40 +02:00
justusbunsi 45fbfed51b
Split settings structs into separate files
Signed-off-by: Steven Kriegler <61625851+justusbunsi@users.noreply.github.com>
2021-10-09 21:10:30 +02:00
justusbunsi aac7f5743d
Fix tests
Signed-off-by: Steven Kriegler <61625851+justusbunsi@users.noreply.github.com>
2021-10-09 21:09:23 +02:00
justusbunsi 34dbd4f609
Add status-check to PR/commit
Signed-off-by: Steven Kriegler <61625851+justusbunsi@users.noreply.github.com>
2021-10-09 20:45:21 +02:00
justusbunsi d24bfdad4f
Replace violations with code_smells
Signed-off-by: Steven Kriegler <61625851+justusbunsi@users.noreply.github.com>
2021-10-09 20:44:09 +02:00
justusbunsi e608a8f969
Retrieve actual data from SonarQube for comment
Signed-off-by: Steven Kriegler <61625851+justusbunsi@users.noreply.github.com>
2021-10-09 18:09:54 +02:00
justusbunsi a1990a60f4
Format code
Signed-off-by: Steven Kriegler <61625851+justusbunsi@users.noreply.github.com>
2021-10-03 17:57:22 +02:00
justusbunsi 16f545f179
Fix failing tests
Signed-off-by: Steven Kriegler <61625851+justusbunsi@users.noreply.github.com>
2021-10-03 17:49:23 +02:00
justusbunsi 1dab92385f
Fetch raw measures from SonarQube
Signed-off-by: Steven Kriegler <61625851+justusbunsi@users.noreply.github.com>
2021-07-12 16:58:48 +02:00