gitlab 4.2.0 → 4.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. checksums.yaml +5 -5
  2. data/.rubocop.yml +33 -0
  3. data/.travis.yml +8 -3
  4. data/README.md +7 -7
  5. data/Rakefile +11 -3
  6. data/gitlab.gemspec +11 -11
  7. data/lib/gitlab.rb +2 -2
  8. data/lib/gitlab/api.rb +2 -1
  9. data/lib/gitlab/cli.rb +2 -6
  10. data/lib/gitlab/cli_helpers.rb +18 -20
  11. data/lib/gitlab/client.rb +8 -5
  12. data/lib/gitlab/client/branches.rb +4 -4
  13. data/lib/gitlab/client/build_variables.rb +64 -2
  14. data/lib/gitlab/client/deployments.rb +32 -0
  15. data/lib/gitlab/client/groups.rb +49 -0
  16. data/lib/gitlab/client/issues.rb +71 -0
  17. data/lib/gitlab/client/merge_requests.rb +1 -0
  18. data/lib/gitlab/client/pipeline_schedules.rb +133 -0
  19. data/lib/gitlab/client/pipeline_triggers.rb +2 -2
  20. data/lib/gitlab/client/projects.rb +1 -1
  21. data/lib/gitlab/client/repository_files.rb +2 -2
  22. data/lib/gitlab/client/users.rb +5 -5
  23. data/lib/gitlab/configuration.rb +2 -2
  24. data/lib/gitlab/error.rb +10 -2
  25. data/lib/gitlab/file_response.rb +1 -1
  26. data/lib/gitlab/help.rb +5 -6
  27. data/lib/gitlab/page_links.rb +2 -2
  28. data/lib/gitlab/request.rb +34 -50
  29. data/lib/gitlab/shell.rb +5 -8
  30. data/lib/gitlab/version.rb +1 -1
  31. data/spec/fixtures/deployment.json +57 -0
  32. data/spec/fixtures/deployments.json +116 -0
  33. data/spec/fixtures/group_edit.json +14 -0
  34. data/spec/fixtures/group_subgroups.json +16 -0
  35. data/spec/fixtures/pipeline_schedule.json +32 -0
  36. data/spec/fixtures/pipeline_schedule_create.json +21 -0
  37. data/spec/fixtures/pipeline_schedule_update.json +26 -0
  38. data/spec/fixtures/pipeline_schedule_variable.json +5 -0
  39. data/spec/fixtures/pipeline_schedule_variable_update.json +5 -0
  40. data/spec/fixtures/pipeline_schedules.json +22 -0
  41. data/spec/gitlab/api_spec.rb +11 -0
  42. data/spec/gitlab/cli_helpers_spec.rb +14 -15
  43. data/spec/gitlab/cli_spec.rb +11 -11
  44. data/spec/gitlab/client/award_emojis_spec.rb +55 -55
  45. data/spec/gitlab/client/boards_spec.rb +12 -12
  46. data/spec/gitlab/client/branches_spec.rb +22 -22
  47. data/spec/gitlab/client/build_variables_spec.rb +93 -10
  48. data/spec/gitlab/client/builds_spec.rb +36 -36
  49. data/spec/gitlab/client/commits_spec.rb +21 -21
  50. data/spec/gitlab/client/deployments_spec.rb +38 -0
  51. data/spec/gitlab/client/environments_spec.rb +18 -18
  52. data/spec/gitlab/client/groups_spec.rb +73 -22
  53. data/spec/gitlab/client/issues_spec.rb +121 -22
  54. data/spec/gitlab/client/jobs_spec.rb +13 -13
  55. data/spec/gitlab/client/keys_spec.rb +2 -2
  56. data/spec/gitlab/client/labels_spec.rb +12 -12
  57. data/spec/gitlab/client/merge_requests_spec.rb +23 -23
  58. data/spec/gitlab/client/milestones_spec.rb +12 -12
  59. data/spec/gitlab/client/namespaces_spec.rb +3 -3
  60. data/spec/gitlab/client/notes_spec.rb +40 -40
  61. data/spec/gitlab/client/pipeline_schedules_spec.rb +158 -0
  62. data/spec/gitlab/client/pipeline_triggers_spec.rb +17 -17
  63. data/spec/gitlab/client/pipelines_spec.rb +22 -22
  64. data/spec/gitlab/client/projects_spec.rb +75 -75
  65. data/spec/gitlab/client/repositories_spec.rb +16 -16
  66. data/spec/gitlab/client/repository_files_spec.rb +10 -10
  67. data/spec/gitlab/client/runners_spec.rb +20 -22
  68. data/spec/gitlab/client/services_spec.rb +6 -6
  69. data/spec/gitlab/client/snippets_spec.rb +12 -12
  70. data/spec/gitlab/client/system_hooks_spec.rb +12 -12
  71. data/spec/gitlab/client/tags_spec.rb +19 -20
  72. data/spec/gitlab/client/todos_spec.rb +12 -12
  73. data/spec/gitlab/client/users_spec.rb +49 -49
  74. data/spec/gitlab/error_spec.rb +50 -23
  75. data/spec/gitlab/file_response_spec.rb +6 -6
  76. data/spec/gitlab/help_spec.rb +5 -5
  77. data/spec/gitlab/objectified_hash_spec.rb +8 -8
  78. data/spec/gitlab/page_links_spec.rb +1 -1
  79. data/spec/gitlab/paginated_response_spec.rb +4 -4
  80. data/spec/gitlab/request_spec.rb +19 -19
  81. data/spec/gitlab/shell_spec.rb +12 -12
  82. data/spec/gitlab_spec.rb +13 -14
  83. data/spec/spec_helper.rb +10 -45
  84. metadata +46 -3
