Commit 821d053d authored by Igor Drozdov's avatar Igor Drozdov

Merge branch 'ph/235716/readyToMergeGraphql' into 'master'

Move the ready to merge state to GraphQL

See merge request gitlab-org/gitlab!49948
parents d4ed85ad f680c29f
......@@ -25,12 +25,13 @@ export default {
class="mr-commit-dropdown"
>
<gl-dropdown-item
v-for="commit in commits"
:key="commit.short_id"
v-for="(commit, index) in commits"
:key="index"
class="text-nowrap text-truncate"
@click="$emit('input', commit.message)"
>
<span class="monospace mr-2">{{ commit.short_id }}</span> {{ commit.title }}
<span class="monospace mr-2">{{ commit.shortId || commit.short_id }}</span>
{{ commit.title }}
</gl-dropdown-item>
</gl-dropdown>
</div>
......
......@@ -27,7 +27,7 @@ export default {
return __('Merge when pipeline succeeds');
},
shouldShowMergeImmediatelyDropdown() {
return this.mr.isPipelineActive && !this.mr.onlyAllowMergeIfPipelineSucceeds;
return this.isPipelineActive && !this.stateData.onlyAllowMergeIfPipelineSucceeds;
},
isMergeImmediatelyDangerous() {
return false;
......
fragment ReadyToMerge on Project {
onlyAllowMergeIfPipelineSucceeds
mergeRequestsFfOnlyEnabled
squashReadOnly
mergeRequest(iid: $iid) {
autoMergeEnabled
shouldRemoveSourceBranch
defaultMergeCommitMessage
defaultMergeCommitMessageWithDescription
defaultSquashCommitMessage
squash
squashOnMerge
availableAutoMergeStrategies
hasCi
mergeable
mergeWhenPipelineSucceeds
commitCount
diffHeadSha
userPermissions {
removeSourceBranch
}
targetBranch
mergeError
commitsWithoutMergeCommits {
nodes {
sha
shortId
title
message
}
}
pipelines(first: 1) {
nodes {
id
status
path
active
}
}
}
}
#import "./ready_to_merge.fragment.graphql"
query readyToMergeQuery($projectPath: ID!, $iid: String!) {
project(fullPath: $projectPath) {
...ReadyToMerge
}
}
......@@ -167,7 +167,7 @@ export default class MergeRequestStore {
this.canBeMerged = mergeRequest.mergeStatus === 'can_be_merged';
this.canMerge = mergeRequest.userPermissions.canMerge;
this.ciStatus = pipeline?.status.toLowerCase();
this.commitsCount = mergeRequest.commitCount;
this.commitsCount = mergeRequest.commitCount || 10;
this.branchMissing = !mergeRequest.sourceBranchExists || !mergeRequest.targetBranchExists;
this.hasConflicts = mergeRequest.conflicts;
this.hasMergeableDiscussionsState = mergeRequest.mergeableDiscussionsState === false;
......
......@@ -1016,3 +1016,11 @@ $mr-widget-min-height: 69px;
vertical-align: middle;
}
}
.mr-ready-to-merge-loader {
max-width: 418px;
> svg {
vertical-align: middle;
}
}
......@@ -96,6 +96,8 @@ module Types
description: 'Default merge commit message of the merge request'
field :default_merge_commit_message_with_description, GraphQL::STRING_TYPE, null: true,
description: 'Default merge commit message of the merge request with description'
field :default_squash_commit_message, GraphQL::STRING_TYPE, null: true, calls_gitaly: true,
description: 'Default squash commit message of the merge request'
field :merge_ongoing, GraphQL::BOOLEAN_TYPE, method: :merge_ongoing?, null: false,
description: 'Indicates if a merge is currently occurring'
field :source_branch_exists, GraphQL::BOOLEAN_TYPE,
......@@ -161,6 +163,8 @@ module Types
description: 'Users who approved the merge request'
field :squash_on_merge, GraphQL::BOOLEAN_TYPE, null: false, method: :squash_on_merge?,
description: 'Indicates if squash on merge is enabled'
field :squash, GraphQL::BOOLEAN_TYPE, null: false,
description: 'Indicates if squash on merge is enabled'
field :available_auto_merge_strategies, [GraphQL::STRING_TYPE], null: true, calls_gitaly: true,
description: 'Array of available auto merge strategies'
field :has_ci, GraphQL::BOOLEAN_TYPE, null: false, method: :has_ci?,
......
......@@ -13754,6 +13754,11 @@ type MergeRequest implements CurrentUserTodos & Noteable {
"""
defaultMergeCommitMessageWithDescription: String
"""
Default squash commit message of the merge request
"""
defaultSquashCommitMessage: String
"""
Description of the merge request (Markdown rendered as HTML for caching)
"""
......@@ -14114,6 +14119,11 @@ type MergeRequest implements CurrentUserTodos & Noteable {
"""
sourceProjectId: Int
"""
Indicates if squash on merge is enabled
"""
squash: Boolean!
"""
Indicates if squash on merge is enabled
"""
......
......@@ -37758,6 +37758,20 @@
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "defaultSquashCommitMessage",
"description": "Default squash commit message of the merge request",
"args": [
],
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "description",
"description": "Description of the merge request (Markdown rendered as HTML for caching)",
......@@ -38718,6 +38732,24 @@
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "squash",
"description": "Indicates if squash on merge is enabled",
"args": [
],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "Boolean",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "squashOnMerge",
"description": "Indicates if squash on merge is enabled",
......@@ -2082,6 +2082,7 @@ Autogenerated return type of MarkAsSpamSnippet.
| `currentUserTodos` | TodoConnection! | Todos for the current user |
| `defaultMergeCommitMessage` | String | Default merge commit message of the merge request |
| `defaultMergeCommitMessageWithDescription` | String | Default merge commit message of the merge request with description |
| `defaultSquashCommitMessage` | String | Default squash commit message of the merge request |
| `description` | String | Description of the merge request (Markdown rendered as HTML for caching) |
| `descriptionHtml` | String | The GitLab Flavored Markdown rendering of `description` |
| `diffHeadSha` | String | Diff head SHA of the merge request |
......@@ -2125,6 +2126,7 @@ Autogenerated return type of MarkAsSpamSnippet.
| `sourceBranchProtected` | Boolean! | Indicates if the source branch is protected |
| `sourceProject` | Project | Source project of the merge request |
| `sourceProjectId` | Int | ID of the merge request source project |
| `squash` | Boolean! | Indicates if squash on merge is enabled |
| `squashOnMerge` | Boolean! | Indicates if squash on merge is enabled |
| `state` | MergeRequestState! | State of the merge request |
| `subscribed` | Boolean! | Indicates if the currently logged in user is subscribed to this merge request |
......
......@@ -36,13 +36,13 @@ export default {
return PIPELINE_MUST_SUCCEED_CONFLICT_TEXT;
},
autoMergeText() {
if (this.mr.preferredAutoMergeStrategy === MTWPS_MERGE_STRATEGY) {
if (this.mr.mergeTrainsCount === 0) {
if (this.preferredAutoMergeStrategy === MTWPS_MERGE_STRATEGY) {
if (this.stateData.mergeTrainsCount === 0) {
return __('Start merge train when pipeline succeeds');
}
return __('Add to merge train when pipeline succeeds');
} else if (this.mr.preferredAutoMergeStrategy === MT_MERGE_STRATEGY) {
if (this.mr.mergeTrainsCount === 0) {
} else if (this.preferredAutoMergeStrategy === MT_MERGE_STRATEGY) {
if (this.stateData.mergeTrainsCount === 0) {
return __('Start merge train');
}
return __('Add to merge train');
......@@ -51,22 +51,22 @@ export default {
},
shouldRenderMergeTrainHelperText() {
return (
this.mr.pipeline &&
isNumber(this.mr.pipeline.id) &&
isString(this.mr.pipeline.path) &&
this.mr.preferredAutoMergeStrategy === MTWPS_MERGE_STRATEGY &&
!this.mr.autoMergeEnabled
this.pipeline &&
isNumber(this.pipeline.id) &&
isString(this.pipeline.path) &&
this.preferredAutoMergeStrategy === MTWPS_MERGE_STRATEGY &&
!this.stateData.autoMergeEnabled
);
},
shouldShowMergeImmediatelyDropdown() {
if (this.mr.preferredAutoMergeStrategy === MT_MERGE_STRATEGY) {
if (this.preferredAutoMergeStrategy === MT_MERGE_STRATEGY) {
return true;
}
return this.mr.isPipelineActive && !this.mr.onlyAllowMergeIfPipelineSucceeds;
return this.isPipelineActive && !this.stateData.onlyAllowMergeIfPipelineSucceeds;
},
isMergeImmediatelyDangerous() {
return [MT_MERGE_STRATEGY, MTWPS_MERGE_STRATEGY].includes(this.mr.preferredAutoMergeStrategy);
return [MT_MERGE_STRATEGY, MTWPS_MERGE_STRATEGY].includes(this.preferredAutoMergeStrategy);
},
},
};
#import "~/vue_merge_request_widget/queries/states/ready_to_merge.fragment.graphql"
query readyToMergeQuery($projectPath: ID!, $iid: String!) {
project(fullPath: $projectPath) {
...ReadyToMerge
mergeRequest(iid: $iid) {
mergeTrainsCount
}
}
}
......@@ -47,7 +47,8 @@ describe('Commits message dropdown component', () => {
});
it('should have correct message for the first dropdown list element', () => {
expect(findFirstDropdownElement().text()).toBe('78d5b7 Commit 1');
expect(findFirstDropdownElement().text()).toContain('78d5b7');
expect(findFirstDropdownElement().text()).toContain('Commit 1');
});
it('should emit a commit title on selecting commit', () => {
......
......@@ -29,7 +29,7 @@ RSpec.describe GitlabSchema.types['MergeRequest'] do
total_time_spent reference author merged_at commit_count current_user_todos
conflicts auto_merge_enabled approved_by source_branch_protected
default_merge_commit_message_with_description squash_on_merge available_auto_merge_strategies
has_ci mergeable commits_without_merge_commits security_auto_fix
has_ci mergeable commits_without_merge_commits squash security_auto_fix default_squash_commit_message
]
if Gitlab.ee?
......
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