gitlab-faraday 5.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. checksums.yaml +7 -0
  2. data/lib/gitlab/api.rb +16 -0
  3. data/lib/gitlab/client/access_requests.rb +103 -0
  4. data/lib/gitlab/client/application_settings.rb +172 -0
  5. data/lib/gitlab/client/avatar.rb +21 -0
  6. data/lib/gitlab/client/award_emojis.rb +137 -0
  7. data/lib/gitlab/client/boards.rb +146 -0
  8. data/lib/gitlab/client/branches.rb +135 -0
  9. data/lib/gitlab/client/broadcast_messages.rb +75 -0
  10. data/lib/gitlab/client/build_variables.rb +135 -0
  11. data/lib/gitlab/client/builds.rb +108 -0
  12. data/lib/gitlab/client/commits.rb +216 -0
  13. data/lib/gitlab/client/container_registry.rb +90 -0
  14. data/lib/gitlab/client/deployments.rb +34 -0
  15. data/lib/gitlab/client/environments.rb +89 -0
  16. data/lib/gitlab/client/epic_issues.rb +23 -0
  17. data/lib/gitlab/client/epics.rb +73 -0
  18. data/lib/gitlab/client/events.rb +60 -0
  19. data/lib/gitlab/client/features.rb +48 -0
  20. data/lib/gitlab/client/group_badges.rb +88 -0
  21. data/lib/gitlab/client/group_boards.rb +141 -0
  22. data/lib/gitlab/client/group_labels.rb +88 -0
  23. data/lib/gitlab/client/group_milestones.rb +94 -0
  24. data/lib/gitlab/client/groups.rb +526 -0
  25. data/lib/gitlab/client/issue_links.rb +48 -0
  26. data/lib/gitlab/client/issues.rb +242 -0
  27. data/lib/gitlab/client/jobs.rb +250 -0
  28. data/lib/gitlab/client/keys.rb +29 -0
  29. data/lib/gitlab/client/labels.rb +88 -0
  30. data/lib/gitlab/client/lint.rb +19 -0
  31. data/lib/gitlab/client/markdown.rb +23 -0
  32. data/lib/gitlab/client/merge_request_approvals.rb +265 -0
  33. data/lib/gitlab/client/merge_requests.rb +415 -0
  34. data/lib/gitlab/client/merge_trains.rb +55 -0
  35. data/lib/gitlab/client/milestones.rb +106 -0
  36. data/lib/gitlab/client/namespaces.rb +22 -0
  37. data/lib/gitlab/client/notes.rb +313 -0
  38. data/lib/gitlab/client/packages.rb +95 -0
  39. data/lib/gitlab/client/pipeline_schedules.rb +159 -0
  40. data/lib/gitlab/client/pipeline_triggers.rb +103 -0
  41. data/lib/gitlab/client/pipelines.rb +130 -0
  42. data/lib/gitlab/client/project_badges.rb +85 -0
  43. data/lib/gitlab/client/project_clusters.rb +83 -0
  44. data/lib/gitlab/client/project_exports.rb +54 -0
  45. data/lib/gitlab/client/project_release_links.rb +76 -0
  46. data/lib/gitlab/client/project_releases.rb +90 -0
  47. data/lib/gitlab/client/projects.rb +792 -0
  48. data/lib/gitlab/client/protected_tags.rb +59 -0
  49. data/lib/gitlab/client/remote_mirrors.rb +90 -0
  50. data/lib/gitlab/client/repositories.rb +130 -0
  51. data/lib/gitlab/client/repository_files.rb +131 -0
  52. data/lib/gitlab/client/repository_submodules.rb +27 -0
  53. data/lib/gitlab/client/resource_label_events.rb +82 -0
  54. data/lib/gitlab/client/resource_state_events.rb +57 -0
  55. data/lib/gitlab/client/runners.rb +278 -0
  56. data/lib/gitlab/client/search.rb +66 -0
  57. data/lib/gitlab/client/services.rb +53 -0
  58. data/lib/gitlab/client/sidekiq.rb +39 -0
  59. data/lib/gitlab/client/snippets.rb +95 -0
  60. data/lib/gitlab/client/system_hooks.rb +64 -0
  61. data/lib/gitlab/client/tags.rb +97 -0
  62. data/lib/gitlab/client/templates.rb +100 -0
  63. data/lib/gitlab/client/todos.rb +46 -0
  64. data/lib/gitlab/client/user_snippets.rb +114 -0
  65. data/lib/gitlab/client/users.rb +521 -0
  66. data/lib/gitlab/client/versions.rb +18 -0
  67. data/lib/gitlab/client/wikis.rb +79 -0
  68. data/lib/gitlab/client.rb +96 -0
  69. data/lib/gitlab/configuration.rb +36 -0
  70. data/lib/gitlab/error.rb +114 -0
  71. data/lib/gitlab/file_response.rb +43 -0
  72. data/lib/gitlab/headers/page_links.rb +32 -0
  73. data/lib/gitlab/headers/total.rb +24 -0
  74. data/lib/gitlab/objectified_hash.rb +44 -0
  75. data/lib/gitlab/paginated_response.rb +114 -0
  76. data/lib/gitlab/request.rb +144 -0
  77. data/lib/gitlab/version.rb +5 -0
  78. data/lib/gitlab.rb +36 -0
  79. metadata +156 -0
