diff options
author | Douwe Maan <douwe@selenight.nl> | 2016-05-04 17:27:47 +0200 |
---|---|---|
committer | Douwe Maan <douwe@selenight.nl> | 2016-05-04 17:27:47 +0200 |
commit | 6a8359f3d3be01af6f5b124b61af7ee1c77c17d0 (patch) | |
tree | 9e972713fc223d7a466ea2b1601a093d719f0817 /lib | |
parent | 72e4bd5fc40c3b61792bf5f8897ab881775c7146 (diff) | |
parent | c4b9bd041321df25764ad1de90f89b1f0dda9f33 (diff) | |
download | gitlab-ce-6a8359f3d3be01af6f5b124b61af7ee1c77c17d0.tar.gz |
Merge branch 'pacoguzman/gitlab-ce-15001-since-and-until-operators-api-commits'
# Conflicts:
# Gemfile.lock
Diffstat (limited to 'lib')
-rw-r--r-- | lib/api/commits.rb | 8 | ||||
-rw-r--r-- | lib/api/helpers.rb | 16 | ||||
-rw-r--r-- | lib/gitlab/push_data_builder.rb | 2 |
3 files changed, 24 insertions, 2 deletions
diff --git a/lib/api/commits.rb b/lib/api/commits.rb index 4544a41b1e3..93a3a5ce089 100644 --- a/lib/api/commits.rb +++ b/lib/api/commits.rb @@ -12,14 +12,20 @@ module API # Parameters: # id (required) - The ID of a project # ref_name (optional) - The name of a repository branch or tag, if not given the default branch is used + # since (optional) - Only commits after or in this date will be returned + # until (optional) - Only commits before or in this date will be returned # Example Request: # GET /projects/:id/repository/commits get ":id/repository/commits" do + datetime_attributes! :since, :until + page = (params[:page] || 0).to_i per_page = (params[:per_page] || 20).to_i ref = params[:ref_name] || user_project.try(:default_branch) || 'master' + after = params[:since] + before = params[:until] - commits = user_project.repository.commits(ref, nil, per_page, page * per_page) + commits = user_project.repository.commits(ref, limit: per_page, offset: page * per_page, after: after, before: before) present commits, with: Entities::RepoCommit end diff --git a/lib/api/helpers.rb b/lib/api/helpers.rb index 5bbf721321d..40c967453fb 100644 --- a/lib/api/helpers.rb +++ b/lib/api/helpers.rb @@ -183,6 +183,22 @@ module API Gitlab::Access.options_with_owner.values.include? level.to_i end + # Checks the occurrences of datetime attributes, each attribute if present in the params hash must be in ISO 8601 + # format (YYYY-MM-DDTHH:MM:SSZ) or a Bad Request error is invoked. + # + # Parameters: + # keys (required) - An array consisting of elements that must be parseable as dates from the params hash + def datetime_attributes!(*keys) + keys.each do |key| + begin + params[key] = Time.xmlschema(params[key]) if params[key].present? + rescue ArgumentError + message = "\"" + key.to_s + "\" must be a timestamp in ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ" + render_api_error!(message, 400) + end + end + end + def issuable_order_by if params["order_by"] == 'updated_at' 'updated_at' diff --git a/lib/gitlab/push_data_builder.rb b/lib/gitlab/push_data_builder.rb index 67622f321a6..c8f12577112 100644 --- a/lib/gitlab/push_data_builder.rb +++ b/lib/gitlab/push_data_builder.rb @@ -66,7 +66,7 @@ module Gitlab # This method provide a sample data generated with # existing project and commits to test webhooks def build_sample(project, user) - commits = project.repository.commits(project.default_branch, nil, 3) + commits = project.repository.commits(project.default_branch, limit: 3) ref = "#{Gitlab::Git::BRANCH_REF_PREFIX}#{project.default_branch}" build(project, user, commits.last.id, commits.first.id, ref, commits) end |