File: build_variables.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 (135 lines) | stat: -rw-r--r-- 5,041 bytes parent folder | download
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# frozen_string_literal: true

class Gitlab::Client
  # Defines methods related to builds.
  # @see https://docs.gitlab.com/ce/api/project_level_variables.html
  # @see https://docs.gitlab.com/ce/api/group_level_variables.html
  module BuildVariables
    # Gets a list of the project's build variables
    #
    # @example
    #   Gitlab.variables(5)
    #
    # @param  [Integer, String] project The ID or name of a project.
    # @return [Array<Gitlab::ObjectifiedHash>] The list of variables.
    def variables(project)
      get("/projects/#{url_encode project}/variables")
    end

    # Gets details of a project's specific build variable.
    #
    # @example
    #   Gitlab.variable(5, "TEST_VARIABLE_1")
    #
    # @param  [Integer, String] project The ID or name of a project.
    # @param  [String] key The key of a variable.
    # @return [Gitlab::ObjectifiedHash] The variable.
    def variable(project, key)
      get("/projects/#{url_encode project}/variables/#{key}")
    end

    # Create a build variable for a project.
    #
    # @example
    #   Gitlab.create_variable(5, "NEW_VARIABLE", "new value")
    #
    # @param  [Integer, String] project The ID or name of a project.
    # @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
    # @param  [String] value The value of a variable
    # @param  [Hash] opts optional parameters
    # @return [Gitlab::ObjectifiedHash] The variable.
    def create_variable(project, key, value, **opts)
      post("/projects/#{url_encode project}/variables", body: opts.merge(key: key, value: value))
    end

    # Update a project's build variable.
    #
    # @example
    #   Gitlab.update_variable(5, "NEW_VARIABLE", "updated value")
    #
    # @param  [Integer, String] project The ID or name of a project.
    # @param  [String] key The key of a variable
    # @param  [String] value The value of a variable
    # @param  [Hash] opts optional parameters
    # @return [Gitlab::ObjectifiedHash] The variable.
    def update_variable(project, key, value, **opts)
      put("/projects/#{url_encode project}/variables/#{key}", body: opts.merge(value: value))
    end

    # Remove a project's build variable.
    #
    # @example
    #   Gitlab.remove_variable(5, "VARIABLE_1")
    #
    # @param  [Integer, String] project The ID or name of a project.
    # @param  [String] key The key of a variable.
    # @param  [Hash] opts optional parameters
    # @return [Gitlab::ObjectifiedHash] The variable.
    def remove_variable(project, key, **opts)
      delete("/projects/#{url_encode project}/variables/#{key}", query: opts)
    end

    # Gets a list of the group's build variables
    #
    # @example
    #   Gitlab.group_variables(5)
    #
    # @param  [Integer, String] group The ID or name of a group.
    # @return [Array<Gitlab::ObjectifiedHash>] The list of variables.
    def group_variables(group)
      get("/groups/#{url_encode group}/variables")
    end

    # Gets details of a group's specific build variable.
    #
    # @example
    #   Gitlab.group_variable(5, "TEST_VARIABLE_1")
    #
    # @param  [Integer, String] group The ID or name of a group.
    # @param  [String] key The key of a variable.
    # @return [Gitlab::ObjectifiedHash] The variable.
    def group_variable(group, key)
      get("/groups/#{url_encode group}/variables/#{key}")
    end

    # Create a build variable for a group.
    #
    # @example
    #   Gitlab.create_group_variable(5, "NEW_VARIABLE", "new value")
    #
    # @param  [Integer, String] group The ID or name of a group.
    # @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
    # @param  [String] value The value of a variable
    # @param  [Hash] opts optional parameters
    # @return [Gitlab::ObjectifiedHash] The variable.
    def create_group_variable(group, key, value, **opts)
      post("/groups/#{url_encode group}/variables", body: opts.merge(key: key, value: value))
    end

    # Update a group's build variable.
    #
    # @example
    #   Gitlab.update_group_variable(5, "NEW_VARIABLE", "updated value")
    #
    # @param  [Integer, String] group The ID or name of a group.
    # @param  [String] key The key of a variable
    # @param  [String] value The value of a variable
    # @param  [Hash] opts optional parameters
    # @return [Gitlab::ObjectifiedHash] The variable.
    def update_group_variable(group, key, value, **opts)
      put("/groups/#{url_encode group}/variables/#{key}", body: opts.merge(value: value))
    end

    # Remove a group's build variable.
    #
    # @example
    #   Gitlab.remove_group_variable(5, "VARIABLE_1")
    #
    # @param  [Integer, String] group The ID or name of a group.
    # @param  [String] key The key of a variable.
    # @return [Gitlab::ObjectifiedHash] The variable.
    def remove_group_variable(group, key)
      delete("/groups/#{url_encode group}/variables/#{key}")
    end
  end
end