@@ -6,7 +6,7 @@ module Gitlab
6
6
  HEADER_LINK = 'Link'.freeze
7
7
  DELIM_LINKS = ','.freeze
8
8
  LINK_REGEX = /<([^>]+)>; rel=\"([^\"]+)\"/
9
- METAS = %w(last next first prev)
9
+ METAS = %w(last next first prev).freeze
10
10
 
11
11
  attr_accessor(*METAS)
12
12
 
@@ -25,7 +25,7 @@ module Gitlab
25
25
  LINK_REGEX.match(link.strip) do |match|
26
26
  url, meta = match[1], match[2]
27
27
  next if !url || !meta || METAS.index(meta).nil?
28
- self.send("#{meta}=", url)
28
+ send("#{meta}=", url)
29
29
  end
30
30
  end
31
31
  end
@@ -26,58 +26,42 @@ module Gitlab
26
26
  elsif body.nil?
27
27
  false
28
28
  else
29
- raise Error::Parsing.new "Couldn't parse a response body"
29
+ raise Error::Parsing, "Couldn't parse a response body"
30
30
  end
31
31
  end
32
32
 
33
33
  # Decodes a JSON response into Ruby object.
34
34
  def self.decode(response)
35
- JSON.load response
35
+ return response ? JSON.load(response) : {}
36
36
  rescue JSON::ParserError
37
- raise Error::Parsing.new "The response is not a valid JSON"
37
+ raise Error::Parsing, 'The response is not a valid JSON'
38
38
  end
39
39
 
40
- def get(path, options={})
41
- set_httparty_config(options)
42
- set_authorization_header(options)
43
- validate self.class.get(@endpoint + path, options)
44
- end
45
-
46
- def post(path, options={})
47
- set_httparty_config(options)
48
- set_authorization_header(options)
49
- validate self.class.post(@endpoint + path, options)
50
- end
51
-
52
- def put(path, options={})
53
- set_httparty_config(options)
54
- set_authorization_header(options)
55
- validate self.class.put(@endpoint + path, options)
56
- end
57
-
58
- def delete(path, options={})
59
- set_httparty_config(options)
60
- set_authorization_header(options)
61
- validate self.class.delete(@endpoint + path, options)
40
+ %w(get post put delete).each do |method|
41
+ define_method method do |path, options={}|
42
+ httparty_config(options)
43
+ authorization_header(options)
44
+ validate self.class.send(method, @endpoint + path, options)
45
+ end
62
46
  end
