Module: Octokit::Client::Labels

Included in:
Octokit::Client
Defined in:
lib/octokit/client/labels.rb

Overview

Methods for the Issue Labels API

Instance Method Summary collapse

Instance Method Details

#add_label(repo, label, color = 'ffffff', options = {}) ⇒ Sawyer::Resource

Add a label to a repository

Examples:

Add a new label “Version 1.0” with color “#cccccc”

Octokit.add_label("octokit/octokit.rb", "Version 1.0", "cccccc")

Parameters:

  • repo (Integer, String, Repository, Hash)

    A GitHub repository

  • label (String)

    A new label

  • color (String) (defaults to: 'ffffff')

    A color, in hex, without the leading #

Returns:

  • (Sawyer::Resource)

    The new label

See Also:



43
44
45
# File 'lib/octokit/client/labels.rb', line 43

def add_label(repo, label, color = 'ffffff', options = {})
  post "#{Repository.path repo}/labels", options.merge({ name: label, color: color })
end

#add_labels_to_an_issue(repo, number, labels) ⇒ Array<Sawyer::Resource>

Add label(s) to an Issue

Examples:

Add two labels for octokit/octokit.rb

Octokit.add_labels_to_an_issue("octokit/octokit.rb", 10, ['V3 Transition', 'Improvement'])

Parameters:

  • repo (Integer, String, Repository, Hash)

    A Github repository

  • number (Integer)

    Number ID of the issue

  • labels (Array)

    An array of labels to apply to this Issue

Returns:

  • (Array<Sawyer::Resource>)

    A list of the labels currently on the issue

See Also:



126
127
128
# File 'lib/octokit/client/labels.rb', line 126

def add_labels_to_an_issue(repo, number, labels)
  post "#{Repository.path repo}/issues/#{number}/labels", labels
end

#delete_label!(repo, label, options = {}) ⇒ Boolean

Delete a label from a repository.

This deletes the label from the repository, and removes it from all issues.

Examples:

Delete the label “Version 1.0” from the repository.

Octokit.delete_label!("octokit/octokit.rb", "Version 1.0")

Parameters:

  • repo (Integer, String, Repository, Hash)

    A GitHub repository

  • label (String)

    String name of the label

Returns:

  • (Boolean)

    Success

See Also:



72
73
74
# File 'lib/octokit/client/labels.rb', line 72

def delete_label!(repo, label, options = {})
  boolean_from_response :delete, "#{Repository.path repo}/labels/#{ERB::Util.url_encode(label)}", options
end

#label(repo, name, options = {}) ⇒ Sawyer::Resource

Get single label for a repository

Examples:

Get the “V3 Addition” label from octokit/octokit.rb

Octokit.label("octokit/octokit.rb", "V3 Addition")

Parameters:

  • repo (Integer, String, Repository, Hash)

    A GitHub repository

  • name (String)

    Name of the label

Returns:

  • (Sawyer::Resource)

    A single label from the repository

See Also:



30
31
32
# File 'lib/octokit/client/labels.rb', line 30

def label(repo, name, options = {})
  get "#{Repository.path repo}/labels/#{ERB::Util.url_encode(name)}", options
end

#labels(repo, options = {}) ⇒ Array<Sawyer::Resource>

List available labels for a repository

Examples:

List labels for octokit/octokit.rb

Octokit.labels("octokit/octokit.rb")

Parameters:

  • repo (Integer, String, Repository, Hash)

    A GitHub repository

Returns:

  • (Array<Sawyer::Resource>)

    A list of the labels across the repository

See Also:



18
19
20
# File 'lib/octokit/client/labels.rb', line 18

def labels(repo, options = {})
  paginate "#{Repository.path repo}/labels", options
end

#labels_for_issue(repo, number, options = {}) ⇒ Array<Sawyer::Resource>

List labels for a given issue

Examples:

List labels for octokit/octokit.rb, issue # 1

Octokit.labels_for_issue("octokit/octokit.rb", 1)

Parameters:

  • repo (Integer, String, Repository, Hash)

    A GitHub repository

  • number (Integer)

    Number ID of the issue

