Add polling mechanism for Code Quality MR Widget
What does this MR do and why?
This MR fixes: #368409 (closed)
It fixes a bug where the CodeQuality MR Widget would throw an uncaught error when the Backend returned with a 204 No Content Status Code.
This MR enables polling on the CodeQuality Widget using the MR Widget Extension, so in case of 204 it will poll until it receives a status Code 200 from the Backend.
Screenshots or screen recordings
before | after |
---|---|
Note to reviewer: I highly recommend reviewing this MR commit by commit. I refactored the extension to use a constants file while I was at it, and the diff looks a little confusing. First commit fixes the bug, second commit does the refactor. That way it'll be much easier to read
How to set up and validate locally
Unfortunately this is a little bit of a pain to reproduce, so if you're having Issues please give me a ping I'm happy to provide a demo.
- Setup a Project in your GDK with a codequality job. For example fork: https://gitlab.com/jannik_lehmann/code-quality-test
- run a pipeline
- create a MR which fixes or adds codequality findings for example: jannik_lehmann/code-quality-test!4
- open the MR, search the Network tab for
codequality_reports.json
polling is not always needed, so this will behave differently on each reload, you might see only 1 request with status code 200, reloading multiple times should return you a case where it will be multiple requests 204 at the beginning 200 at the final request.
To increase your odds to see the described above behaviour I recommend applying this patch, which messes with the BE response.
diff --git a/app/controllers/projects/merge_requests_controller.rb b/app/controllers/projects/merge_requests_controller.rb
index be56ccf62b5e..3434a30ded99 100644
--- a/app/controllers/projects/merge_requests_controller.rb
+++ b/app/controllers/projects/merge_requests_controller.rb
@@ -522,7 +522,8 @@ def disable_query_limiting
end
def reports_response(report_comparison, pipeline = nil)
- if pipeline&.active?
+
+ if pipeline&.active? || [true, false, false, false].sample
::Gitlab::PollingInterval.set_header(response, interval: 3000)
render json: '', status: :no_content && return
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.