63
47
 
64
48
  # Checks the response code for common errors.
65
49
  # Returns parsed response for successful requests.
66
50
  def validate(response)
67
51
  error_klass = case response.code
68
- when 400 then Error::BadRequest
69
- when 401 then Error::Unauthorized
70
- when 403 then Error::Forbidden
71
- when 404 then Error::NotFound
72
- when 405 then Error::MethodNotAllowed
73
- when 409 then Error::Conflict
74
- when 422 then Error::Unprocessable
75
- when 500 then Error::InternalServerError
76
- when 502 then Error::BadGateway
77
- when 503 then Error::ServiceUnavailable
78
- end
79
-
80
- fail error_klass.new(response) if error_klass
52
+ when 400 then Error::BadRequest
53
+ when 401 then Error::Unauthorized
54
+ when 403 then Error::Forbidden
55
+ when 404 then Error::NotFound
56
+ when 405 then Error::MethodNotAllowed
57
+ when 409 then Error::Conflict
58
+ when 422 then Error::Unprocessable
59
+ when 500 then Error::InternalServerError
60
+ when 502 then Error::BadGateway
61
+ when 503 then Error::ServiceUnavailable
62
+ end
63
+
64
+ raise error_klass, response if error_klass
81
65
 
82
66
  parsed = response.parsed_response
83
67
  parsed.client = self if parsed.respond_to?(:client=)
@@ -87,9 +71,9 @@ module Gitlab
87
71
 
88
72
  # Sets a base_uri and default_params for requests.
89
73
  # @raise [Error::MissingCredentials] if endpoint not set.
90
- def set_request_defaults(sudo=nil)
74
+ def request_defaults(sudo=nil)
91
75
  self.class.default_params sudo: sudo
92
- raise Error::MissingCredentials.new("Please set an endpoint to API") unless @endpoint
76
+ raise Error::MissingCredentials, 'Please set an endpoint to API' unless @endpoint
93
77
  self.class.default_params.delete(:sudo) if sudo.nil?
94
78
  end
95
79
 
@@ -100,20 +84,20 @@ module Gitlab
100
84
  # @param [Hash] options A customizable set of options.
101
85
  # @option options [Boolean] :unauthenticated true if the API call does not require user authentication.
102
86
  # @raise [Error::MissingCredentials] if private_token and auth_token are not set.
103
- def set_authorization_header(options)
104
- unless options[:unauthenticated]
105
- raise Error::MissingCredentials.new("Please provide a private_token or auth_token for user") unless @private_token
106
- if @private_token.length <= 20
107
- options[:headers] = { 'PRIVATE-TOKEN' => @private_token }
108
- else
109
- options[:headers] = { 'Authorization' => "Bearer #{@private_token}" }
110
- end
111
- end
87
+ def authorization_header(options)
88
+ return if options[:unauthenticated]
89
+ raise Error::MissingCredentials, 'Please provide a private_token or auth_token for user' unless @private_token
90
+
91
+ options[:headers] = if @private_token.size < 21
92
+ { 'PRIVATE-TOKEN' => @private_token }
93
+ else
94
+ { 'Authorization' => "Bearer #{@private_token}" }
95
+ end
112
96
  end
113
97
 
114
98
  # Set HTTParty configuration
115
99
  # @see https://github.com/jnunemaker/httparty
116
- def set_httparty_config(options)
100
+ def httparty_config(options)
117
101
  options.merge!(httparty) if httparty
118
102
  end
119
103
  end
@@ -63,13 +63,10 @@ class Gitlab::Shell
63
63
 
64
64
  # Execute a given command with arguements
