Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-06-25 09:08:50 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-06-25 09:08:50 +0300
commitd7d3c0922dfd2f97ae4e08bba3ad5ff8e702772f (patch)
treea6a733d7124f85ca89a19c1a8576c854cfe3c71b /app/graphql
parent03c38e31112a7dc0de78325e5421e6bb08c508ed (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/graphql')
-rw-r--r--app/graphql/types/diff_stats_summary_type.rb23
-rw-r--r--app/graphql/types/diff_stats_type.rb19
-rw-r--r--app/graphql/types/merge_request_type.rb26
3 files changed, 68 insertions, 0 deletions
diff --git a/app/graphql/types/diff_stats_summary_type.rb b/app/graphql/types/diff_stats_summary_type.rb
new file mode 100644
index 00000000000..5920f3de3da
--- /dev/null
+++ b/app/graphql/types/diff_stats_summary_type.rb
@@ -0,0 +1,23 @@
+# frozen_string_literal: true
+
+module Types
+ # rubocop: disable Graphql/AuthorizeTypes
+ # Types that use DiffStatsType should have their own authorization
+ class DiffStatsSummaryType < BaseObject
+ graphql_name 'DiffStatsSummary'
+
+ description 'Aggregated summary of changes'
+
+ field :additions, GraphQL::INT_TYPE, null: false,
+ description: 'Number of lines added'
+ field :deletions, GraphQL::INT_TYPE, null: false,
+ description: 'Number of lines deleted'
+ field :changes, GraphQL::INT_TYPE, null: false,
+ description: 'Number of lines changed'
+
+ def changes
+ object[:additions] + object[:deletions]
+ end
+ end
+ # rubocop: enable Graphql/AuthorizeTypes
+end
diff --git a/app/graphql/types/diff_stats_type.rb b/app/graphql/types/diff_stats_type.rb
new file mode 100644
index 00000000000..6c79a4c389d
--- /dev/null
+++ b/app/graphql/types/diff_stats_type.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+module Types
+ # rubocop: disable Graphql/AuthorizeTypes
+ # Types that use DiffStatsType should have their own authorization
+ class DiffStatsType < BaseObject
+ graphql_name 'DiffStats'
+
+ description 'Changes to a single file'
+
+ field :path, GraphQL::STRING_TYPE, null: false,
+ description: 'File path, relative to repository root'
+ field :additions, GraphQL::INT_TYPE, null: false,
+ description: 'Number of lines added to this file'
+ field :deletions, GraphQL::INT_TYPE, null: false,
+ description: 'Number of lines deleted from this file'
+ end
+ # rubocop: enable Graphql/AuthorizeTypes
+end
diff --git a/app/graphql/types/merge_request_type.rb b/app/graphql/types/merge_request_type.rb
index cb4ff7ea0c5..5c1f82cdf1d 100644
--- a/app/graphql/types/merge_request_type.rb
+++ b/app/graphql/types/merge_request_type.rb
@@ -54,6 +54,13 @@ module Types
description: 'Indicates if the merge has been set to be merged when its pipeline succeeds (MWPS)'
field :diff_head_sha, GraphQL::STRING_TYPE, null: true,
description: 'Diff head SHA of the merge request'
+ field :diff_stats, [Types::DiffStatsType], null: true, calls_gitaly: true,
+ description: 'Details about which files were changed in this merge request' do
+ argument :path, GraphQL::STRING_TYPE, required: false, description: 'A specific file-path'
+ end
+
+ field :diff_stats_summary, Types::DiffStatsSummaryType, null: true, calls_gitaly: true,
+ description: 'Summary of which files were changed in this merge request'
field :merge_commit_sha, GraphQL::STRING_TYPE, null: true,
description: 'SHA of the merge request commit (set once merged)'
field :user_notes_count, GraphQL::INT_TYPE, null: true,
@@ -134,5 +141,24 @@ module Types
end
field :task_completion_status, Types::TaskCompletionStatus, null: false,
description: Types::TaskCompletionStatus.description
+
+ def diff_stats(path: nil)
+ stats = Array.wrap(object.diff_stats&.to_a)
+
+ if path.present?
+ stats.select { |s| s.path == path }
+ else
+ stats
+ end
+ end
+
+ def diff_stats_summary
+ nil_stats = { additions: 0, deletions: 0 }
+ return nil_stats unless object.diff_stats.present?
+
+ object.diff_stats.each_with_object(nil_stats) do |status, hash|
+ hash.merge!(additions: status.additions, deletions: status.deletions) { |_, x, y| x + y }
+ end
+ end
end
end