OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
[#54122] GitLab integration pipeline status not updated
Judith Rothaa7a8cfaaf4d
diff --git a/modules/gitlab_integration/app/models/gitlab_merge_request.rb b/modules/gitlab_integration/app/models/gitlab_merge_request.rbindex 77724d3b534..6c2dd089fb2 100644--- a/modules/gitlab_integration/app/models/gitlab_merge_request.rb+++ b/modules/gitlab_integration/app/models/gitlab_merge_request.rb@@ -73,8 +73,8 @@ class GitlabMergeRequest < ApplicationRecorddef latest_pipelineswith_logging do- gitlab_pipelines.select("DISTINCT ON (gitlab_pipelines.project_id, gitlab_pipelines.name) *")- .order(project_id: :asc, name: :asc, started_at: :desc)+ gitlab_pipelines.select("DISTINCT ON (gitlab_pipelines.project_id, gitlab_pipelines.gitlab_id) *")+ .order(project_id: :asc, gitlab_id: :desc, started_at: :desc)endenddiff --git a/modules/gitlab_integration/spec/models/gitlab_merge_request_spec.rb b/modules/gitlab_integration/spec/models/gitlab_merge_request_spec.rbindex 30050f24441..b38067e3568 100644--- a/modules/gitlab_integration/spec/models/gitlab_merge_request_spec.rb+++ b/modules/gitlab_integration/spec/models/gitlab_merge_request_spec.rb@@ -186,11 +186,37 @@ RSpec.describe GitlabMergeRequest docontext "when multiple pipelines for the same merge request exist" doshared_association_default(:gitlab_merge_request) { create(:gitlab_merge_request) }- shared_let(:latest_pipelines) { create_list(:gitlab_pipeline, 2, :recent, project_id: 123) }- shared_let(:outdated_pipelines) { create_list(:gitlab_pipeline, 2, :outdated, project_id: 123) }+ context "when the piplelines are for multiple projects" do+ let!(:second_pipeline) { create(:gitlab_pipeline, project_id: 112, gitlab_id: 3) }+ let!(:first_pipeline) { create(:gitlab_pipeline, project_id: 111, gitlab_id: 2) }+ let!(:third_pipeline) { create(:gitlab_pipeline, project_id: 113, gitlab_id: 1) }++ it "they are ordered by project_id asc" do+ expect(gitlab_merge_request.reload.latest_pipelines.to_a)+ .to eql([first_pipeline, second_pipeline, third_pipeline])+ end+ end++ context "when the pipelines are for the same project" do+ let!(:second_pipeline) { create(:gitlab_pipeline, project_id: 123, gitlab_id: 10) }+ let!(:first_pipeline) { create(:gitlab_pipeline, project_id: 123, gitlab_id: 11) }+ let!(:third_pipeline) { create(:gitlab_pipeline, project_id: 123, gitlab_id: 9) }++ it "they are ordered by gitlab_id desc (not name, which is a string consisting of the gitlab_id and would lead to a wrong sorting)" do # rubocop:disable Layout/LineLength+ expect(gitlab_merge_request.reload.latest_pipelines.to_a)+ .to eql([first_pipeline, second_pipeline, third_pipeline])+ end+ end++ context "when the pipelines are for the same project and same gitlab_id" do+ let!(:second_pipeline) { create(:gitlab_pipeline, project_id: 123, gitlab_id: 1, started_at: 2.hours.ago) }+ let!(:first_pipeline) { create(:gitlab_pipeline, project_id: 123, gitlab_id: 1, started_at: 3.hours.ago) }+ let!(:third_pipeline) { create(:gitlab_pipeline, project_id: 123, gitlab_id: 1, started_at: 1.hour.ago) }- it "returns the latest pipeline ordered from most recent" do- expect(gitlab_merge_request.reload.latest_pipelines).to match_array(latest_pipelines + outdated_pipelines)+ it "only returns the most recent pipeline and ignores the others" do+ expect(gitlab_merge_request.reload.latest_pipelines.to_a)+ .to eql([third_pipeline])+ endendendend