65
65
  def execute(cmd=command, args=arguments)
66
- if actions.include?(cmd.to_sym)
67
- confirm_command(cmd)
68
- gitlab_helper(cmd, args)
69
- else
70
- fail "Unknown command: #{cmd}. " \
71
- "See the 'help' for a list of valid commands."
72
- end
66
+ raise "Unknown command: #{cmd}. See the 'help' for a list of valid commands." unless actions.include?(cmd.to_sym)
67
+
68
+ confirm_command(cmd)
69
+ gitlab_helper(cmd, args)
73
70
  end
74
71
 
75
72
  def quit_shell
@@ -80,5 +77,5 @@ class Gitlab::Shell
80
77
  def history
81
78
  @history ||= History.new
82
79
  end
83
- end # class << self
80
+ end
84
81
  end
@@ -1,3 +1,3 @@
1
1
  module Gitlab
2
- VERSION = "4.2.0"
2
+ VERSION = '4.3.0'.freeze
3
3
  end
@@ -0,0 +1,57 @@
1
+ {
2
+ "id": 42,
3
+ "iid": 2,
4
+ "ref": "master",
5
+ "sha": "a91957a858320c0e17f3a0eca7cfacbff50ea29a",
6
+ "created_at": "2016-08-11T11:32:35.444Z",
7
+ "user": {
8
+ "name": "Administrator",
9
+ "username": "root",
10
+ "id": 1,
11
+ "state": "active",
12
+ "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon",
13
+ "web_url": "http://localhost:3000/root"
14
+ },
15
+ "environment": {
16
+ "id": 9,
17
+ "name": "production",
18
+ "external_url": "https://about.gitlab.com"
19
+ },
20
+ "deployable": {
21
+ "id": 664,
22
+ "status": "success",
23
+ "stage": "deploy",
24
+ "name": "deploy",
25
+ "ref": "master",
26
+ "tag": false,
27
+ "coverage": null,
28
+ "created_at": "2016-08-11T11:32:24.456Z",
29
+ "started_at": null,
30
+ "finished_at": "2016-08-11T11:32:35.145Z",
31
+ "user": {
32
+ "name": "Administrator",
33
+ "username": "root",
34
+ "id": 1,
35
+ "state": "active",
36
+ "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon",
37
+ "web_url": "http://localhost:3000/root",
38
+ "created_at": "2016-08-11T07:09:20.351Z",
39
+ "bio": null,
40
+ "location": null,
41
+ "skype": "",
42
+ "linkedin": "",
43
+ "twitter": "",
44
+ "website_url": ""
45
+ },
46
+ "commit": {
47
+ "id": "a91957a858320c0e17f3a0eca7cfacbff50ea29a",
48
+ "short_id": "a91957a8",
49
+ "title": "Merge branch 'rename-readme' into 'master'\r",
50
+ "author_name": "Administrator",
51
+ "author_email": "admin@example.com",
52
+ "created_at": "2016-08-11T13:28:26.000+02:00",
53
+ "message": "Merge branch 'rename-readme' into 'master'\r\n\r\nRename README\r\n\r\n\r\n\r\nSee merge request !2"
54
+ },
55
+ "runner": null
56
+ }
57
+ }
@@ -0,0 +1,116 @@
1
+ [
2
+ {
3
+ "created_at": "2016-08-11T07:36:40.222Z",
4
+ "deployable": {
5
+ "commit": {
6
+ "author_email": "admin@example.com",
7
+ "author_name": "Administrator",
8
+ "created_at": "2016-08-11T09:36:01.000+02:00",
9
+ "id": "99d03678b90d914dbb1b109132516d71a4a03ea8",
10
+ "message": "Merge branch 'new-title' into 'master'\r\n\r\nUpdate README\r\n\r\n\r\n\r\nSee merge request !1",
11
+ "short_id": "99d03678",
12
+ "title": "Merge branch 'new-title' into 'master'\r"
13
+ },
14
+ "coverage": null,
15
+ "created_at": "2016-08-11T07:36:27.357Z",
16
+ "finished_at": "2016-08-11T07:36:39.851Z",
17
+ "id": 657,
18
+ "name": "deploy",
19
+ "ref": "master",
20
+ "runner": null,
21
+ "stage": "deploy",
22
+ "started_at": null,
23
+ "status": "success",
24
+ "tag": false,
25
+ "user": {
26
+ "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon",
27
+ "bio": null,
28
+ "created_at": "2016-08-11T07:09:20.351Z",
29
+ "id": 1,
30
+ "linkedin": "",
31
+ "location": null,
32
+ "name": "Administrator",
33
+ "skype": "",
34
+ "state": "active",
35
+ "twitter": "",
36
+ "username": "root",
37
+ "web_url": "http://localhost:3000/root",
38
+ "website_url": ""
39
+ }
40
+ },
41
+ "environment": {
42
+ "external_url": "https://about.gitlab.com",
43
+ "id": 9,
44
+ "name": "production"
45
+ },
46
+ "id": 41,
47
+ "iid": 1,
48
+ "ref": "master",
49
+ "sha": "99d03678b90d914dbb1b109132516d71a4a03ea8",
50
+ "user": {
51
+ "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon",
52
+ "id": 1,
53
+ "name": "Administrator",
54
+ "state": "active",
55
+ "username": "root",
56
+ "web_url": "http://localhost:3000/root"
57
+ }
58
+ },
59
+ {
60
+ "created_at": "2016-08-11T11:32:35.444Z",
61
+ "deployable": {
62
+ "commit": {
63
+ "author_email": "admin@example.com",
64
+ "author_name": "Administrator",
65
+ "created_at": "2016-08-11T13:28:26.000+02:00",
66
+ "id": "a91957a858320c0e17f3a0eca7cfacbff50ea29a",
67
+ "message": "Merge branch 'rename-readme' into 'master'\r\n\r\nRename README\r\n\r\n\r\n\r\nSee merge request !2",
68
+ "short_id": "a91957a8",
69
+ "title": "Merge branch 'rename-readme' into 'master'\r"
70
+ },
71
+ "coverage": null,
72
+ "created_at": "2016-08-11T11:32:24.456Z",
73
+ "finished_at": "2016-08-11T11:32:35.145Z",
74
+ "id": 664,
75
+ "name": "deploy",
76
+ "ref": "master",
77
+ "runner": null,
78
+ "stage": "deploy",
79
+ "started_at": null,
80
+ "status": "success",
81
+ "tag": false,
82
+ "user": {
83
+ "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon",
84
+ "bio": null,
85
+ "created_at": "2016-08-11T07:09:20.351Z",
86
+ "id": 1,
87
+ "linkedin": "",
88
+ "location": null,
89
+ "name": "Administrator",
90
+ "skype": "",
91
+ "state": "active",
92
+ "twitter": "",
93
+ "username": "root",
94
+ "web_url": "http://localhost:3000/root",
95
+ "website_url": ""
96
+ }
97
+ },
98
+ "environment": {
99
+ "external_url": "https://about.gitlab.com",
100
+ "id": 9,
101
+ "name": "production"
102
+ },
103
+ "id": 42,
104
+ "iid": 2,
105
+ "ref": "master",
106
+ "sha": "a91957a858320c0e17f3a0eca7cfacbff50ea29a",
107
+ "user": {
108
+ "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon",
109
+ "id": 1,
110
+ "name": "Administrator",
111
+ "state": "active",
112
+ "username": "root",
113
+ "web_url": "http://localhost:3000/root"
114
+ }
115
+ }
116
+ ]
@@ -0,0 +1,14 @@
1
+ {
2
+ "id": 1,
3
+ "name": "Foobar Group",
4
+ "path": "foo-bar",
5
+ "description": "An interesting group",
6
+ "visibility": "public",
7
+ "lfs_enabled": true,
8
+ "avatar_url": "http://gitlab.example.com/uploads/group/avatar/1/foo.jpg",
9
+ "web_url": "http://gitlab.example.com/groups/foo-bar",
10
+ "request_access_enabled": false,
11
+ "full_name": "Foobar Group",
12
+ "full_path": "foo-bar",
13
+ "parent_id": 123
14
+ }
@@ -0,0 +1,16 @@
1
+ [
2
+ {
3
+ "id": 1,
4
+ "name": "Foobar Group",
5
+ "path": "foo-bar",
6
+ "description": "An interesting group",
7
+ "visibility": "public",
8
+ "lfs_enabled": true,
9
+ "avatar_url": "http://gitlab.example.com/uploads/group/avatar/1/foo.jpg",
10
+ "web_url": "http://gitlab.example.com/groups/foo-bar",
11
+ "request_access_enabled": false,
12
+ "full_name": "Foobar Group",
13
+ "full_path": "foo-bar",
14
+ "parent_id": 123
15
+ }
16
+ ]
@@ -0,0 +1,32 @@
1
+ {
2
+ "id": 13,
3
+ "description": "Test schedule pipeline",
4
+ "ref": "master",
5
+ "cron": "* * * * *",
6
+ "cron_timezone": "Asia/Tokyo",
7
+ "next_run_at": "2017-05-19T13:41:00.000Z",
8
+ "active": true,
9
+ "created_at": "2017-05-19T13:31:08.849Z",
10
+ "updated_at": "2017-05-19T13:40:17.727Z",
11
+ "last_pipeline": {
12
+ "id": 332,
13
+ "sha": "0e788619d0b5ec17388dffb973ecd505946156db",
14
+ "ref": "master",
15
+ "status": "pending"
16
+ },
17
+ "owner": {
18
+ "name": "Administrator",
19
+ "username": "root",
20
+ "id": 1,
21
+ "state": "active",
22
+ "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon",
23
+ "web_url": "https://gitlab.example.com/root"
24
+ },
25
+ "variables": [
26
+ {
27
+ "key": "TEST_VARIABLE_1",
28
+ "value": "TEST_1"
29
+ }
30
+ ]
31
+ }
32
+
@@ -0,0 +1,21 @@
1
+ {
2
+ "id": 14,
3
+ "description": "Build packages",
4
+ "ref": "master",
5
+ "cron": "0 1 * * 5",
6
+ "cron_timezone": "UTC",
7
+ "next_run_at": "2017-05-26T01:00:00.000Z",
8
+ "active": true,
9
+ "created_at": "2017-05-19T13:43:08.169Z",
10
+ "updated_at": "2017-05-19T13:43:08.169Z",
11
+ "last_pipeline": null,
12
+ "owner": {
13
+ "name": "Administrator",
14
+ "username": "root",
15
+ "id": 1,
16
+ "state": "active",
17
+ "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon",
18
+ "web_url": "https://gitlab.example.com/root"
19
+ }
20
+ }
21
+
@@ -0,0 +1,26 @@
1
+ {
2
+ "id": 13,
3
+ "description": "Test schedule pipeline",
4
+ "ref": "master",
5
+ "cron": "0 2 * * *",
6
+ "cron_timezone": "Asia/Tokyo",
7
+ "next_run_at": "2017-05-19T17:00:00.000Z",
8
+ "active": true,
9
+ "created_at": "2017-05-19T13:31:08.849Z",
10
+ "updated_at": "2017-05-19T13:44:16.135Z",
11
+ "last_pipeline": {
12
+ "id": 332,
13
+ "sha": "0e788619d0b5ec17388dffb973ecd505946156db",
14
+ "ref": "master",
15
+ "status": "pending"
16
+ },
17
+ "owner": {
18
+ "name": "Administrator",
19
+ "username": "root",
20
+ "id": 1,
21
+ "state": "active",
22
+ "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon",
23
+ "web_url": "https://gitlab.example.com/root"
24
+ }
25
+ }
26
+