Commit a6ee50ab authored by Phil Hughes's avatar Phil Hughes

Added more field types for merge request widget

Added field types that are needed for the merge request
widget.

https://gitlab.com/gitlab-org/gitlab/-/issues/235716
parent 8300b3cd
...@@ -94,6 +94,9 @@ module Types ...@@ -94,6 +94,9 @@ module Types
field :project, Types::ProjectType, null: true, field :project, Types::ProjectType, null: true,
description: 'Project the pipeline belongs to' description: 'Project the pipeline belongs to'
field :active, GraphQL::BOOLEAN_TYPE, null: false, method: :active?,
description: 'Indicates if the pipeline is active'
def detailed_status def detailed_status
object.detailed_status(context[:current_user]) object.detailed_status(context[:current_user])
end end
......
...@@ -12,6 +12,8 @@ module Types ...@@ -12,6 +12,8 @@ module Types
description: 'ID (global ID) of the commit' description: 'ID (global ID) of the commit'
field :sha, type: GraphQL::STRING_TYPE, null: false, field :sha, type: GraphQL::STRING_TYPE, null: false,
description: 'SHA1 ID of the commit' description: 'SHA1 ID of the commit'
field :short_id, type: GraphQL::STRING_TYPE, null: false,
description: 'Short SHA1 ID of the commit'
field :title, type: GraphQL::STRING_TYPE, null: true, calls_gitaly: true, field :title, type: GraphQL::STRING_TYPE, null: true, calls_gitaly: true,
description: 'Title of the commit message' description: 'Title of the commit message'
markdown_field :title_html, null: true markdown_field :title_html, null: true
......
...@@ -92,6 +92,8 @@ module Types ...@@ -92,6 +92,8 @@ module Types
description: 'Indicates if there is a rebase currently in progress for the merge request' description: 'Indicates if there is a rebase currently in progress for the merge request'
field :default_merge_commit_message, GraphQL::STRING_TYPE, null: true, field :default_merge_commit_message, GraphQL::STRING_TYPE, null: true,
description: 'Default merge commit message of the merge request' 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 :merge_ongoing, GraphQL::BOOLEAN_TYPE, method: :merge_ongoing?, null: false, field :merge_ongoing, GraphQL::BOOLEAN_TYPE, method: :merge_ongoing?, null: false,
description: 'Indicates if a merge is currently occurring' description: 'Indicates if a merge is currently occurring'
field :source_branch_exists, GraphQL::BOOLEAN_TYPE, field :source_branch_exists, GraphQL::BOOLEAN_TYPE,
...@@ -153,6 +155,16 @@ module Types ...@@ -153,6 +155,16 @@ module Types
field :approved_by, Types::UserType.connection_type, null: true, field :approved_by, Types::UserType.connection_type, null: true,
description: 'Users who approved the merge request' 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 :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?,
description: 'Indicates if the merge request has CI'
field :mergeable, GraphQL::BOOLEAN_TYPE, null: false, method: :mergeable?, calls_gitaly: true,
description: 'Indicates if the merge request is mergeable'
field :commits_without_merge_commits, Types::CommitType.connection_type, null: true,
calls_gitaly: true, description: 'Merge request commits excluding merge commits'
def approved_by def approved_by
object.approved_by_users object.approved_by_users
...@@ -203,6 +215,18 @@ module Types ...@@ -203,6 +215,18 @@ module Types
def discussion_locked def discussion_locked
!!object.discussion_locked !!object.discussion_locked
end end
def default_merge_commit_message_with_description
object.default_merge_commit_message(include_description: true)
end
def available_auto_merge_strategies
AutoMergeService.new(object.project, current_user).available_strategies(object)
end
def commits_without_merge_commits
object.recent_commits.without_merge_commits
end
end end
end end
......
...@@ -107,6 +107,8 @@ module Types ...@@ -107,6 +107,8 @@ module Types
description: 'Indicates if issues referenced by merge requests and commits within the default branch are closed automatically' description: 'Indicates if issues referenced by merge requests and commits within the default branch are closed automatically'
field :suggestion_commit_message, GraphQL::STRING_TYPE, null: true, field :suggestion_commit_message, GraphQL::STRING_TYPE, null: true,
description: 'The commit message used to apply merge request suggestions' description: 'The commit message used to apply merge request suggestions'
field :squash_read_only, GraphQL::BOOLEAN_TYPE, null: false, method: :squash_readonly?,
description: 'Indicates if squash readonly is enabled'
field :namespace, Types::NamespaceType, null: true, field :namespace, Types::NamespaceType, null: true,
description: 'Namespace of the project' description: 'Namespace of the project'
......
...@@ -3075,6 +3075,11 @@ type Commit { ...@@ -3075,6 +3075,11 @@ type Commit {
""" """
sha: String! sha: String!
"""
Short SHA1 ID of the commit
"""
shortId: String!
""" """
Rendered HTML of the commit signature Rendered HTML of the commit signature
""" """
...@@ -3168,6 +3173,26 @@ enum CommitActionMode { ...@@ -3168,6 +3173,26 @@ enum CommitActionMode {
UPDATE UPDATE
} }
"""
The connection type for Commit.
"""
type CommitConnection {
"""
A list of edges.
"""
edges: [CommitEdge]
"""
A list of nodes.
"""
nodes: [Commit]
"""
Information to aid in pagination.
"""
pageInfo: PageInfo!
}
""" """
Autogenerated input type of CommitCreate Autogenerated input type of CommitCreate
""" """
...@@ -3223,6 +3248,21 @@ type CommitCreatePayload { ...@@ -3223,6 +3248,21 @@ type CommitCreatePayload {
errors: [String!]! errors: [String!]!
} }
"""
An edge in a connection.
"""
type CommitEdge {
"""
A cursor for use in pagination.
"""
cursor: String!
"""
The item at the end of the edge.
"""
node: Commit
}
enum CommitEncoding { enum CommitEncoding {
""" """
Base64 encoding Base64 encoding
...@@ -12927,11 +12967,41 @@ type MergeRequest implements CurrentUserTodos & Noteable { ...@@ -12927,11 +12967,41 @@ type MergeRequest implements CurrentUserTodos & Noteable {
""" """
autoMergeEnabled: Boolean! autoMergeEnabled: Boolean!
"""
Array of available auto merge strategies
"""
availableAutoMergeStrategies: [String!]
""" """
Number of commits in the merge request Number of commits in the merge request
""" """
commitCount: Int commitCount: Int
"""
Merge request commits excluding merge commits
"""
commitsWithoutMergeCommits(
"""
Returns the elements in the list that come after the specified cursor.
"""
after: String
"""
Returns the elements in the list that come before the specified cursor.
"""
before: String
"""
Returns the first _n_ elements from the list.
"""
first: Int
"""
Returns the last _n_ elements from the list.
"""
last: Int
): CommitConnection
""" """
Indicates if the merge request has conflicts Indicates if the merge request has conflicts
""" """
...@@ -12977,6 +13047,11 @@ type MergeRequest implements CurrentUserTodos & Noteable { ...@@ -12977,6 +13047,11 @@ type MergeRequest implements CurrentUserTodos & Noteable {
""" """
defaultMergeCommitMessage: String defaultMergeCommitMessage: String
"""
Default merge commit message of the merge request with description
"""
defaultMergeCommitMessageWithDescription: String
""" """
Description of the merge request (Markdown rendered as HTML for caching) Description of the merge request (Markdown rendered as HTML for caching)
""" """
...@@ -13052,6 +13127,11 @@ type MergeRequest implements CurrentUserTodos & Noteable { ...@@ -13052,6 +13127,11 @@ type MergeRequest implements CurrentUserTodos & Noteable {
""" """
forceRemoveSourceBranch: Boolean forceRemoveSourceBranch: Boolean
"""
Indicates if the merge request has CI
"""
hasCi: Boolean!
""" """
The pipeline running on the branch HEAD of the merge request The pipeline running on the branch HEAD of the merge request
""" """
...@@ -13117,11 +13197,20 @@ type MergeRequest implements CurrentUserTodos & Noteable { ...@@ -13117,11 +13197,20 @@ type MergeRequest implements CurrentUserTodos & Noteable {
""" """
mergeStatus: String mergeStatus: String
"""
"""
mergeTrainsCount: Int
""" """
Indicates if the merge has been set to be merged when its pipeline succeeds (MWPS) Indicates if the merge has been set to be merged when its pipeline succeeds (MWPS)
""" """
mergeWhenPipelineSucceeds: Boolean mergeWhenPipelineSucceeds: Boolean
"""
Indicates if the merge request is mergeable
"""
mergeable: Boolean!
""" """
Indicates if all discussions in the merge request have been resolved, allowing the merge request to be merged Indicates if all discussions in the merge request have been resolved, allowing the merge request to be merged
""" """
...@@ -13292,6 +13381,11 @@ type MergeRequest implements CurrentUserTodos & Noteable { ...@@ -13292,6 +13381,11 @@ type MergeRequest implements CurrentUserTodos & Noteable {
""" """
sourceProjectId: Int sourceProjectId: Int
"""
Indicates if squash on merge is enabled
"""
squashOnMerge: Boolean!
""" """
State of the merge request State of the merge request
""" """
...@@ -15434,6 +15528,11 @@ type PageInfo { ...@@ -15434,6 +15528,11 @@ type PageInfo {
} }
type Pipeline { type Pipeline {
"""
Indicates if the pipeline is active
"""
active: Boolean!
""" """
Base SHA of the source branch Base SHA of the source branch
""" """
...@@ -17490,6 +17589,11 @@ type Project { ...@@ -17490,6 +17589,11 @@ type Project {
""" """
snippetsEnabled: Boolean snippetsEnabled: Boolean
"""
Indicates if squash readonly is enabled
"""
squashReadOnly: Boolean!
""" """
URL to connect to the project via SSH URL to connect to the project via SSH
""" """
......
...@@ -524,6 +524,7 @@ Represents the code coverage summary for a project. ...@@ -524,6 +524,7 @@ Represents the code coverage summary for a project.
| `message` | String | Raw commit message | | `message` | String | Raw commit message |
| `pipelines` | PipelineConnection | Pipelines of the commit ordered latest first | | `pipelines` | PipelineConnection | Pipelines of the commit ordered latest first |
| `sha` | String! | SHA1 ID of the commit | | `sha` | String! | SHA1 ID of the commit |
| `shortId` | String! | Short SHA1 ID of the commit |
| `signatureHtml` | String | Rendered HTML of the commit signature | | `signatureHtml` | String | Rendered HTML of the commit signature |
| `title` | String | Title of the commit message | | `title` | String | Title of the commit message |
| `titleHtml` | String | The GitLab Flavored Markdown rendering of `title` | | `titleHtml` | String | The GitLab Flavored Markdown rendering of `title` |
...@@ -2013,11 +2014,14 @@ Autogenerated return type of MarkAsSpamSnippet. ...@@ -2013,11 +2014,14 @@ Autogenerated return type of MarkAsSpamSnippet.
| `assignees` | UserConnection | Assignees of the merge request | | `assignees` | UserConnection | Assignees of the merge request |
| `author` | User | User who created this merge request | | `author` | User | User who created this merge request |
| `autoMergeEnabled` | Boolean! | Indicates if auto merge is enabled for the merge request | | `autoMergeEnabled` | Boolean! | Indicates if auto merge is enabled for the merge request |
| `availableAutoMergeStrategies` | String! => Array | Array of available auto merge strategies |
| `commitCount` | Int | Number of commits in the merge request | | `commitCount` | Int | Number of commits in the merge request |
| `commitsWithoutMergeCommits` | CommitConnection | Merge request commits excluding merge commits |
| `conflicts` | Boolean! | Indicates if the merge request has conflicts | | `conflicts` | Boolean! | Indicates if the merge request has conflicts |
| `createdAt` | Time! | Timestamp of when the merge request was created | | `createdAt` | Time! | Timestamp of when the merge request was created |
| `currentUserTodos` | TodoConnection! | Todos for the current user | | `currentUserTodos` | TodoConnection! | Todos for the current user |
| `defaultMergeCommitMessage` | String | Default merge commit message of the merge request | | `defaultMergeCommitMessage` | String | Default merge commit message of the merge request |
| `defaultMergeCommitMessageWithDescription` | String | Default merge commit message of the merge request with description |
| `description` | String | Description of the merge request (Markdown rendered as HTML for caching) | | `description` | String | Description of the merge request (Markdown rendered as HTML for caching) |
| `descriptionHtml` | String | The GitLab Flavored Markdown rendering of `description` | | `descriptionHtml` | String | The GitLab Flavored Markdown rendering of `description` |
| `diffHeadSha` | String | Diff head SHA of the merge request | | `diffHeadSha` | String | Diff head SHA of the merge request |
...@@ -2028,6 +2032,7 @@ Autogenerated return type of MarkAsSpamSnippet. ...@@ -2028,6 +2032,7 @@ Autogenerated return type of MarkAsSpamSnippet.
| `discussions` | DiscussionConnection! | All discussions on this noteable | | `discussions` | DiscussionConnection! | All discussions on this noteable |
| `downvotes` | Int! | Number of downvotes for the merge request | | `downvotes` | Int! | Number of downvotes for the merge request |
| `forceRemoveSourceBranch` | Boolean | Indicates if the project settings will lead to source branch deletion after merge | | `forceRemoveSourceBranch` | Boolean | Indicates if the project settings will lead to source branch deletion after merge |
| `hasCi` | Boolean! | Indicates if the merge request has CI |
| `headPipeline` | Pipeline | The pipeline running on the branch HEAD of the merge request | | `headPipeline` | Pipeline | The pipeline running on the branch HEAD of the merge request |
| `id` | ID! | ID of the merge request | | `id` | ID! | ID of the merge request |
| `iid` | String! | Internal ID of the merge request | | `iid` | String! | Internal ID of the merge request |
...@@ -2037,7 +2042,9 @@ Autogenerated return type of MarkAsSpamSnippet. ...@@ -2037,7 +2042,9 @@ Autogenerated return type of MarkAsSpamSnippet.
| `mergeError` | String | Error message due to a merge error | | `mergeError` | String | Error message due to a merge error |
| `mergeOngoing` | Boolean! | Indicates if a merge is currently occurring | | `mergeOngoing` | Boolean! | Indicates if a merge is currently occurring |
| `mergeStatus` | String | Status of the merge request | | `mergeStatus` | String | Status of the merge request |
| `mergeTrainsCount` | Int | |
| `mergeWhenPipelineSucceeds` | Boolean | Indicates if the merge has been set to be merged when its pipeline succeeds (MWPS) | | `mergeWhenPipelineSucceeds` | Boolean | Indicates if the merge has been set to be merged when its pipeline succeeds (MWPS) |
| `mergeable` | Boolean! | Indicates if the merge request is mergeable |
| `mergeableDiscussionsState` | Boolean | Indicates if all discussions in the merge request have been resolved, allowing the merge request to be merged | | `mergeableDiscussionsState` | Boolean | Indicates if all discussions in the merge request have been resolved, allowing the merge request to be merged |
| `mergedAt` | Time | Timestamp of when the merge request was merged, null if not merged | | `mergedAt` | Time | Timestamp of when the merge request was merged, null if not merged |
| `milestone` | Milestone | The milestone of the merge request | | `milestone` | Milestone | The milestone of the merge request |
...@@ -2056,6 +2063,7 @@ Autogenerated return type of MarkAsSpamSnippet. ...@@ -2056,6 +2063,7 @@ Autogenerated return type of MarkAsSpamSnippet.
| `sourceBranchProtected` | Boolean! | Indicates if the source branch is protected | | `sourceBranchProtected` | Boolean! | Indicates if the source branch is protected |
| `sourceProject` | Project | Source project of the merge request | | `sourceProject` | Project | Source project of the merge request |
| `sourceProjectId` | Int | ID of the merge request source project | | `sourceProjectId` | Int | ID of the merge request source project |
| `squashOnMerge` | Boolean! | Indicates if squash on merge is enabled |
| `state` | MergeRequestState! | State of the merge request | | `state` | MergeRequestState! | State of the merge request |
| `subscribed` | Boolean! | Indicates if the currently logged in user is subscribed to this merge request | | `subscribed` | Boolean! | Indicates if the currently logged in user is subscribed to this merge request |
| `targetBranch` | String! | Target branch of the merge request | | `targetBranch` | String! | Target branch of the merge request |
...@@ -2396,6 +2404,7 @@ Information about pagination in a connection.. ...@@ -2396,6 +2404,7 @@ Information about pagination in a connection..
| Field | Type | Description | | Field | Type | Description |
| ----- | ---- | ----------- | | ----- | ---- | ----------- |
| `active` | Boolean! | Indicates if the pipeline is active |
| `beforeSha` | String | Base SHA of the source branch | | `beforeSha` | String | Base SHA of the source branch |
| `cancelable` | Boolean! | Specifies if a pipeline can be canceled | | `cancelable` | Boolean! | Specifies if a pipeline can be canceled |
| `committedAt` | Time | Timestamp of the pipeline's commit | | `committedAt` | Time | Timestamp of the pipeline's commit |
...@@ -2567,6 +2576,7 @@ Autogenerated return type of PipelineRetry. ...@@ -2567,6 +2576,7 @@ Autogenerated return type of PipelineRetry.
| `sharedRunnersEnabled` | Boolean | Indicates if shared runners are enabled for the project | | `sharedRunnersEnabled` | Boolean | Indicates if shared runners are enabled for the project |
| `snippets` | SnippetConnection | Snippets of the project | | `snippets` | SnippetConnection | Snippets of the project |
| `snippetsEnabled` | Boolean | Indicates if Snippets are enabled for the current user | | `snippetsEnabled` | Boolean | Indicates if Snippets are enabled for the current user |
| `squashReadOnly` | Boolean! | Indicates if squash readonly is enabled |
| `sshUrlToRepo` | String | URL to connect to the project via SSH | | `sshUrlToRepo` | String | URL to connect to the project via SSH |
| `starCount` | Int! | Number of times the project has been starred | | `starCount` | Int! | Number of times the project has been starred |
| `statistics` | ProjectStatistics | Statistics of the project | | `statistics` | ProjectStatistics | Statistics of the project |
......
...@@ -12,6 +12,14 @@ module EE ...@@ -12,6 +12,14 @@ module EE
description: 'Number of approvals left' description: 'Number of approvals left'
field :approvals_required, GraphQL::INT_TYPE, null: true, field :approvals_required, GraphQL::INT_TYPE, null: true,
description: 'Number of approvals required' description: 'Number of approvals required'
field :merge_trains_count, GraphQL::INT_TYPE, null: true,
description: ''
end
def merge_trains_count
return unless object.target_project.merge_trains_enabled?
MergeTrain.total_count_in_train(object)
end end
end end
end end
......
...@@ -6,4 +6,19 @@ RSpec.describe Types::Ci::PipelineType do ...@@ -6,4 +6,19 @@ RSpec.describe Types::Ci::PipelineType do
specify { expect(described_class.graphql_name).to eq('Pipeline') } specify { expect(described_class.graphql_name).to eq('Pipeline') }
specify { expect(described_class).to expose_permissions_using(Types::PermissionTypes::Ci::Pipeline) } specify { expect(described_class).to expose_permissions_using(Types::PermissionTypes::Ci::Pipeline) }
it 'contains attributes related to a pipeline' do
expected_fields = %w[
id iid sha before_sha status detailed_status config_source duration
coverage created_at updated_at started_at finished_at committed_at
stages user retryable cancelable jobs source_job downstream
upstream path project active user_permissions
]
if Gitlab.ee?
expected_fields << 'security_report_summary'
end
expect(described_class).to have_graphql_fields(*expected_fields)
end
end end
...@@ -9,7 +9,7 @@ RSpec.describe GitlabSchema.types['Commit'] do ...@@ -9,7 +9,7 @@ RSpec.describe GitlabSchema.types['Commit'] do
it 'contains attributes related to commit' do it 'contains attributes related to commit' do
expect(described_class).to have_graphql_fields( expect(described_class).to have_graphql_fields(
:id, :sha, :title, :description, :description_html, :message, :title_html, :authored_date, :id, :sha, :short_id, :title, :description, :description_html, :message, :title_html, :authored_date,
:author_name, :author_gravatar, :author, :web_url, :web_path, :author_name, :author_gravatar, :author, :web_url, :web_path,
:pipelines, :signature_html :pipelines, :signature_html
) )
......
...@@ -28,12 +28,15 @@ RSpec.describe GitlabSchema.types['MergeRequest'] do ...@@ -28,12 +28,15 @@ RSpec.describe GitlabSchema.types['MergeRequest'] do
milestone assignees participants subscribed labels discussion_locked time_estimate milestone assignees participants subscribed labels discussion_locked time_estimate
total_time_spent reference author merged_at commit_count current_user_todos total_time_spent reference author merged_at commit_count current_user_todos
conflicts auto_merge_enabled approved_by source_branch_protected 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
] ]
if Gitlab.ee? if Gitlab.ee?
expected_fields << 'approved' expected_fields << 'approved'
expected_fields << 'approvals_left' expected_fields << 'approvals_left'
expected_fields << 'approvals_required' expected_fields << 'approvals_required'
expected_fields << 'merge_trains_count'
end end
expect(described_class).to have_graphql_fields(*expected_fields) expect(described_class).to have_graphql_fields(*expected_fields)
......
...@@ -31,7 +31,7 @@ RSpec.describe GitlabSchema.types['Project'] do ...@@ -31,7 +31,7 @@ RSpec.describe GitlabSchema.types['Project'] do
container_expiration_policy service_desk_enabled service_desk_address container_expiration_policy service_desk_enabled service_desk_address
issue_status_counts terraform_states alert_management_integrations issue_status_counts terraform_states alert_management_integrations
container_repositories container_repositories_count container_repositories container_repositories_count
pipeline_analytics total_pipeline_duration pipeline_analytics total_pipeline_duration squash_read_only
] ]
expect(described_class).to include_graphql_fields(*expected_fields) expect(described_class).to include_graphql_fields(*expected_fields)
......
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