Commit bf2faf39 authored by Phil Hughes's avatar Phil Hughes

Use headPipeline in GraphQL widget queries

Closes https://gitlab.com/gitlab-org/gitlab/-/issues/323913
parent fe2022ba
...@@ -124,7 +124,7 @@ export default { ...@@ -124,7 +124,7 @@ export default {
}, },
pipeline() { pipeline() {
if (this.glFeatures.mergeRequestWidgetGraphql) { if (this.glFeatures.mergeRequestWidgetGraphql) {
return this.state.pipelines?.nodes?.[0]; return this.state.headPipeline;
} }
return this.mr.pipeline; return this.mr.pipeline;
......
...@@ -11,12 +11,11 @@ query getState($projectPath: ID!, $iid: String!) { ...@@ -11,12 +11,11 @@ query getState($projectPath: ID!, $iid: String!) {
mergeError mergeError
mergeStatus mergeStatus
mergeableDiscussionsState mergeableDiscussionsState
pipelines(first: 1) { headPipeline {
nodes { id
status status
warnings warnings
} }
}
shouldBeRebased shouldBeRebased
sourceBranchExists sourceBranchExists
state state
......
...@@ -30,13 +30,11 @@ fragment ReadyToMerge on Project { ...@@ -30,13 +30,11 @@ fragment ReadyToMerge on Project {
message message
} }
} }
pipelines(first: 1) { headPipeline {
nodes {
id id
status status
path path
active active
} }
} }
}
} }
...@@ -163,7 +163,7 @@ export default class MergeRequestStore { ...@@ -163,7 +163,7 @@ export default class MergeRequestStore {
setGraphqlData(project) { setGraphqlData(project) {
const { mergeRequest } = project; const { mergeRequest } = project;
const pipeline = mergeRequest.pipelines?.nodes?.[0]; const pipeline = mergeRequest.headPipeline;
this.projectArchived = project.archived; this.projectArchived = project.archived;
this.onlyAllowMergeIfPipelineSucceeds = project.onlyAllowMergeIfPipelineSucceeds; this.onlyAllowMergeIfPipelineSucceeds = project.onlyAllowMergeIfPipelineSucceeds;
......
...@@ -17,6 +17,7 @@ RSpec.describe 'User adds a merge request to a merge train', :js do ...@@ -17,6 +17,7 @@ RSpec.describe 'User adds a merge request to a merge train', :js do
end end
before do before do
stub_const('Gitlab::QueryLimiting::Transaction::THRESHOLD', 200)
stub_feature_flags(disable_merge_trains: false) stub_feature_flags(disable_merge_trains: false)
stub_licensed_features(merge_pipelines: true, merge_trains: true) stub_licensed_features(merge_pipelines: true, merge_trains: true)
project.add_maintainer(user) project.add_maintainer(user)
...@@ -84,6 +85,12 @@ RSpec.describe 'User adds a merge request to a merge train', :js do ...@@ -84,6 +85,12 @@ RSpec.describe 'User adds a merge request to a merge train', :js do
context "when user clicks 'Remove from merge train' button" do context "when user clicks 'Remove from merge train' button" do
before do before do
click_link 'Remove from merge train' click_link 'Remove from merge train'
# Currently, this page shows "Add to merge train" button instead of "Start merge train",
# even though the merge train is empty.
# This likely is caused by the stale cache in client side. Frontend
# would need to refresh the mergiability data, specifically `stateData.mergeTrainsCount` periodically e.g. polling.
# As a workaround, we're doing a hard reload by executing `visit` here.
visit project_merge_request_path(project, merge_request)
end end
it 'cancels automatic merge' do it 'cancels automatic merge' do
......
...@@ -333,6 +333,31 @@ RSpec.describe 'Merge request > User sees pipelines triggered by merge request', ...@@ -333,6 +333,31 @@ RSpec.describe 'Merge request > User sees pipelines triggered by merge request',
end end
end end
context 'when the latest pipeline is running in the parent project' do
before do
Ci::CreatePipelineService.new(project, user, ref: 'feature')
.execute(:merge_request_event, merge_request: merge_request)
end
context 'when the previous pipeline failed in the fork project' do
before do
detached_merge_request_pipeline.drop!
end
context 'when the parent project enables pipeline must succeed' do
before do
project.update!(only_allow_merge_if_pipeline_succeeds: true)
end
it 'shows MWPS button' do
visit project_merge_request_path(project, merge_request)
expect(page).to have_button('Merge when pipeline succeeds')
end
end
end
end
context 'when a user merges a merge request from a forked project to the parent project' do context 'when a user merges a merge request from a forked project to the parent project' do
before do before do
click_link("Overview") click_link("Overview")
......
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