Class: Github::Client::Issues::Labels

Inherits:
API
  • Object
show all
Defined in:
lib/github_api/client/issues/labels.rb

Constant Summary collapse

VALID_LABEL_INPUTS =
%w[ name color ].freeze

Constants included from MimeType

MimeType::MEDIA_LOOKUP

Constants included from Github::Constants

Github::Constants::ACCEPT, Github::Constants::ACCEPTED_OAUTH_SCOPES, Github::Constants::ACCEPT_CHARSET, Github::Constants::CACHE_CONTROL, Github::Constants::CONTENT_LENGTH, Github::Constants::CONTENT_TYPE, Github::Constants::DATE, Github::Constants::ETAG, Github::Constants::HEADER_LAST, Github::Constants::HEADER_LINK, Github::Constants::HEADER_NEXT, Github::Constants::LOCATION, Github::Constants::META_FIRST, Github::Constants::META_LAST, Github::Constants::META_NEXT, Github::Constants::META_PREV, Github::Constants::META_REL, Github::Constants::OAUTH_SCOPES, Github::Constants::PARAM_PAGE, Github::Constants::PARAM_PER_PAGE, Github::Constants::PARAM_START_PAGE, Github::Constants::RATELIMIT_LIMIT, Github::Constants::RATELIMIT_REMAINING, Github::Constants::RATELIMIT_RESET, Github::Constants::SERVER, Github::Constants::USER_AGENT

Instance Attribute Summary

Attributes inherited from API

#current_options

Instance Method Summary collapse

Methods inherited from API

after_callbacks, after_request, #api_methods_in, #arguments, before_callbacks, before_request, clear_request_methods!, #disable_redirects, #execute, extend_with_actions, extra_methods, #extract_basic_auth, extract_class_name, #filter_callbacks, inherited, #initialize, internal_methods, method_added, #method_missing, #module_methods_in, namespace, request_methods, require_all, #respond_to?, root!, #run_callbacks, #set, #yield_or_eval

Methods included from Request::Verbs

#delete_request, #get_request, #head_request, #options_request, #patch_request, #post_request, #put_request

Methods included from RateLimit

#ratelimit, #ratelimit_remaining, #ratelimit_reset

Methods included from MimeType

#lookup_media, #parse

Methods included from Authorization

#auth_code, #authenticated?, #authentication, #authorize_url, #basic_authed?, #client, #get_token

Constructor Details

This class inherits a constructor from Github::API

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Github::API

Instance Method Details

#add(*args) ⇒ Object Also known as: <<

Add labels to an issue

Examples:

github = Github.new
github.issues.labels.add 'user-name', 'repo-name', 'issue-number',
  'label1', 'label2', ...


134
135
136
137
138
139
140
# File 'lib/github_api/client/issues/labels.rb', line 134

def add(*args)
  arguments(args, required: [:user, :repo, :number])
  params = arguments.params
  params['data'] = arguments.remaining unless arguments.remaining.empty?

  post_request("/repos/#{arguments.user}/#{arguments.repo}/issues/#{arguments.number}/labels", params)
end

#create(*args) ⇒ Object

Create a label

Examples:

github = Github.new user: 'user-name', repo: 'repo-name'
github.issues.labels.create name: 'API', color: 'FFFFFF'

Parameters:



80
81
82
83
84
85
86
87
# File 'lib/github_api/client/issues/labels.rb', line 80

def create(*args)
  arguments(args, required: [:user, :repo]) do
    permit VALID_LABEL_INPUTS
    assert_required VALID_LABEL_INPUTS
  end

  post_request("/repos/#{arguments.user}/#{arguments.repo}/labels", arguments.params)
end

#delete(*args) ⇒ Object

Delete a label



120
121
122
123
124
# File 'lib/github_api/client/issues/labels.rb', line 120

def delete(*args)
  arguments(args, required: [:user, :repo, :label_name])

  delete_request("/repos/#{arguments.user}/#{arguments.repo}/labels/#{arguments.label_name}", arguments.params)
