Commit ba19b4c2 authored by Steve Abrams's avatar Steve Abrams

Add event tracking to NPM package API

Add event tracking for pushing and pulling
npm packages via the api endpoints.
parent 9f5bf29e
...@@ -144,6 +144,8 @@ module API ...@@ -144,6 +144,8 @@ module API
package_file = ::Packages::PackageFileFinder package_file = ::Packages::PackageFileFinder
.new(package, params[:file_name]).execute! .new(package, params[:file_name]).execute!
track_event('pull_package')
present_carrierwave_file!(package_file.file) present_carrierwave_file!(package_file.file)
end end
...@@ -158,6 +160,8 @@ module API ...@@ -158,6 +160,8 @@ module API
put ':id/packages/npm/:package_name', requirements: NPM_ENDPOINT_REQUIREMENTS do put ':id/packages/npm/:package_name', requirements: NPM_ENDPOINT_REQUIREMENTS do
authorize_create_package!(user_project) authorize_create_package!(user_project)
track_event('push_package')
created_package = ::Packages::Npm::CreatePackageService created_package = ::Packages::Npm::CreatePackageService
.new(user_project, current_user, params.merge(build: current_authenticated_job)).execute .new(user_project, current_user, params.merge(build: current_authenticated_job)).execute
......
...@@ -133,12 +133,16 @@ describe API::NpmPackages do ...@@ -133,12 +133,16 @@ describe API::NpmPackages do
end end
context 'a public project' do context 'a public project' do
subject { get_file(package_file) }
it 'returns the file with no token needed' do it 'returns the file with no token needed' do
get_file(package_file) subject
expect(response).to have_gitlab_http_status(200) expect(response).to have_gitlab_http_status(200)
expect(response.content_type.to_s).to eq('application/octet-stream') expect(response.content_type.to_s).to eq('application/octet-stream')
end end
it_behaves_like 'a gitlab tracking event', described_class.name, 'pull_package'
end end
context 'private project' do context 'private project' do
...@@ -230,13 +234,19 @@ describe API::NpmPackages do ...@@ -230,13 +234,19 @@ describe API::NpmPackages do
let(:package_name) { "@#{group.path}/my_package_name" } let(:package_name) { "@#{group.path}/my_package_name" }
let(:params) { upload_params(package_name) } let(:params) { upload_params(package_name) }
it 'creates npm package with file with access token' do context 'with access token' do
expect { upload_package_with_token(package_name, params) } subject { upload_package_with_token(package_name, params) }
.to change { project.packages.count }.by(1)
.and change { Packages::PackageFile.count }.by(1)
.and change { Packages::Tag.count }.by(1)
expect(response).to have_gitlab_http_status(200) it_behaves_like 'a gitlab tracking event', described_class.name, 'push_package'
it 'creates npm package with file' do
expect { subject }
.to change { project.packages.count }.by(1)
.and change { Packages::PackageFile.count }.by(1)
.and change { Packages::Tag.count }.by(1)
expect(response).to have_gitlab_http_status(200)
end
end end
it 'creates npm package with file with job token' do it 'creates npm package with file with job token' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment