Commit 3b179bc3 authored by James Lopez's avatar James Lopez

WIP - refactored events to use build serializer, related spec passing

parent 81d0146c
...@@ -2,17 +2,23 @@ class AnalyticsBuildEntity < Grape::Entity ...@@ -2,17 +2,23 @@ class AnalyticsBuildEntity < Grape::Entity
include RequestAwareEntity include RequestAwareEntity
expose :name expose :name
expose :id
expose :ref, as: :branch expose :ref, as: :branch
expose :short_sha expose :short_sha
expose :started_at, as: :date expose :started_at, as: :date
expose :duration, as: :total_time expose :duration, as: :total_time
expose :author, using: UserEntity
expose :url do |build| expose :branch do
url_to(:namespace_project_build, build) expose :ref, as: :name
expose :url do |build|
url_to(:namespace_project_tree, build, build.ref)
end
end end
expose :branch_url do |build| expose :url do |build|
url_to(:namespace_project_tree, build, build.ref) url_to(:namespace_project_build, build)
end end
expose :commit_url do |build| expose :commit_url do |build|
......
...@@ -30,7 +30,7 @@ module Gitlab ...@@ -30,7 +30,7 @@ module Gitlab
end end
def test_events def test_events
@fetcher.fetch(stage: :test).each do |event| @fetcher.fetch(stage: :test).map do |event|
parse_build_event(event) parse_build_event(event)
end end
end end
...@@ -40,7 +40,7 @@ module Gitlab ...@@ -40,7 +40,7 @@ module Gitlab
end end
def staging_events def staging_events
@fetcher.fetch(stage: :staging).each do |event| @fetcher.fetch(stage: :staging).map do |event|
parse_build_event(event) parse_build_event(event)
end end
end end
...@@ -64,7 +64,7 @@ module Gitlab ...@@ -64,7 +64,7 @@ module Gitlab
def parse_build_event(event) def parse_build_event(event)
build = ::Ci::Build.find(event['id']) build = ::Ci::Build.find(event['id'])
#event['author_name'] = build.author.try(:name) AnalyticsBuildSerializer.new(project: @project).represent(build).as_json
end end
def first_time_reference_commit(commits, event) def first_time_reference_commit(commits, event)
......
...@@ -6,14 +6,19 @@ describe AnalyticsBuildEntity do ...@@ -6,14 +6,19 @@ describe AnalyticsBuildEntity do
end end
context 'when build is a regular job' do context 'when build is a regular job' do
let(:build) { create(:ci_build) } let(:user) { create(:user) }
let(:build) { create(:ci_build, author: user) }
subject { entity.as_json } subject { entity.as_json }
it 'contains url to build page and retry action' do it 'contains URLs' do
expect(subject).to include(:url, :branch_url, :commit_url) expect(subject).to include(:url, :branch_url, :commit_url)
end end
it 'contains the author' do
expect(subject).to include(:author)
end
it 'does not contain sensitive information' do it 'does not contain sensitive information' do
expect(subject).not_to include(/token/) expect(subject).not_to include(/token/)
expect(subject).not_to include(/variables/) expect(subject).not_to include(/variables/)
......
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