end

#get(*args) ⇒ Object Also known as: find

Get a single label

Examples:

github = Github.new
github.issues.labels.find 'user-name', 'repo-name', 'label-name'
github = Github.new user: 'user-name', repo: 'repo-name'
github.issues.labels.get label_name: 'bug'


59
60
61
62
63
64
# File 'lib/github_api/client/issues/labels.rb', line 59

def get(*args)
  arguments(args, required: [:user, :repo, :label_name])
  params = arguments.params

  get_request("/repos/#{arguments.user}/#{arguments.repo}/labels/#{arguments.label_name}", params)
end

#list(*args) ⇒ Object Also known as: all

List all labels for a repository

Get labels for every issue in a milestone

List labels on an issue

Examples:

github = Github.new user: 'user-name', repo: 'repo-name'
github.issues.labels.list
github.issues.labels.list { |label| ... }
github = Github.new
github.issues.labels.list 'user-name', 'repo-name', milestone_id: 'milestone-id'
github = Github.new
github.issues.labels.list 'user-name', 'repo-name', issue_id: 'issue-id'


30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/github_api/client/issues/labels.rb', line 30

def list(*args)
  arguments(args, required: [:user, :repo])
  params = arguments.params
  user = arguments.user
  repo = arguments.repo

  response = if (milestone_id = params.delete('milestone_id'))
    get_request("/repos/#{user}/#{repo}/milestones/#{milestone_id}/labels", params)
  elsif (issue_id = params.delete('issue_id'))
    get_request("/repos/#{user}/#{repo}/issues/#{issue_id}/labels", params)
  else
    get_request("/repos/#{user}/#{repo}/labels", params)
  end
  return response unless block_given?
  response.each { |el| yield el }
end

#remove(*args) ⇒ Object

Remove a label from an issue

Remove all labels from an issue

Examples:

github = Github.new
github.issues.labels.remove 'user-name', 'repo-name', 'issue-number',
  label_name: 'label-name'
github = Github.new
github.issues.labels.remove 'user-name', 'repo-name', 'issue-number'


157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'lib/github_api/client/issues/labels.rb', line 157

def remove(*args)
  arguments(args, required: [:user, :repo, :number])
  params = arguments.params
  user   = arguments.user
  repo   = arguments.repo
  number = arguments.number

  if (label_name = params.delete('label_name'))
    delete_request("/repos/#{user}/#{repo}/issues/#{number}/labels/#{label_name}", params)
  else
    delete_request("/repos/#{user}/#{repo}/issues/#{number}/labels", params)
  end
end

#replace(*args) ⇒ Object

Replace all labels for an issue

Sending an empty array ([]) will remove all Labels from the Issue.

Examples:

github = Github.new
github.issues.labels.replace 'user-name', 'repo-name', 'issue-number',
  'label1', 'label2', ...


181
182
183
184
185
186
187
# File 'lib/github_api/client/issues/labels.rb', line 181

def replace(*args)
  arguments(args, required: [:user, :repo, :number])
  params = arguments.params
  params['data'] = arguments.remaining unless arguments.remaining.empty?

  put_request("/repos/#{arguments.user}/#{arguments.repo}/issues/#{arguments.number}/labels", params)
end

#update(*args) ⇒ Object Also known as: edit

Update a label

Examples:

github = Github.new
github.issues.labels.update 'user-name', 'repo-name', 'label-name',
  name: 'API', color: "FFFFFF"

Parameters:



103
104
105
106
107
108
109
110
# File 'lib/github_api/client/issues/labels.rb', line 103

def update(*args)
  arguments(args, required: [:user, :repo, :label_name]) do
    permit VALID_LABEL_INPUTS
    assert_required VALID_LABEL_INPUTS
  end

  patch_request("/repos/#{arguments.user}/#{arguments.repo}/labels/#{arguments.label_name}", arguments.params)
end