Skip to content

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)

  1. Follow the NPM packages docs to set up an NPM project that can publish to the GitLab Package Registry.
  2. Follow the Snowplow Guide to set up Snowplow Micro for local testing of Snowplow events.
  3. Use this method to test for creation and non-creation of API::NpmPackages / push_package events:
    1. Checkout the master branch to test current behavior.
    2. 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".
    3. Go to http://localhost:9090/micro/reset to clear the existing event.
    4. Try publishing the same package again and see it fail with 403 Forbidden because it's detected as a duplicate.
    5. 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.
    6. Go to http://localhost:9090/micro/reset to clear the existing event.
    7. Checkout this branch (330475-fix-npm-push_package-event-created-on-api-error) to test the fixed behavior.
    8. Try publishing the same package again and see it fail with 403 Forbidden because it's detected as a duplicate.
    9. Go to http://localhost:9090/micro/all and confirm there are no events, meaning the fix worked.
    10. Bump the package version in package.json and try publishing again, seeing it succeed this time.
    11. 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.

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Edited by Hugo Ortiz

Merge request reports