BigW Consortium Gitlab

Commit 07fc2f85 by Z.J. van de Weg

Method names changed to #includes_commit?

parent 03ea0194
...@@ -69,6 +69,10 @@ ...@@ -69,6 +69,10 @@
&.ci-success { &.ci-success {
color: $gl-success; color: $gl-success;
a.environment {
color: inherit;
}
} }
&.ci-success_with_warnings { &.ci-success_with_warnings {
...@@ -126,7 +130,6 @@ ...@@ -126,7 +130,6 @@
&.has-conflicts .fa-exclamation-triangle { &.has-conflicts .fa-exclamation-triangle {
color: $gl-warning; color: $gl-warning;
} }
} }
p:last-child { p:last-child {
......
...@@ -37,8 +37,7 @@ class Deployment < ActiveRecord::Base ...@@ -37,8 +37,7 @@ class Deployment < ActiveRecord::Base
deployable.try(:other_actions) deployable.try(:other_actions)
end end
def deployed_to?(ref) def includes_commit?(commit)
commit = project.commit(ref)
return false unless commit return false unless commit
project.repository.is_ancestor?(commit.id, sha) project.repository.is_ancestor?(commit.id, sha)
......
...@@ -26,9 +26,9 @@ class Environment < ActiveRecord::Base ...@@ -26,9 +26,9 @@ class Environment < ActiveRecord::Base
self.external_url = nil if self.external_url.blank? self.external_url = nil if self.external_url.blank?
end end
def deployed_from?(ref) def includes_commit?(commit)
return false unless last_deployment return false unless last_deployment
last_deployment.deployed_to?(ref) last_deployment.includes_commit?(commit)
end end
end end
...@@ -591,8 +591,10 @@ class MergeRequest < ActiveRecord::Base ...@@ -591,8 +591,10 @@ class MergeRequest < ActiveRecord::Base
end end
def environments def environments
return unless diff_head_commit
target_project.environments.select do |environment| target_project.environments.select do |environment|
environment.deployed_from?(ref_path) environment.includes_commit?(diff_head_commit)
end end
end end
......
...@@ -45,10 +45,13 @@ ...@@ -45,10 +45,13 @@
- @merge_request.environments.each do |environment| - @merge_request.environments.each do |environment|
.mr-widget-heading .mr-widget-heading
.ci_widget{ class: "ci-success" } .ci_widget.ci-success
= ci_icon_for_status("success") = ci_icon_for_status("success")
%span.hidden-sm %span.hidden-sm
Released to #{environment.name}. Deployed to
= succeed '.' do
= link_to environment.name, namespace_project_environment_path(@project.namespace, @project, environment), class: 'environment'
- external_url = environment.external_url - external_url = environment.external_url
- if external_url - if external_url
= link_to icon('external-link', text: "View on #{external_url.gsub(/\A.*?:\/\//, '')}"), external_url = link_to external_url, target: '_blank' do
= icon('external-link', text: "View on #{external_url.gsub(/\A.*?:\/\//, '')}", right: true)
...@@ -589,12 +589,12 @@ ActiveRecord::Schema.define(version: 20160810142633) do ...@@ -589,12 +589,12 @@ ActiveRecord::Schema.define(version: 20160810142633) do
t.datetime "locked_at" t.datetime "locked_at"
t.integer "updated_by_id" t.integer "updated_by_id"
t.string "merge_error" t.string "merge_error"
t.text "merge_params"
t.boolean "merge_when_build_succeeds", default: false, null: false t.boolean "merge_when_build_succeeds", default: false, null: false
t.integer "merge_user_id" t.integer "merge_user_id"
t.string "merge_commit_sha" t.string "merge_commit_sha"
t.datetime "deleted_at" t.datetime "deleted_at"
t.string "in_progress_merge_commit_sha" t.string "in_progress_merge_commit_sha"
t.text "merge_params"
end end
add_index "merge_requests", ["assignee_id"], name: "index_merge_requests_on_assignee_id", using: :btree add_index "merge_requests", ["assignee_id"], name: "index_merge_requests_on_assignee_id", using: :btree
......
...@@ -16,23 +16,26 @@ describe Deployment, models: true do ...@@ -16,23 +16,26 @@ describe Deployment, models: true do
it { is_expected.to validate_presence_of(:ref) } it { is_expected.to validate_presence_of(:ref) }
it { is_expected.to validate_presence_of(:sha) } it { is_expected.to validate_presence_of(:sha) }
describe '#deployed_to?' do describe '#includes_commit?' do
let(:project) { create(:project) } let(:project) { create(:project) }
let(:environment) { create(:environment, project: project) } let(:environment) { create(:environment, project: project) }
let(:deployment) do let(:deployment) do
create(:deployment, environment: environment, create(:deployment, environment: environment, sha: project.commit.id)
sha: '5f923865dde3436854e9ceb9cdb7815618d4e849')
end end
context 'when there is no project commit' do context 'when there is no project commit' do
it 'returns false' do it 'returns false' do
expect(deployment.deployed_to?('random-branch')).to be false commit = project.commit('feature')
expect(deployment.includes_commit?(commit)).to be false
end end
end end
context 'when they share the same tree branch' do context 'when they share the same tree branch' do
it 'returns true' do it 'returns true' do
expect(deployment.deployed_to?('HEAD')).to be true commit = project.commit
expect(deployment.includes_commit?(commit)).to be true
end end
end end
end end
......
...@@ -31,12 +31,35 @@ describe Environment, models: true do ...@@ -31,12 +31,35 @@ describe Environment, models: true do
end end
end end
describe '#deployed_from?' do describe '#includes_commit?' do
let(:environment) { create(:environment) }
context 'without a last deployment' do context 'without a last deployment' do
it "returns false" do it "returns false" do
expect(environment.deployed_from?('HEAD')).to be false expect(environment.includes_commit?('HEAD')).to be false
end
end
context 'with a last deployment' do
let(:project) { create(:project) }
let(:environment) { create(:environment, project: project) }
let!(:deployment) do
create(:deployment, environment: environment, sha: project.commit('master').id)
end
context 'in the same branch' do
it 'returns true' do
expect(environment.includes_commit?(RepoHelpers.sample_commit)).to be true
end
end
context 'not in the same branch' do
before do
deployment.update(sha: project.commit('feature').id)
end
it 'returns false' do
expect(environment.includes_commit?(RepoHelpers.sample_commit)).to be false
end
end end
end end
end end
......
...@@ -676,18 +676,15 @@ describe MergeRequest, models: true do ...@@ -676,18 +676,15 @@ describe MergeRequest, models: true do
describe "#environments" do describe "#environments" do
let(:project) { create(:project) } let(:project) { create(:project) }
let!(:deployment) do
create(:deployment, environment: environment,
sha: '5f923865dde3436854e9ceb9cdb7815618d4e849')
end
let!(:environment) { create(:environment, project: project) } let!(:environment) { create(:environment, project: project) }
let!(:environment1) { create(:environment, project: project) } let!(:environment1) { create(:environment, project: project) }
let!(:environment2) { create(:environment, project: project) }
let(:merge_request) { create(:merge_request, source_project: project) } let(:merge_request) { create(:merge_request, source_project: project) }
it 'selects deployed environments' do it 'selects deployed environments' do
create(:deployment, environment: environment, sha: project.commit('master').id)
create(:deployment, environment: environment1, sha: project.commit('feature').id)
expect(merge_request.environments).to eq [environment] expect(merge_request.environments).to eq [environment]
end end
end end
......
...@@ -8,18 +8,19 @@ describe 'projects/merge_requests/widget/_heading' do ...@@ -8,18 +8,19 @@ describe 'projects/merge_requests/widget/_heading' do
let(:merge_request) { create(:merge_request, :merged) } let(:merge_request) { create(:merge_request, :merged) }
let(:environment) { create(:environment, project: project) } let(:environment) { create(:environment, project: project) }
let!(:deployment) do let!(:deployment) do
create(:deployment, environment: environment, create(:deployment, environment: environment, sha: project.commit('master').id)
sha: 'a5391128b0ef5d21df5dd23d98557f4ef12fae20')
end end
before do before do
assign(:merge_request, merge_request) assign(:merge_request, merge_request)
assign(:project, project)
render render
end end
it 'displays that the environment is deployed' do it 'displays that the environment is deployed' do
expect(rendered).to match("Released to #{environment.name}") expect(rendered).to match("Deployed to")
expect(rendered).to match("#{environment.name}")
end end
end 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