Skip to content

Commit

Permalink
Fix mr pipeline detection for child pipelines (#610)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrcuns authored Dec 11, 2023
1 parent 95a938d commit cdb49e8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
8 changes: 1 addition & 7 deletions lib/allure_report_publisher/lib/providers/gitlab.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class Gitlab < Provider

def_delegators :"Publisher::Providers::Info::Gitlab.instance",
:allure_project,
:mr_iid,
:allure_mr_iid,
:server_url,
:build_name
Expand Down Expand Up @@ -68,13 +69,6 @@ def project
@project ||= allure_project || env("CI_MERGE_REQUEST_PROJECT_PATH") || env("CI_PROJECT_PATH")
end

# Merge request iid
#
# @return [Integer]
def mr_iid
@mr_iid ||= allure_mr_iid || env("CI_MERGE_REQUEST_IID")
end

# Commit sha url
#
# @return [String]
Expand Down
9 changes: 8 additions & 1 deletion lib/allure_report_publisher/lib/providers/info/gitlab.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def executor(report_url)
#
# @return [Boolean]
def pr?
!!(allure_project && allure_mr_iid) || ENV["CI_PIPELINE_SOURCE"] == "merge_request_event"
!!((allure_project && allure_mr_iid) || mr_iid)
end

# Get ci run ID without creating instance of ci provider
Expand Down Expand Up @@ -58,6 +58,13 @@ def allure_project
@allure_project ||= env("ALLURE_PROJECT_PATH")
end

# Merge request iid
#
# @return [Integer]
def mr_iid
@mr_iid ||= allure_mr_iid || env("CI_MERGE_REQUEST_IID")
end

# Custom mr iid name
#
# @return [String]
Expand Down
10 changes: 5 additions & 5 deletions spec/allure_report_publisher/lib/providers/info/gitlab_spec.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
RSpec.describe Publisher::Providers::Info::Gitlab, epic: "providers" do
subject(:pr) { described_class.instance.pr? }

let(:mr_iid) { nil }
let(:allure_project) { nil }
let(:allure_mr_iid) { nil }
let(:pipeline_source) { "push" }

let(:env) do
{
ALLURE_PROJECT_PATH: allure_project,
ALLURE_MERGE_REQUEST_IID: allure_mr_iid,
CI_PIPELINE_SOURCE: pipeline_source
CI_MERGE_REQUEST_IID: mr_iid
}
end

Expand All @@ -18,12 +18,12 @@
end

describe "#pr?" do
context "with push event" do
context "with non merge request pipeline" do
it { is_expected.to be(false) }
end

context "with merge request event" do
let(:pipeline_source) { "merge_request_event" }
context "with merge request pipeline" do
let(:mr_iid) { "1" }

it { is_expected.to be(true) }
end
Expand Down

0 comments on commit cdb49e8

Please sign in to comment.