summaryrefslogtreecommitdiff
path: root/lib/api/commits.rb
diff options
context:
space:
mode:
authorToon Claes <toon@gitlab.com>2019-02-28 19:57:34 +0100
committerToon Claes <toon@gitlab.com>2019-02-28 19:57:34 +0100
commit62d7990b9bb30cf33ed87017c5c633d1cccc75c2 (patch)
treec3e1b69c58a412ba1c6f50a0337a23d9f9d6e1a4 /lib/api/commits.rb
parentf6453eca992a9c142268e78ac782cef98110d183 (diff)
downloadgitlab-ce-tc-standard-gem.tar.gz
Ran standardrb --fix on the whole codebasetc-standard-gem
Inspired by https://twitter.com/searls/status/1101137953743613952 I decided to try https://github.com/testdouble/standard on our codebase. It's opinionated, but at least it's a _standard_.
Diffstat (limited to 'lib/api/commits.rb')
-rw-r--r--lib/api/commits.rb186
1 files changed, 93 insertions, 93 deletions
diff --git a/lib/api/commits.rb b/lib/api/commits.rb
index 8defc59224d..a38d476b122 100644
--- a/lib/api/commits.rb
+++ b/lib/api/commits.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-require 'mime/types'
+require "mime/types"
module API
class Commits < Grape::API
@@ -21,37 +21,37 @@ module API
end
params do
- requires :id, type: String, desc: 'The ID of a project'
+ requires :id, type: String, desc: "The ID of a project"
end
resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do
- desc 'Get a project repository commits' do
+ desc "Get a project repository commits" do
success Entities::Commit
end
params do
- optional :ref_name, type: String, desc: 'The name of a repository branch or tag, if not given the default branch is used'
- optional :since, type: DateTime, desc: 'Only commits after or on this date will be returned'
- optional :until, type: DateTime, desc: 'Only commits before or on this date will be returned'
- optional :path, type: String, desc: 'The file path'
- optional :all, type: Boolean, desc: 'Every commit will be returned'
- optional :with_stats, type: Boolean, desc: 'Stats about each commit will be added to the response'
+ optional :ref_name, type: String, desc: "The name of a repository branch or tag, if not given the default branch is used"
+ optional :since, type: DateTime, desc: "Only commits after or on this date will be returned"
+ optional :until, type: DateTime, desc: "Only commits before or on this date will be returned"
+ optional :path, type: String, desc: "The file path"
+ optional :all, type: Boolean, desc: "Every commit will be returned"
+ optional :with_stats, type: Boolean, desc: "Stats about each commit will be added to the response"
use :pagination
end
- get ':id/repository/commits' do
+ get ":id/repository/commits" do
path = params[:path]
before = params[:until]
after = params[:since]
- ref = params[:ref_name] || user_project.try(:default_branch) || 'master' unless params[:all]
+ ref = params[:ref_name] || user_project.try(:default_branch) || "master" unless params[:all]
offset = (params[:page] - 1) * params[:per_page]
all = params[:all]
with_stats = params[:with_stats]
commits = user_project.repository.commits(ref,
- path: path,
- limit: params[:per_page],
- offset: offset,
- before: before,
- after: after,
- all: all)
+ path: path,
+ limit: params[:per_page],
+ offset: offset,
+ before: before,
+ after: after,
+ all: all)
commit_count =
if all || path || before || after
@@ -68,39 +68,39 @@ module API
present paginate(paginated_commits), with: serializer
end
- desc 'Commit multiple file changes as one commit' do
+ desc "Commit multiple file changes as one commit" do
success Entities::CommitDetail
- detail 'This feature was introduced in GitLab 8.13'
+ detail "This feature was introduced in GitLab 8.13"
end
params do
- requires :branch, type: String, desc: 'Name of the branch to commit into. To create a new branch, also provide `start_branch`.', allow_blank: false
- requires :commit_message, type: String, desc: 'Commit message'
- requires :actions, type: Array, desc: 'Actions to perform in commit' do
- requires :action, type: String, desc: 'The action to perform, `create`, `delete`, `move`, `update`, `chmod`', values: %w[create update move delete chmod].freeze
- requires :file_path, type: String, desc: 'Full path to the file. Ex. `lib/class.rb`'
- given action: ->(action) { action == 'move' } do
- requires :previous_path, type: String, desc: 'Original full path to the file being moved. Ex. `lib/class1.rb`'
+ requires :branch, type: String, desc: "Name of the branch to commit into. To create a new branch, also provide `start_branch`.", allow_blank: false
+ requires :commit_message, type: String, desc: "Commit message"
+ requires :actions, type: Array, desc: "Actions to perform in commit" do
+ requires :action, type: String, desc: "The action to perform, `create`, `delete`, `move`, `update`, `chmod`", values: %w[create update move delete chmod].freeze
+ requires :file_path, type: String, desc: "Full path to the file. Ex. `lib/class.rb`"
+ given action: ->(action) { action == "move" } do
+ requires :previous_path, type: String, desc: "Original full path to the file being moved. Ex. `lib/class1.rb`"
end
given action: ->(action) { %w[create move].include? action } do
- optional :content, type: String, desc: 'File content'
+ optional :content, type: String, desc: "File content"
end
- given action: ->(action) { action == 'update' } do
- requires :content, type: String, desc: 'File content'
+ given action: ->(action) { action == "update" } do
+ requires :content, type: String, desc: "File content"
end
- optional :encoding, type: String, desc: '`text` or `base64`', default: 'text', values: %w[text base64]
+ optional :encoding, type: String, desc: "`text` or `base64`", default: "text", values: %w[text base64]
given action: ->(action) { %w[update move delete].include? action } do
- optional :last_commit_id, type: String, desc: 'Last known file commit id'
+ optional :last_commit_id, type: String, desc: "Last known file commit id"
end
- given action: ->(action) { action == 'chmod' } do
- requires :execute_filemode, type: Boolean, desc: 'When `true/false` enables/disables the execute flag on the file.'
+ given action: ->(action) { action == "chmod" } do
+ requires :execute_filemode, type: Boolean, desc: "When `true/false` enables/disables the execute flag on the file."
end
end
- optional :start_branch, type: String, desc: 'Name of the branch to start the new commit from'
- optional :author_email, type: String, desc: 'Author email for commit'
- optional :author_name, type: String, desc: 'Author name for commit'
- optional :stats, type: Boolean, default: true, desc: 'Include commit stats'
+ optional :start_branch, type: String, desc: "Name of the branch to start the new commit from"
+ optional :author_email, type: String, desc: "Author email for commit"
+ optional :author_name, type: String, desc: "Author name for commit"
+ optional :stats, type: Boolean, default: true, desc: "Include commit stats"
end
- post ':id/repository/commits' do
+ post ":id/repository/commits" do
authorize_push_to_branch!(params[:branch])
attrs = declared_params
@@ -120,33 +120,33 @@ module API
end
end
- desc 'Get a specific commit of a project' do
+ desc "Get a specific commit of a project" do
success Entities::CommitDetail
- failure [[404, 'Commit Not Found']]
+ failure [[404, "Commit Not Found"]]
end
params do
- requires :sha, type: String, desc: 'A commit sha, or the name of a branch or tag'
- optional :stats, type: Boolean, default: true, desc: 'Include commit stats'
+ requires :sha, type: String, desc: "A commit sha, or the name of a branch or tag"
+ optional :stats, type: Boolean, default: true, desc: "Include commit stats"
end
- get ':id/repository/commits/:sha', requirements: API::COMMIT_ENDPOINT_REQUIREMENTS do
+ get ":id/repository/commits/:sha", requirements: API::COMMIT_ENDPOINT_REQUIREMENTS do
commit = user_project.commit(params[:sha])
- not_found! 'Commit' unless commit
+ not_found! "Commit" unless commit
present commit, with: Entities::CommitDetail, stats: params[:stats]
end
- desc 'Get the diff for a specific commit of a project' do
- failure [[404, 'Commit Not Found']]
+ desc "Get the diff for a specific commit of a project" do
+ failure [[404, "Commit Not Found"]]
end
params do
- requires :sha, type: String, desc: 'A commit sha, or the name of a branch or tag'
+ requires :sha, type: String, desc: "A commit sha, or the name of a branch or tag"
use :pagination
end
- get ':id/repository/commits/:sha/diff', requirements: API::COMMIT_ENDPOINT_REQUIREMENTS do
+ get ":id/repository/commits/:sha/diff", requirements: API::COMMIT_ENDPOINT_REQUIREMENTS do
commit = user_project.commit(params[:sha])
- not_found! 'Commit' unless commit
+ not_found! "Commit" unless commit
raw_diffs = ::Kaminari.paginate_array(commit.raw_diffs.to_a)
@@ -155,43 +155,43 @@ module API
desc "Get a commit's comments" do
success Entities::CommitNote
- failure [[404, 'Commit Not Found']]
+ failure [[404, "Commit Not Found"]]
end
params do
use :pagination
- requires :sha, type: String, desc: 'A commit sha, or the name of a branch or tag'
+ requires :sha, type: String, desc: "A commit sha, or the name of a branch or tag"
end
# rubocop: disable CodeReuse/ActiveRecord
- get ':id/repository/commits/:sha/comments', requirements: API::COMMIT_ENDPOINT_REQUIREMENTS do
+ get ":id/repository/commits/:sha/comments", requirements: API::COMMIT_ENDPOINT_REQUIREMENTS do
commit = user_project.commit(params[:sha])
- not_found! 'Commit' unless commit
+ not_found! "Commit" unless commit
notes = commit.notes.order(:created_at)
present paginate(notes), with: Entities::CommitNote
end
# rubocop: enable CodeReuse/ActiveRecord
- desc 'Cherry pick commit into a branch' do
- detail 'This feature was introduced in GitLab 8.15'
+ desc "Cherry pick commit into a branch" do
+ detail "This feature was introduced in GitLab 8.15"
success Entities::Commit
end
params do
- requires :sha, type: String, desc: 'A commit sha, or the name of a branch or tag to be cherry picked'
- requires :branch, type: String, desc: 'The name of the branch', allow_blank: false
+ requires :sha, type: String, desc: "A commit sha, or the name of a branch or tag to be cherry picked"
+ requires :branch, type: String, desc: "The name of the branch", allow_blank: false
end
- post ':id/repository/commits/:sha/cherry_pick', requirements: API::COMMIT_ENDPOINT_REQUIREMENTS do
+ post ":id/repository/commits/:sha/cherry_pick", requirements: API::COMMIT_ENDPOINT_REQUIREMENTS do
authorize_push_to_branch!(params[:branch])
commit = user_project.commit(params[:sha])
- not_found!('Commit') unless commit
+ not_found!("Commit") unless commit
find_branch!(params[:branch])
commit_params = {
commit: commit,
start_branch: params[:branch],
- branch_name: params[:branch]
+ branch_name: params[:branch],
}
result = ::Commits::CherryPickService
@@ -206,26 +206,26 @@ module API
end
end
- desc 'Revert a commit in a branch' do
- detail 'This feature was introduced in GitLab 11.5'
+ desc "Revert a commit in a branch" do
+ detail "This feature was introduced in GitLab 11.5"
success Entities::Commit
end
params do
- requires :sha, type: String, desc: 'Commit SHA to revert'
- requires :branch, type: String, desc: 'Target branch name', allow_blank: false
+ requires :sha, type: String, desc: "Commit SHA to revert"
+ requires :branch, type: String, desc: "Target branch name", allow_blank: false
end
- post ':id/repository/commits/:sha/revert', requirements: API::COMMIT_ENDPOINT_REQUIREMENTS do
+ post ":id/repository/commits/:sha/revert", requirements: API::COMMIT_ENDPOINT_REQUIREMENTS do
authorize_push_to_branch!(params[:branch])
commit = user_project.commit(params[:sha])
- not_found!('Commit') unless commit
+ not_found!("Commit") unless commit
find_branch!(params[:branch])
commit_params = {
commit: commit,
start_branch: params[:branch],
- branch_name: params[:branch]
+ branch_name: params[:branch],
}
result = ::Commits::RevertService
@@ -240,47 +240,47 @@ module API
end
end
- desc 'Get all references a commit is pushed to' do
- detail 'This feature was introduced in GitLab 10.6'
+ desc "Get all references a commit is pushed to" do
+ detail "This feature was introduced in GitLab 10.6"
success Entities::BasicRef
end
params do
- requires :sha, type: String, desc: 'A commit sha'
- optional :type, type: String, values: %w[branch tag all], default: 'all', desc: 'Scope'
+ requires :sha, type: String, desc: "A commit sha"
+ optional :type, type: String, values: %w[branch tag all], default: "all", desc: "Scope"
use :pagination
end
- get ':id/repository/commits/:sha/refs', requirements: API::COMMIT_ENDPOINT_REQUIREMENTS do
+ get ":id/repository/commits/:sha/refs", requirements: API::COMMIT_ENDPOINT_REQUIREMENTS do
commit = user_project.commit(params[:sha])
- not_found!('Commit') unless commit
+ not_found!("Commit") unless commit
refs = []
- refs.concat(user_project.repository.branch_names_contains(commit.id).map {|name| { type: 'branch', name: name }}) unless params[:type] == 'tag'
- refs.concat(user_project.repository.tag_names_contains(commit.id).map {|name| { type: 'tag', name: name }}) unless params[:type] == 'branch'
+ refs.concat(user_project.repository.branch_names_contains(commit.id).map {|name| {type: "branch", name: name}}) unless params[:type] == "tag"
+ refs.concat(user_project.repository.tag_names_contains(commit.id).map {|name| {type: "tag", name: name}}) unless params[:type] == "branch"
refs = Kaminari.paginate_array(refs)
present paginate(refs), with: Entities::BasicRef
end
- desc 'Post comment to commit' do
+ desc "Post comment to commit" do
success Entities::CommitNote
end
params do
- requires :sha, type: String, desc: 'A commit sha, or the name of a branch or tag on which to post a comment'
- requires :note, type: String, desc: 'The text of the comment'
- optional :path, type: String, desc: 'The file path'
+ requires :sha, type: String, desc: "A commit sha, or the name of a branch or tag on which to post a comment"
+ requires :note, type: String, desc: "The text of the comment"
+ optional :path, type: String, desc: "The file path"
given :path do
- requires :line, type: Integer, desc: 'The line number'
- requires :line_type, type: String, values: %w[new old], default: 'new', desc: 'The type of the line'
+ requires :line, type: Integer, desc: "The line number"
+ requires :line_type, type: String, values: %w[new old], default: "new", desc: "The type of the line"
end
end
- post ':id/repository/commits/:sha/comments', requirements: API::COMMIT_ENDPOINT_REQUIREMENTS do
+ post ":id/repository/commits/:sha/comments", requirements: API::COMMIT_ENDPOINT_REQUIREMENTS do
commit = user_project.commit(params[:sha])
- not_found! 'Commit' unless commit
+ not_found! "Commit" unless commit
opts = {
note: params[:note],
- noteable_type: 'Commit',
- commit_id: commit.id
+ noteable_type: "Commit",
+ commit_id: commit.id,
}
if params[:path]
@@ -310,16 +310,16 @@ module API
end
end
- desc 'Get Merge Requests associated with a commit' do
+ desc "Get Merge Requests associated with a commit" do
success Entities::MergeRequestBasic
end
params do
- requires :sha, type: String, desc: 'A commit sha, or the name of a branch or tag on which to find Merge Requests'
+ requires :sha, type: String, desc: "A commit sha, or the name of a branch or tag on which to find Merge Requests"
use :pagination
end
- get ':id/repository/commits/:sha/merge_requests', requirements: API::COMMIT_ENDPOINT_REQUIREMENTS do
+ get ":id/repository/commits/:sha/merge_requests", requirements: API::COMMIT_ENDPOINT_REQUIREMENTS do
commit = user_project.commit(params[:sha])
- not_found! 'Commit' unless commit
+ not_found! "Commit" unless commit
present paginate(commit.merge_requests), with: Entities::MergeRequestBasic
end
@@ -328,14 +328,14 @@ module API
success Entities::CommitSignature
end
params do
- requires :sha, type: String, desc: 'A commit sha, or the name of a branch or tag'
+ requires :sha, type: String, desc: "A commit sha, or the name of a branch or tag"
end
- get ':id/repository/commits/:sha/signature', requirements: API::COMMIT_ENDPOINT_REQUIREMENTS do
+ get ":id/repository/commits/:sha/signature", requirements: API::COMMIT_ENDPOINT_REQUIREMENTS do
commit = user_project.commit(params[:sha])
- not_found! 'Commit' unless commit
+ not_found! "Commit" unless commit
signature = commit.signature
- not_found! 'GPG Signature' unless signature
+ not_found! "GPG Signature" unless signature
present signature, with: Entities::CommitSignature
end