File: environments.rb

package info (click to toggle)
ruby-gitlab 5.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,660 kB
  • sloc: ruby: 12,582; makefile: 7; sh: 4
file content (89 lines) | stat: -rw-r--r-- 3,457 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# frozen_string_literal: true

class Gitlab::Client
  # Defines methods related to environments.
  # @see https://docs.gitlab.com/ce/api/environments.html
  module Environments
    # Gets a list of project environments.
    #
    # @example
    #   Gitlab.environments(5)
    #   Gitlab.environments(5, { per_page: 10, page:  2 })
    #
    # @param  [Integer, String] project The ID or name of a project.
    # @param  [Hash] options A customizable set of options.
    # @option options [Integer] :page The page number.
    # @option options [Integer] :per_page The number of results per page.
    # @return [Array<Gitlab::ObjectifiedHash>]
    def environments(project, options = {})
      get("/projects/#{url_encode project}/environments", query: options)
    end

    # Gets a single environment.
    #
    # @example
    #   Gitlab.environment(5, 36)
    #
    # @param  [Integer, String] project The ID or name of a project.
    # @param  [Integer] id The ID of an environment.
    # @return [Gitlab::ObjectifiedHash]
    def environment(project, id)
      get("/projects/#{url_encode project}/environments/#{id}")
    end

    # Create an environment.
    #
    # @examples
    #   Gitlab.create_environment(5, 'test-branch')
    #   Gitlab.create_environment(5, 'test-branch', external_url: 'https://test-branch.example.host.com')
    #
    # @param  [Integer, String] project The ID or name of a project.
    # @param  [String] env_name Name for the environment
    # @option options [String] :external_url Optional URL for viewing the deployed project in this environment
    # @return [Gitlab::ObjectifiedHash] The updated environment.
    def create_environment(project, env_name, options = {})
      body = { name: env_name }.merge(options)
      post("/projects/#{url_encode project}/environments", body: body)
    end

    # Update an environment.
    #
    # @examples
    #   Gitlab.edit_environment(5, 36, name: 'test-branch')
    #   Gitlab.edit_environment(5, 36, external_url: 'https://test-branch.example.host.com')
    #
    # @param  [Integer, String] project The ID or name of a project.
    # @param  [Integer] id The ID of an environment.
    # @param  [Hash] options A hash of the attribute keys & values to update.
    # @option options [String] env_name Name for the environment
    # @option options [String] external_url Optional URL for viewing the deployed project in this environment
    # @return [Gitlab::ObjectifiedHash] The updated environment.
    def edit_environment(project, id, options = {})
      put("/projects/#{url_encode project}/environments/#{id}", body: options)
    end

    # Deletes an environment.
    #
    # @example
    #   Gitlab.delete_environment(5, 36)
    #
    # @param  [Integer, String] project The ID or name of a project.
    # @param  [Integer] id The ID of an environment.
    # @return [Gitlab::ObjectifiedHash] Information about the deleted environment.
    def delete_environment(project, id)
      delete("/projects/#{url_encode project}/environments/#{id}")
    end

    # Stop an environment.
    #
    # @example
    #   Gitlab.stop_environment(5, 36)
    #
    # @param  [Integer, String] project The ID or name of a project.
    # @param  [Integer] id The ID of an environment.
    # @return [Array<Gitlab::ObjectifiedHash>] The stopped environment.
    def stop_environment(project, id)
      post("/projects/#{url_encode project}/environments/#{id}/stop")
    end
  end
end