2

Some requests to GitLab API, like listing Merge Requests (https://docs.gitlab.com/ee/api/merge_requests.html#list-merge-requests) allow for URL query parameters of datetime type (created_after and created_before params for this particular example).

I can't seem to find a format for the datetime param that would work. Timestamps (both with and without milliseconds) doesn't work, nor do the ISO format like 2017-06-29T11:00:00.000Z.

Maybe this query parameter doesn't work at all?

mzywiol
  • 386
  • 1
  • 3
  • 11
  • Did you try `2017-06-29T11%3A00%3A00.000Z` (iso url encoded) ? – Bertrand Martel Jun 29 '17 at 11:58
  • @BertrandMartel tried that too, didn't work. – mzywiol Jun 29 '17 at 12:17
  • Ah, dammit, I found the issue: we're using Community Edition, not Enterprise. The `created_before` and `created_after` are not available in CE. What is the Stack policy in this case? Should I answer the question? Remove it completely? Or is this comment sufficient? – mzywiol Jul 04 '17 at 08:08
  • Create an answer yourself and mark it as successful. – secustor Jul 05 '17 at 20:24
  • OK, it's not CE vs EE problem: on official site the API for both editions is identical: https://docs.gitlab.com/ce/api/merge_requests.html VS https://docs.gitlab.com/ee/api/merge_requests.html. Funny thing though is that the latest stable code on their GitHub is missing these parameters: https://github.com/gitlabhq/gitlabhq/blob/9-3-stable/app/finders/issuable_finder.rb I'm trying to get some answers from them on Twitter. – mzywiol Jul 06 '17 at 09:57
  • Yup, it seems this change was not released as of version 9.3.5: https://github.com/gitlabhq/gitlabhq/blob/master/changelogs/unreleased/12151-add-since-and-until-params-to-issuables.yml (note it's placed in "unreleased" directory). – mzywiol Jul 06 '17 at 09:59

4 Answers4

1

Found the reason: the created_before and created_after parameters, though listed and described in the official API documentation, are not yet included in any released version.

As of GitLab version 9.3.5 it's still listed under unreleased:

https://github.com/gitlabhq/gitlabhq/blob/master/changelogs/unreleased/12151-add-since-and-until-params-to-issuables.yml

https://github.com/gitlabhq/gitlabhq/commit/9fe6c2b2c2dd92831c93297021b41d6721e4b201

mzywiol
  • 386
  • 1
  • 3
  • 11
0

Try ISO8601 timestamps, therefore remove nanoseconds and include the timezone:

2017-06-29T11:00:00+00:00

Use for reference the ruby DateTime class as this one is used in Gitlab.

https://ruby-doc.org/stdlib-2.3.1/libdoc/date/rdoc/DateTime.html

The merge request API class of Gitlab:
https://gitlab.com/gitlab-org/gitlab-ce/blob/master/lib/api/merge_requests.rb

secustor
  • 3,001
  • 2
  • 14
  • 20
  • That doesn't work either... I read through both the GitLab code and DateTime Ruby documentation. That didn't help. The actual comparison is done here: https://gitlab.com/gitlab-org/gitlab-ce/blob/master/app/finders/issuable_finder.rb#L417 (like 417) but that doesn't help me much. – mzywiol Jun 30 '17 at 20:47
  • K, interresting but is nothing showing up in the logs? Do you getting anything back, e.g. if you let the parameters empty? – secustor Jun 30 '17 at 21:08
  • I don't have access to logs - I'm querying my company's GitLab. I do get a 200 OK responses filled with data - no 40X even when I fill the created_before param with gibberish. All the other query params for this API call work fine and are applied, this one seems just to be ignored. – mzywiol Jun 30 '17 at 21:11
  • 1
    Are you using by any change [APIv3](https://gitlab.com/gitlab-org/gitlab-ce/blob/8-16-stable/doc/api/merge_requests.md) instead of [APIv4](https://docs.gitlab.com/ee/api/merge_requests.html#list-merge-requests) as the first has not this fields? – secustor Jun 30 '17 at 21:25
  • Nope, it's APIv4. At least it's v4 that's specified in the url I'm using. – mzywiol Jul 03 '17 at 08:53
0

This is the time format that worked for me (Standard ISO-8601):
three_weeks_ago = (datetime.datetime.now(timezone.utc)- timedelta(days=21)).isoformat() . mrs = request(f'/merge_requests?state=merged&created_after={three_weeks_ago}&per_page=100')

Roy Horev
  • 106
  • 7
0

In Gitlab 12.6.4-ee (Enterprise Edition), ISO8601 datetime formats like "2020-02-12T00:08:15Z" and "2020-02-12T00:07:15+01:00" work, when URL-encoded. So "2020-02-12T00:08:15Z" -> "2020-02-12T00%3A08%3A15Z", and "2020-02-12T00:07:15+01:00" -> "2020-02-12T00%3A07%3A15%2B01%3A00". So a full (fake) URL example would be: https://gitlab.mycompany.com/api/v4/projects/myproject/merge_requests?updated_after=2020-02-12T00%3A07%3A15%2B01%3A00

jor
  • 121
  • 1
  • 4