Prevent creation of push_package event on NPM packages API error
What does this MR do?
Prevents creating a push_package
tracking event when there's an error while uploading an NPM package via the PUT /api/v4/projects/:id/packages/npm/:package_name
endpoint.
This addresses the NPM package type for #330475 (closed).
Screenshots or Screencasts (strongly suggested)
How to setup and validate locally (strongly suggested)
- Follow the NPM packages docs to set up an NPM project that can publish to the GitLab Package Registry.
- Follow the Snowplow Guide to set up Snowplow Micro for local testing of Snowplow events.
- Use this method to test for creation and non-creation of
API::NpmPackages
/push_package
events:- Checkout the
master
branch to test current behavior. - Publish an NPM package, and go to http://localhost:9090/micro/all to confirm there is 1 good event. Go to http://localhost:9090/micro/good and see the event created with
se_category: "API::NpmPackages"
,se_action: "push_package"
. - Go to http://localhost:9090/micro/reset to clear the existing event.
- Try publishing the same package again and see it fail with
403 Forbidden
because it's detected as a duplicate. - Go to http://localhost:9090/micro/all and confirm there is 1 good event. Go to http://localhost:9090/micro/good and see that an event with
se_category: "API::NpmPackages"
,se_action: "push_package"
was created even when the package push failed. - Go to http://localhost:9090/micro/reset to clear the existing event.
- Checkout this branch (
330475-fix-npm-push_package-event-created-on-api-error
) to test the fixed behavior. - Try publishing the same package again and see it fail with
403 Forbidden
because it's detected as a duplicate. - Go to http://localhost:9090/micro/all and confirm there are no events, meaning the fix worked.
- Bump the package version in
package.json
and try publishing again, seeing it succeed this time. - Go to http://localhost:9090/micro/all and confirm there is 1 good event. Go to http://localhost:9090/micro/good and see the event created with
se_category: "API::NpmPackages"
,se_action: "push_package"
, meaning the success case still works correctly after the fix.
- Checkout the
Does this MR meet the acceptance criteria?
Conformity
-
I have included changelog trailers, or none are needed. (Does this MR need a changelog?) -
I have added/updated documentation, or it's not needed. (Is documentation required?) -
I have properly separated EE content from FOSS, or this MR is FOSS only. (Where should EE code go?) -
I have added information for database reviewers in the MR description, or it's not needed. (Does this MR have database related changes?) -
I have self-reviewed this MR per code review guidelines. -
This MR does not harm performance, or I have asked a reviewer to help assess the performance impact. (Merge request performance guidelines) -
I have followed the style guides. -
This change is backwards compatible across updates, or this does not apply.
Availability and Testing
-
I have added/updated tests following the Testing Guide, or it's not needed. (Consider all test levels. See the Test Planning Process.) -
I have tested this MR in all supported browsers, or it's not needed. -
I have informed the Infrastructure department of a default or new setting change per definition of done, or it's not needed.
Edited by Hugo Ortiz