Commit 41376fac authored by Alex Kalderimis's avatar Alex Kalderimis

Merge branch 'build-hooks-add-deployed-environment' into 'master'

Add environment attrs to build & pipeline hooks

See merge request gitlab-org/gitlab!54480
parents ecdb95a8 826c7cdf
---
title: Added environment details to Job Hook and Pipeline Hook
merge_request: 54480
author: AdrianLC
type: changed
......@@ -1133,6 +1133,10 @@ X-Gitlab-Event: Pipeline Hook
"artifacts_file":{
"filename": null,
"size": null
},
"environment": {
"name": "production",
"action": "start"
}
},
{
......@@ -1167,7 +1171,8 @@ X-Gitlab-Event: Pipeline Hook
"artifacts_file":{
"filename": null,
"size": null
}
},
"environment": null
},
{
"id": 378,
......@@ -1200,7 +1205,8 @@ X-Gitlab-Event: Pipeline Hook
"artifacts_file":{
"filename": null,
"size": null
}
},
"environment": null
},
{
"id": 376,
......@@ -1233,7 +1239,8 @@ X-Gitlab-Event: Pipeline Hook
"artifacts_file":{
"filename": null,
"size": null
}
},
"environment": null
},
{
"id": 379,
......@@ -1257,6 +1264,10 @@ X-Gitlab-Event: Pipeline Hook
"artifacts_file":{
"filename": null,
"size": null
},
"environment": {
"name": "staging",
"action": "start"
}
}
]
......@@ -1329,7 +1340,8 @@ X-Gitlab-Event: Job Hook
"linux",
"docker"
]
}
},
"environment": null
}
```
......
......@@ -62,7 +62,9 @@ module Gitlab
git_http_url: project.http_url_to_repo,
git_ssh_url: project.ssh_url_to_repo,
visibility_level: project.visibility_level
}
},
environment: build_environment(build)
}
data
......@@ -86,6 +88,15 @@ module Gitlab
tags: runner.tags&.map(&:name)
}
end
def build_environment(build)
return unless build.has_environment?
{
name: build.expanded_environment_name,
action: build.environment_action
}
end
end
end
end
......@@ -67,7 +67,8 @@ module Gitlab
artifacts_file: {
filename: build.artifacts_file&.filename,
size: build.artifacts_size
}
},
environment: environment_hook_attrs(build)
}
end
......@@ -80,6 +81,15 @@ module Gitlab
tags: runner.tags&.map(&:name)
}
end
def environment_hook_attrs(build)
return unless build.has_environment?
{
name: build.expanded_environment_name,
action: build.environment_action
}
end
end
end
end
......@@ -38,6 +38,7 @@ RSpec.describe Gitlab::DataBuilder::Build do
it { expect(data[:runner][:id]).to eq(build.runner.id) }
it { expect(data[:runner][:tags]).to match_array(tag_names) }
it { expect(data[:runner][:description]).to eq(build.runner.description) }
it { expect(data[:environment]).to be_nil }
context 'commit author_url' do
context 'when no commit present' do
......@@ -63,6 +64,13 @@ RSpec.describe Gitlab::DataBuilder::Build do
expect(data[:commit][:author_url]).to eq(Gitlab::Routing.url_helpers.user_url(username: build.commit.author.username))
end
end
context 'with environment' do
let(:build) { create(:ci_build, :teardown_environment) }
it { expect(data[:environment][:name]).to eq(build.expanded_environment_name) }
it { expect(data[:environment][:action]).to eq(build.environment_action) }
end
end
end
end
......@@ -37,6 +37,7 @@ RSpec.describe Gitlab::DataBuilder::Pipeline do
expect(build_data[:id]).to eq(build.id)
expect(build_data[:status]).to eq(build.status)
expect(build_data[:allow_failure]).to eq(build.allow_failure)
expect(build_data[:environment]).to be_nil
expect(runner_data).to eq(nil)
expect(project_data).to eq(project.hook_attrs(backward: false))
expect(data[:merge_request]).to be_nil
......@@ -115,5 +116,12 @@ RSpec.describe Gitlab::DataBuilder::Pipeline do
expect(build_data[:id]).to eq(build.id)
end
end
context 'build with environment' do
let!(:build) { create(:ci_build, :teardown_environment, pipeline: pipeline) }
it { expect(build_data[:environment][:name]).to eq(build.expanded_environment_name) }
it { expect(build_data[:environment][:action]).to eq(build.environment_action) }
end
end
end
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