@@ -0,0 +1,135 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Gitlab::Client
4
+ # Defines methods related to repositories.
5
+ # @see https://docs.gitlab.com/ce/api/branches.html
6
+ module Branches
7
+ # Gets a list of project repositiory branches.
8
+ #
9
+ # @example
10
+ # Gitlab.branches(42)
11
+ #
12
+ # @param [Integer, String] project The ID or name of a project.
13
+ # @param [Hash] options A customizable set of options.
14
+ # @option options [Integer] :page The page number.
15
+ # @option options [Integer] :per_page The number of results per page.
16
+ # @return [Array<Gitlab::ObjectifiedHash>]
17
+ def branches(project, options = {})
18
+ get("/projects/#{url_encode project}/repository/branches", query: options)
19
+ end
20
+ alias repo_branches branches
21
+
22
+ # Gets information about a repository branch.
23
+ #
24
+ # @example
25
+ # Gitlab.branch(3, 'api')
26
+ # Gitlab.repo_branch(5, 'master')
27
+ #
28
+ # @param [Integer, String] project The ID or name of a project.
29
+ # @param [String] branch The name of the branch.
30
+ # @return [Gitlab::ObjectifiedHash]
31
+ def branch(project, branch)
32
+ get("/projects/#{url_encode project}/repository/branches/#{url_encode branch}")
33
+ end
34
+ alias repo_branch branch
35
+
36
+ # Protects a repository branch.
37
+ #
38
+ # @example
39
+ # Gitlab.protect_branch(3, 'api')
40
+ # Gitlab.repo_protect_branch(5, 'master')
41
+ # Gitlab.protect_branch(5, 'api', developers_can_push: true)
42
+ #
43
+ # To update options, call `protect_branch` again with new options (i.e. `developers_can_push: false`)
44
+ #
45
+ # @param [Integer, String] project The ID or name of a project.
46
+ # @param [String] branch The name of the branch.
47
+ # @param [Hash] options A customizable set of options.
48
+ # @option options [Boolean] :developers_can_push True to allow developers to push to the branch (default = false)
49
+ # @option options [Boolean] :developers_can_merge True to allow developers to merge into the branch (default = false)
50
+ # @return [Gitlab::ObjectifiedHash] Details about the branch
51
+ def protect_branch(project, branch, options = {})
52
+ post("/projects/#{url_encode project}/protected_branches", body: { name: branch }.merge(options))
53
+ end
54
+ alias repo_protect_branch protect_branch
55
+
56
+ # Unprotects a repository branch.
57
+ #
58
+ # @example
59
+ # Gitlab.unprotect_branch(3, 'api')
60
+ # Gitlab.repo_unprotect_branch(5, 'master')
61
+ #
62
+ # @param [Integer, String] project The ID or name of a project.
63
+ # @param [String] branch The name of the branch.
64
+ # @return [Gitlab::ObjectifiedHash] Details about the branch
65
+ def unprotect_branch(project, branch)
66
+ delete("/projects/#{url_encode project}/protected_branches/#{url_encode branch}")
67
+ end
68
+ alias repo_unprotect_branch unprotect_branch
69
+
70
+ # Creates a repository branch. Requires Gitlab >= 6.8.x
71
+ #
72
+ # @example
73
+ # Gitlab.create_branch(3, 'api', 'feat/new-api')
74
+ # Gitlab.repo_create_branch(5, 'master', 'develop')
75
+ #
76
+ # @param [Integer, String] project The ID or name of a project.
77
+ # @param [String] branch The name of the new branch.
78
+ # @param [String] ref Create branch from commit sha or existing branch
79
+ # @return [Gitlab::ObjectifiedHash] Details about the branch
80
+ def create_branch(project, branch, ref)
81
+ post("/projects/#{url_encode project}/repository/branches", query: { branch: branch, ref: ref })
82
+ end
83
+ alias repo_create_branch create_branch
84
+
85
+ # Deletes a repository branch. Requires Gitlab >= 6.8.x
86
+ #
87
+ # @example
88
+ # Gitlab.delete_branch(3, 'api')
89
+ # Gitlab.repo_delete_branch(5, 'master')
90
+ #
91
+ # @param [Integer, String] project The ID or name of a project.
92
+ # @param [String] branch The name of the branch to delete
93
+ def delete_branch(project, branch)
94
+ delete("/projects/#{url_encode project}/repository/branches/#{url_encode branch}")
95
+ end
96
+ alias repo_delete_branch delete_branch
97
+
98
+ # Delete all branches that are merged into the project default branch. Protected branches will not be deleted as part of this operation.
99
+ #
100
+ # @example
101
+ # Gitlab.delete_merged_branches(3)
102
+ #
103
+ # @param [Integer, String] project The ID or name of a project.
104
+ # @return [nil] This API call returns an empty response body.
105
+ def delete_merged_branches(project)
106
+ delete("/projects/#{url_encode project}/repository/merged_branches")
107
+ end
108
+ alias repo_delete_merged_branches delete_merged_branches
109
+
110
+ # Gets a list of protected branches from a project.
111
+ #
112
+ # @example
113
+ # Gitlab.protected_branches(42)
114
+ #
115
+ # @param [Integer, String] project The ID or name of a project.
116
+ # @return [Array<Gitlab::ObjectifiedHash>]
117
+ def protected_branches(project)
118
+ get("/projects/#{url_encode project}/protected_branches")
119
+ end
120
+ alias repo_protected_branches protected_branches
121
+
122
+ # Gets a single protected branch or wildcard protected branch
123
+ #
124
+ # @example
125
+ # Gitlab.protected_branch(3, 'api')
126
+ #
127
+ # @param [Integer, String] project The ID or name of a project.
128
+ # @param [String] name The name of the branch or wildcard
129
+ # @return [Gitlab::ObjectifiedHash]
130
+ def protected_branch(project, branch)
131
+ get("/projects/#{url_encode project}/protected_branches/#{url_encode branch}")
132
+ end
133
+ alias repo_protected_branch protected_branch
134
+ end
135
+ end
@@ -0,0 +1,75 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Gitlab::Client
4
+ # Defines methods related to broadcast messages (only accessible to administrators).
5
+ # @see https://docs.gitlab.com/ce/api/broadcast_messages.html
6
+ module BroadcastMessages
7
+ # Get all broadcast messages
8
+ #
9
+ # @example
10
+ # Gitlab.broadcast_messages
11
+ #
12
+ # @return [Array<Gitlab::ObjectifiedHash>]
13
+ def broadcast_messages
14
+ get('/broadcast_messages')
15
+ end
16
+
17
+ # Get a specific broadcast message
18
+ #
19
+ # @example
20
+ # Gitlab.broadcast_message(3)
21
+ #
22
+ # @param [Integer] id The ID of broadcast message
23
+ # @return [Gitlab::ObjectifiedHash]
24
+ def broadcast_message(id)
25
+ get("/broadcast_messages/#{id}")
26
+ end
27
+
28
+ # Create a broadcast message.
29
+ #
30
+ # @example
31
+ # Gitlab.create_broadcast_message('Mayday')
32
+ # Gitlab.create_broadcast_message('Mayday', {starts_at: Time.zone.now, ends_at: Time.zone.now + 30.minutes, color: '#cecece', font: '#FFFFFF'})
33
+ #
34
+ # @param [String] message Message to display
35
+ # @param [Hash] options A customizable set of options.
36
+ # @option options [DateTime] :starts_at(optional) Starting time (defaults to current time)
37
+ # @option options [DateTime] :ends_at(optional) Ending time (defaults to one hour from current time)
38
+ # @option options [String] :color(optional) Background color hex code
39
+ # @option options [String] :font(optional) Foreground color hex code
40
+ # @return [Gitlab::ObjectifiedHash] Information about created broadcast message.
41
+ def create_broadcast_message(message, options = {})
42
+ body = { message: message }.merge(options)
43
+ post('/broadcast_messages', body: body)
44
+ end
45
+
46
+ # Update a broadcast message
47
+ #
48
+ # @example
49
+ # Gitlab.edit_broadcast_message(6, { message: 'No Mayday' })
50
+ # Gitlab.edit_broadcast_message(6, { font: '#FEFEFE' })
51
+ #
52
+ # @param [Integer] id The ID of a broadcast message
53
+ # @param [Hash] options A customizable set of options.
54
+ # @option options [String] :message(optional) Message to display
55
+ # @option options [DateTime] :starts_at(optional) Starting time (defaults to current time)
56
+ # @option options [DateTime] :ends_at(optional) Ending time (defaults to one hour from current time)
57
+ # @option options [String] :color(optional) Background color hex code
58
+ # @option options [String] :font(optional) Foreground color hex code
59
+ # @return [Gitlab::ObjectifiedHash] Information about updated broadcast message.
60
+ def edit_broadcast_message(id, options = {})
61
+ put("/broadcast_messages/#{id}", body: options)
62
+ end
63
+
64
+ # Delete a broadcast message.
65
+ #
66
+ # @example
67
+ # Gitlab.delete_broadcast_message(3)
68
+ #
69
+ # @param [Integer] id The ID of a broadcast message.
70
+ # @return [nil] This API call returns an empty response body.
71
+ def delete_broadcast_message(id)
72
+ delete("/broadcast_messages/#{id}")
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,135 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Gitlab::Client
4
+ # Defines methods related to builds.
5
+ # @see https://docs.gitlab.com/ce/api/project_level_variables.html
6
+ # @see https://docs.gitlab.com/ce/api/group_level_variables.html
7
+ module BuildVariables
8
+ # Gets a list of the project's build variables
9
+ #
10
+ # @example
11
+ # Gitlab.variables(5)
12
+ #
13
+ # @param [Integer, String] project The ID or name of a project.
14
+ # @return [Array<Gitlab::ObjectifiedHash>] The list of variables.
15
+ def variables(project)
16
+ get("/projects/#{url_encode project}/variables")
17
+ end
18
+
19
+ # Gets details of a project's specific build variable.
20
+ #
21
+ # @example
22
+ # Gitlab.variable(5, "TEST_VARIABLE_1")
23
+ #
24
+ # @param [Integer, String] project The ID or name of a project.
25
+ # @param [String] key The key of a variable.
26
+ # @return [Gitlab::ObjectifiedHash] The variable.
27
+ def variable(project, key)
28
+ get("/projects/#{url_encode project}/variables/#{key}")
29
+ end
30
+
31
+ # Create a build variable for a project.
32
+ #
33
+ # @example
34
+ # Gitlab.create_variable(5, "NEW_VARIABLE", "new value")
35
+ #
36
+ # @param [Integer, String] project The ID or name of a project.
37
+ # @param [String] key The key of a variable; must have no more than 255 characters; only `A-Z`, `a-z`, `0-9` and `_` are allowed
38
+ # @param [String] value The value of a variable
39
+ # @param [Hash] opts optional parameters
40
+ # @return [Gitlab::ObjectifiedHash] The variable.
41
+ def create_variable(project, key, value, **opts)
42
+ post("/projects/#{url_encode project}/variables", body: opts.merge(key: key, value: value))
43
+ end
44
+
45
+ # Update a project's build variable.
46
+ #
47
+ # @example
48
+ # Gitlab.update_variable(5, "NEW_VARIABLE", "updated value")
49
+ #
50
+ # @param [Integer, String] project The ID or name of a project.
51
+ # @param [String] key The key of a variable
52
+ # @param [String] value The value of a variable
53
+ # @param [Hash] opts optional parameters
54
+ # @return [Gitlab::ObjectifiedHash] The variable.
55
+ def update_variable(project, key, value, **opts)
56
+ put("/projects/#{url_encode project}/variables/#{key}", body: opts.merge(value: value))
57
+ end
58
+
59
+ # Remove a project's build variable.
60
+ #
61
+ # @example
62
+ # Gitlab.remove_variable(5, "VARIABLE_1")
63
+ #
64
+ # @param [Integer, String] project The ID or name of a project.
65
+ # @param [String] key The key of a variable.
66
+ # @param [Hash] opts optional parameters
67
+ # @return [Gitlab::ObjectifiedHash] The variable.
68
+ def remove_variable(project, key, **opts)
69
+ delete("/projects/#{url_encode project}/variables/#{key}", query: opts)
70
+ end
71
+
72
+ # Gets a list of the group's build variables
73
+ #
74
+ # @example
75
+ # Gitlab.group_variables(5)
76
+ #
77
+ # @param [Integer, String] group The ID or name of a group.
78
+ # @return [Array<Gitlab::ObjectifiedHash>] The list of variables.
79
+ def group_variables(group)
80
+ get("/groups/#{url_encode group}/variables")
81
+ end
82
+
83
+ # Gets details of a group's specific build variable.
84
+ #
85
+ # @example
86
+ # Gitlab.group_variable(5, "TEST_VARIABLE_1")
87
+ #
88
+ # @param [Integer, String] group The ID or name of a group.
89
+ # @param [String] key The key of a variable.
90
+ # @return [Gitlab::ObjectifiedHash] The variable.
91
+ def group_variable(group, key)
92
+ get("/groups/#{url_encode group}/variables/#{key}")
93
+ end
94
+
95
+ # Create a build variable for a group.
96
+ #
97
+ # @example
98
+ # Gitlab.create_group_variable(5, "NEW_VARIABLE", "new value")
99
+ #
100
+ # @param [Integer, String] group The ID or name of a group.
101
+ # @param [String] key The key of a variable; must have no more than 255 characters; only `A-Z`, `a-z`, `0-9` and `_` are allowed
102
+ # @param [String] value The value of a variable
103
+ # @param [Hash] opts optional parameters
104
+ # @return [Gitlab::ObjectifiedHash] The variable.
105
+ def create_group_variable(group, key, value, **opts)
106
+ post("/groups/#{url_encode group}/variables", body: opts.merge(key: key, value: value))
107
+ end
108
+
109
+ # Update a group's build variable.
110
+ #
111
+ # @example
112
+ # Gitlab.update_group_variable(5, "NEW_VARIABLE", "updated value")
113
+ #
114
+ # @param [Integer, String] group The ID or name of a group.
115
+ # @param [String] key The key of a variable
116
+ # @param [String] value The value of a variable
117
+ # @param [Hash] opts optional parameters
118
+ # @return [Gitlab::ObjectifiedHash] The variable.
119
+ def update_group_variable(group, key, value, **opts)
120
+ put("/groups/#{url_encode group}/variables/#{key}", body: opts.merge(value: value))
121
+ end
122
+
123
+ # Remove a group's build variable.
124
+ #
125
+ # @example
126
+ # Gitlab.remove_group_variable(5, "VARIABLE_1")
127
+ #
128
+ # @param [Integer, String] group The ID or name of a group.
129
+ # @param [String] key The key of a variable.
130
+ # @return [Gitlab::ObjectifiedHash] The variable.
131
+ def remove_group_variable(group, key)
132
+ delete("/groups/#{url_encode group}/variables/#{key}")
133
+ end
134
+ end
135
+ end
@@ -0,0 +1,108 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Gitlab::Client
4
+ # Defines methods related to builds.
5
+ # @see https://docs.gitlab.com/ce/api/builds.html
6
+ module Builds
7
+ # Gets a list of project builds.
8
+ #
9
+ # @example
10
+ # Gitlab.builds(5)
11
+ # Gitlab.builds(5, { per_page: 10, page: 2 })
12
+ #
13
+ # @param [Integer, String] project The ID or name of a project.
14
+ # @param [Hash] options A customizable set of options.
15
+ # @option options [Integer] :page The page number.
16
+ # @option options [Integer] :per_page The number of results per page.
17
+ # @param [Integer, String] project The ID or name of a project.
18
+ # @return [Array<Gitlab::ObjectifiedHash>]
19
+ def builds(project, options = {})
20
+ get("/projects/#{url_encode project}/builds", query: options)
21
+ end
22
+
23
+ # Gets a single build.
24
+ #
25
+ # @example
26
+ # Gitlab.build(5, 36)
27
+ #
28
+ # @param [Integer, String] project The ID or name of a project.
29
+ # @param [Integer] id The ID of a build.
30
+ # @return [Gitlab::ObjectifiedHash]
31
+ def build(project, id)
32
+ get("/projects/#{url_encode project}/builds/#{id}")
33
+ end
34
+
35
+ # Gets build artifacts.
36
+ #
37
+ # @example
38
+ # Gitlab.build_artifacts(1, 8)
39
+ #
40
+ # @param [Integer, String] project The ID or name of a project.
41
+ # @param [Integer] id The ID of a build.
42
+ # @return [Gitlab::FileResponse]
43
+ def build_artifacts(project, id)
44
+ get("/projects/#{url_encode project}/builds/#{id}/artifacts",
45
+ format: nil,
46
+ headers: { Accept: 'application/octet-stream' },
47
+ parser: proc { |body, _|
48
+ if body.encoding == Encoding::ASCII_8BIT # binary response
49
+ ::Gitlab::FileResponse.new StringIO.new(body, 'rb+')
50
+ else # error with json response
51
+ ::Gitlab::Request.parse(body)
52
+ end
53
+ })
54
+ end
55
+
56
+ # Gets a list of builds for specific commit in a project.
57
+ #
58
+ # @example
59
+ # Gitlab.commit_builds(5, 'asdf')
60
+ # Gitlab.commit_builds(5, 'asdf', { per_page: 10, page: 2 })
61
+ #
62
+ # @param [Integer, String] project The ID or name of a project.
63
+ # @param [String] sha The SHA checksum of a commit.
64
+ # @param [Hash] options A customizable set of options.
65
+ # @option options [Integer] :page The page number.
66
+ # @option options [Integer] :per_page The number of results per page.
67
+ # @return [Array<Gitlab::ObjectifiedHash>] The list of builds.
68
+ def commit_builds(project, sha, options = {})
69
+ get("/projects/#{url_encode project}/repository/commits/#{sha}/builds", query: options)
70
+ end
71
+
72
+ # Cancels a build.
73
+ #
74
+ # @example
75
+ # Gitlab.build_cancel(5, 1)
76
+ #
77
+ # @param [Integer, String] project The ID or name of a project.
78
+ # @param [Integer] id The ID of a build.
79
+ # @return [Gitlab::ObjectifiedHash] The builds changes.
80
+ def build_cancel(project, id)
81
+ post("/projects/#{url_encode project}/builds/#{id}/cancel")
82
+ end
83
+
84
+ # Retry a build.
85
+ #
86
+ # @example
87
+ # Gitlab.build_retry(5, 1)
88
+ #
89
+ # @param [Integer, String] project The ID or name of a project.
90
+ # @param [Integer] id The ID of a build.
91
+ # @return [Array<Gitlab::ObjectifiedHash>] The builds changes.
92
+ def build_retry(project, id)
93
+ post("/projects/#{url_encode project}/builds/#{id}/retry")
94
+ end
95
+
96
+ # Erase a single build of a project (remove build artifacts and a build trace)
97
+ #
98
+ # @example
99
+ # Gitlab.build_erase(5, 1)
100
+ #
101
+ # @param [Integer, String] project The ID or name of a project.
102
+ # @param [Integer] id The ID of a build.
103
+ # @return [Gitlab::ObjectifiedHash] The build's changes.
104
+ def build_erase(project, id)
105
+ post("/projects/#{url_encode project}/builds/#{id}/erase")
106
+ end
107
+ end
108
+ end
@@ -0,0 +1,216 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Gitlab::Client
4
+ # Defines methods related to repository commits.
5
+ # @see https://docs.gitlab.com/ce/api/commits.html
6
+ module Commits
7
+ # Gets a list of project commits.
8
+ #
9
+ # @example
10
+ # Gitlab.commits('viking')
11
+ # Gitlab.repo_commits('gitlab', { ref: 'api' })
12
+ #
13
+ # @param [Integer, String] project The ID or name of a project.
14
+ # @param [Hash] options A customizable set of options.
15
+ # @option options [String] :ref The branch or tag name of a project repository.
16
+ # @option options [Integer] :page The page number.
17
+ # @option options [Integer] :per_page The number of results per page.
18
+ # @return [Array<Gitlab::ObjectifiedHash>]
19
+ def commits(project, options = {})
20
+ get("/projects/#{url_encode project}/repository/commits", query: options)
21
+ end
22
+ alias repo_commits commits
23
+
24
+ # Gets a specific commit identified by the commit hash or name of a branch or tag.
25
+ #
26
+ # @example
27
+ # Gitlab.commit(42, '6104942438c14ec7bd21c6cd5bd995272b3faff6')
28
+ # Gitlab.repo_commit(3, 'ed899a2f4b50b4370feeea94676502b42383c746')
29
+ #
30
+ # @param [Integer, String] project The ID or name of a project.
31
+ # @param [String] sha The commit hash or name of a repository branch or tag
32
+ # @return [Gitlab::ObjectifiedHash]
33
+ def commit(project, sha)
34
+ get("/projects/#{url_encode project}/repository/commits/#{sha}")
35
+ end
36
+ alias repo_commit commit
37
+
38
+ # Get all references (from branches or tags) a commit is pushed to.
39
+ #
40
+ # @example
41
+ # Gitlab.commit_refs(42, '6104942438c14ec7bd21c6cd5bd995272b3faff6')
42
+ #
43
+ # @param [Integer, String] project The ID or name of a project.
44
+ # @param [String] sha The commit hash
45
+ # @param [Hash] options A customizable set of options.
46
+ # @option options [String] :type The scope of commits. Possible values `branch`, `tag`, `all`. Default is `all`.
47
+ # @option options [Integer] :page The page number.
48
+ # @option options [Integer] :per_page The number of results per page.
49
+ # @return [Gitlab::ObjectifiedHash]
50
+ def commit_refs(project, sha, options = {})
51
+ get("/projects/#{url_encode project}/repository/commits/#{sha}/refs", query: options)
52
+ end
53
+
54
+ # Cherry picks a commit to a given branch.
55
+ #
56
+ # @example
57
+ # Gitlab.cherry_pick_commit(42, '6104942438c14ec7bd21c6cd5bd995272b3faff6', 'master')
58
+ #
59
+ # @param [Integer, String] project The ID or name of a project.
60
+ # @param [String] sha The commit hash or name of a repository branch or tag
61
+ # @param [String] branch The name of the branch
62
+ # @param [Hash] options A customizable set of options.
63
+ # @option options [Boolean] :dry_run Don't commit any changes
64
+ # @return [Gitlab::ObjectifiedHash]
65
+ def cherry_pick_commit(project, sha, branch, options = {})
66
+ options[:branch] = branch
67
+
68
+ post("/projects/#{url_encode project}/repository/commits/#{sha}/cherry_pick", body: options)
69
+ end
70
+
71
+ # Reverts a commit in a given branch.
72
+ #
73
+ # @example
74
+ # Gitlab.revert_commit(42, '6104942438c14ec7bd21c6cd5bd995272b3faff6', 'master')
75
+ #
76
+ # @param [Integer, String] project The ID or name of a project.
77
+ # @param [String] sha The commit hash or name of a repository branch or tag
78
+ # @param [String] branch The name of the branch
79
+ # @param [Hash] options A customizable set of options.
80
+ # @option options [Boolean] :dry_run Don't commit any changes
81
+ # @return [Gitlab::ObjectifiedHash]
82
+ def revert_commit(project, sha, branch, options = {})
83
+ options[:branch] = branch
84
+
85
+ post("/projects/#{url_encode project}/repository/commits/#{sha}/revert", body: options)
86
+ end
87
+
88
+ # Get the diff of a commit in a project.
89
+ #
90
+ # @example
91
+ # Gitlab.commit_diff(42, '6104942438c14ec7bd21c6cd5bd995272b3faff6')
92
+ # Gitlab.repo_commit_diff(3, 'ed899a2f4b50b4370feeea94676502b42383c746')
93
+ #
94
+ # @param [Integer, String] project The ID or name of a project.
95
+ # @param [String] sha The name of a repository branch or tag or if not given the default branch.
96
+ # @return [Gitlab::ObjectifiedHash]
97
+ def commit_diff(project, sha)
98
+ get("/projects/#{url_encode project}/repository/commits/#{sha}/diff")
99
+ end
100
+ alias repo_commit_diff commit_diff
101
+
102
+ # Gets a list of comments for a commit.
103
+ #
104
+ # @example
105
+ # Gitlab.commit_comments(5, 'c9f9662a9b1116c838b523ed64c6abdb4aae4b8b')
106
+ #
107
+ # @param [Integer] project The ID of a project.
108
+ # @param [String] sha The commit hash or name of a repository branch or tag.
109
+ # @option options [Integer] :page The page number.
110
+ # @option options [Integer] :per_page The number of results per page.
111
+ # @return [Array<Gitlab::ObjectifiedHash>]
112
+ def commit_comments(project, commit, options = {})
113
+ get("/projects/#{url_encode project}/repository/commits/#{commit}/comments", query: options)
114
+ end
115
+ alias repo_commit_comments commit_comments
116
+
117
+ # Creates a new comment for a commit.
118
+ #
119
+ # @example
120
+ # Gitlab.create_commit_comment(5, 'c9f9662a9b1116c838b523ed64c6abdb4aae4b8b', 'Nice work on this commit!')
121
+ #
122
+ # @param [Integer, String] project The ID or name of a project.
123
+ # @param [String] sha The commit hash or name of a repository branch or tag.
124
+ # @param [String] note The text of a comment.
125
+ # @param [Hash] options A customizable set of options.
126
+ # @option options [String] :path The file path.
127
+ # @option options [Integer] :line The line number.
128
+ # @option options [String] :line_type The line type (new or old).
129
+ # @return [Gitlab::ObjectifiedHash] Information about created comment.
130
+ def create_commit_comment(project, commit, note, options = {})
131
+ post("/projects/#{url_encode project}/repository/commits/#{commit}/comments", body: options.merge(note: note))
132
+ end
133
+ alias repo_create_commit_comment create_commit_comment
134
+
135
+ # Get the status of a commit
136
+ #
137
+ # @example
138
+ # Gitlab.commit_status(42, '6104942438c14ec7bd21c6cd5bd995272b3faff6')
139
+ # Gitlab.commit_status(42, '6104942438c14ec7bd21c6cd5bd995272b3faff6', { name: 'jenkins' })
140
+ # Gitlab.commit_status(42, '6104942438c14ec7bd21c6cd5bd995272b3faff6', { name: 'jenkins', all: true })
141
+ #
142
+ # @param [Integer, String] project The ID or name of a project.
143
+ # @param [String] sha The commit hash
144
+ # @param [Hash] options A customizable set of options.
145
+ # @option options [String] :ref Filter by ref name, it can be branch or tag
146
+ # @option options [String] :stage Filter by stage
147
+ # @option options [String] :name Filter by status name, eg. jenkins
148
+ # @option options [Boolean] :all The flag to return all statuses, not only latest ones
149
+ def commit_status(project, sha, options = {})
150
+ get("/projects/#{url_encode project}/repository/commits/#{sha}/statuses", query: options)
151
+ end
152
+ alias repo_commit_status commit_status
153
+
154
+ # Adds or updates a status of a commit.
155
+ #
156
+ # @example
157
+ # Gitlab.update_commit_status(42, '6104942438c14ec7bd21c6cd5bd995272b3faff6', 'success')
158
+ # Gitlab.update_commit_status(42, '6104942438c14ec7bd21c6cd5bd995272b3faff6', 'failed', { name: 'jenkins' })
159
+ # Gitlab.update_commit_status(42, '6104942438c14ec7bd21c6cd5bd995272b3faff6', 'canceled', { name: 'jenkins', target_url: 'http://example.com/builds/1' })
160
+ #
161
+ # @param [Integer, String] project The ID or name of a project.
162
+ # @param [String] sha The commit hash
163
+ # @param [String] state of the status. Can be: pending, running, success, failed, canceled
164
+ # @param [Hash] options A customizable set of options.
165
+ # @option options [String] :ref The ref (branch or tag) to which the status refers
166
+ # @option options [String] :name Filter by status name, eg. jenkins
167
+ # @option options [String] :target_url The target URL to associate with this status
168
+ def update_commit_status(project, sha, state, options = {})
169
+ post("/projects/#{url_encode project}/statuses/#{sha}", body: options.merge(state: state))
170
+ end
171
+ alias repo_update_commit_status update_commit_status
172
+
173
+ # Creates a single commit with one or more changes
174
+ #
175
+ # @see https://docs.gitlab.com/api/commits/#create-a-commit-with-multiple-files-and-actions
176
+ # Introduced in Gitlab 8.13
177
+ #
178
+ # @example
179
+ # Gitlab.create_commit(2726132, 'master', 'refactors everything', [{action: 'create', file_path: '/foo.txt', content: 'bar'}])
180
+ # Gitlab.create_commit(2726132, 'master', 'refactors everything', [{action: 'delete', file_path: '/foo.txt'}])
181
+ #
182
+ # @param [Integer, String] project The ID or name of a project.
183
+ # @param [String] branch the branch name you wish to commit to
184
+ # @param [String] message the commit message
185
+ # @param [Array[Hash]] An array of action hashes to commit as a batch. See the next table for what attributes it can take.
186
+ # @option options [String] :author_email the email address of the author
187
+ # @option options [String] :author_name the name of the author
188
+ # @return [Gitlab::ObjectifiedHash] hash of commit related data
189
+ def create_commit(project, branch, message, actions, options = {})
190
+ payload = {
191
+ branch: branch,
192
+ commit_message: message,
193
+ actions: actions
194
+ }.merge(options)
195
+ post("/projects/#{url_encode project}/repository/commits", body: payload)
196
+ end
197
+
198
+ # Gets a list of merge requests for a commit.
199
+ #
200
+ # @see https://docs.gitlab.com/ce/api/commits.html#list-merge-requests-associated-with-a-commit
201
+ # Introduced in Gitlab 10.7
202
+ #
203
+ # @example
204
+ # Gitlab.commit_merge_requests(5, 'c9f9662a9b1116c838b523ed64c6abdb4aae4b8b')
205
+ #
206
+ # @param [Integer] project The ID of a project.
207
+ # @param [String] sha The commit hash.
208
+ # @option options [Integer] :page The page number.
209
+ # @option options [Integer] :per_page The number of results per page.
210
+ # @return [Array<Gitlab::ObjectifiedHash>]
211
+ def commit_merge_requests(project, commit, options = {})
212
+ get("/projects/#{url_encode project}/repository/commits/#{commit}/merge_requests", query: options)
213
+ end
214
+ alias repo_commit_merge_requests commit_merge_requests
215
+ end
216
+ end