File: labels.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 (88 lines) | stat: -rw-r--r-- 3,568 bytes parent folder | download | duplicates (3)
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
# frozen_string_literal: true

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

    # Creates a new label.
    #
    # @example
    #   Gitlab.create_label(42, "Backlog", '#DD10AA')
    #
    # @param  [Integer, String] project The ID or name of a project.
    # @param  [String] name The name of a label.
    # @param  [String] color The color of a label.
    # @param  [Hash] options A customizable set of options.
    # @option options [String] :description The description of the label.
    # @option options [String] :priority The priority of the label. Must be greater or equal than zero or null to remove the priority.
    # @return [Gitlab::ObjectifiedHash] Information about created label.
    def create_label(project, name, color, options = {})
      post("/projects/#{url_encode project}/labels", body: options.merge(name: name, color: color))
    end

    # Updates a label.
    #
    # @example
    #   Gitlab.edit_label(42, "Backlog", { new_name: 'TODO' })
    #   Gitlab.edit_label(42, "Backlog", { new_name: 'TODO', color: '#DD10AA' })
    #
    # @param  [Integer, String] project The ID or name of a project.
    # @param  [String] name The name of a label.
    # @param  [Hash] options A customizable set of options.
    # @option options [String] :new_name The new name of a label.
    # @option options [String] :color The color of a label.
    # @option options [String] :description The description of the label.
    # @option options [String] :priority The priority of the label. Must be greater or equal than zero or null to remove the priority.
    # @return [Gitlab::ObjectifiedHash] Information about updated label.
    def edit_label(project, name, options = {})
      put("/projects/#{url_encode project}/labels", body: options.merge(name: name))
    end

    # Deletes a label.
    #
    # @example
    #   Gitlab.delete_label(2, 'Backlog')
    #
    # @param  [Integer, String] project The ID or name of a project.
    # @param  [String] name The name of a label.
    # @return [Gitlab::ObjectifiedHash] Information about deleted label.
    def delete_label(project, name)
      delete("/projects/#{url_encode project}/labels/#{name}")
    end

    # Subscribes the user to a label to receive notifications
    #
    # @example
    #   Gitlab.subscribe_to_label(2, 'Backlog')
    #
    # @param  [Integer, String] project The ID or name of a project.
    # @param  [String] name The name of a label.
    # @return [Gitlab::ObjectifiedHash] Information about the label subscribed to.
    def subscribe_to_label(project, name)
      post("/projects/#{url_encode project}/labels/#{url_encode name}/subscribe")
    end

    # Unsubscribes the user from a label to not receive notifications from it
    #
    # @example
    #   Gitlab.unsubscribe_from_label(2, 'Backlog')
    #
    # @param  [Integer, String] project The ID or name of a project.
    # @param  [String] name The name of a label.
    # @return [Gitlab::ObjectifiedHash] Information about the label unsubscribed from.
    def unsubscribe_from_label(project, name)
      post("/projects/#{url_encode project}/labels/#{url_encode name}/unsubscribe")
    end
  end
end