Returns:

  • (Array<Sawyer::Resource>)

    A list of the labels currently on the issue

See Also:



113
114
115
# File 'lib/octokit/client/labels.rb', line 113

def labels_for_issue(repo, number, options = {})
  paginate "#{Repository.path repo}/issues/#{number}/labels", options
end

#labels_for_milestone(repo, number, options = {}) ⇒ Array<Sawyer::Resource>

Get labels for every issue in a milestone

Examples:

List all labels for milestone #2 on octokit/octokit.rb

Octokit.labels_for_milestone("octokit/octokit.rb", 2)

Parameters:

  • repo (Integer, String, Repository, Hash)

    A GitHub repository

  • number (Integer)

    Number ID of the milestone

Returns:

  • (Array<Sawyer::Resource>)

    A list of the labels across the milestone

See Also:



151
152
153
# File 'lib/octokit/client/labels.rb', line 151

def labels_for_milestone(repo, number, options = {})
  paginate "#{Repository.path repo}/milestones/#{number}/labels", options
end

#remove_all_labels(repo, number, options = {}) ⇒ Boolean

Remove all label from an Issue

This removes the label from the Issue

Examples:

Remove all labels from Issue #23

Octokit.remove_all_labels("octokit/octokit.rb", 23)

Parameters:

  • repo (Integer, String, Repository, Hash)

    A GitHub repository

  • number (Integer)

    Number ID of the issue

Returns:

  • (Boolean)

    Success of operation

See Also:



101
102
103
# File 'lib/octokit/client/labels.rb', line 101

def remove_all_labels(repo, number, options = {})
  boolean_from_response :delete, "#{Repository.path repo}/issues/#{number}/labels", options
end

#remove_label(repo, number, label, options = {}) ⇒ Array<Sawyer::Resource>

Remove a label from an Issue

This removes the label from the Issue

Examples:

Remove the label “Version 1.0” from the repository.

Octokit.remove_label("octokit/octokit.rb", 23, "Version 1.0")

Parameters:

  • repo (Integer, String, Repository, Hash)

    A GitHub repository

  • number (Integer)

    Number ID of the issue

  • label (String)

    String name of the label

Returns:

  • (Array<Sawyer::Resource>)

    A list of the labels currently on the issue

See Also:



87
88
89
# File 'lib/octokit/client/labels.rb', line 87

def remove_label(repo, number, label, options = {})
  delete "#{Repository.path repo}/issues/#{number}/labels/#{ERB::Util.url_encode(label)}", options
end

#replace_all_labels(repo, number, labels, _options = {}) ⇒ Array<Sawyer::Resource>

Replace all labels on an Issue

Examples:

Replace labels for octokit/octokit.rb Issue #10

Octokit.replace_all_labels("octokit/octokit.rb", 10, ['V3 Transition', 'Improvement'])

Parameters:

  • repo (Integer, String, Repository, Hash)

    A Github repository

  • number (Integer)

    Number ID of the issue

  • labels (Array)

    An array of labels to use as replacement

Returns:

  • (Array<Sawyer::Resource>)

    A list of the labels currently on the issue

See Also:



139
140
141
# File 'lib/octokit/client/labels.rb', line 139

def replace_all_labels(repo, number, labels, _options = {})
  put "#{Repository.path repo}/issues/#{number}/labels", labels
end

#update_label(repo, label, options = {}) ⇒ Sawyer::Resource

Update a label

Examples:

Update the label “Version 1.0” with new color “#cceeaa”

Octokit.update_label("octokit/octokit.rb", "Version 1.0", {:color => "cceeaa"})

Parameters:

  • repo (Integer, String, Repository, Hash)

    A GitHub repository

  • label (String)

    The name of the label which will be updated

  • options (Hash) (defaults to: {})

    A customizable set of options.

Options Hash (options):

  • :name (String)

    An updated label name

  • :color (String)

    An updated color value, in hex, without leading #

Returns:

  • (Sawyer::Resource)

    The updated label

See Also:



58
59
60
# File 'lib/octokit/client/labels.rb', line 58

def update_label(repo, label, options = {})
  patch "#{Repository.path repo}/labels/#{ERB::Util.url_encode(label)}", options
end