Class: Danger::DangerAutoLabel

Inherits:
Plugin
  • Object
show all
Defined in:
lib/auto_label/plugin.rb

Overview

No more set label to pull request manually. Example, you can set labels simply by changing the PR title.

if github.pr_title.include? “[WIP]”

auto_label.wip=(github.pr_json["number"])

end

Examples:

Very simple usage. Set wip label automatically when the PR title contains “[WIP]”.


See Also:

  • kaelaela/danger-auto_label

Instance Method Summary collapse

Instance Method Details

#delete(name) ⇒ void

This method returns an undefined value.

Delete label from PR.

Parameters:

  • name (String)

    Delete label name.



62
63
64
# File 'lib/auto_label/plugin.rb', line 62

def delete(name)
  github.api.delete_label!(repo, name)
end

#set(pr, name, color) ⇒ void

This method returns an undefined value.

Set any labels to PR by this.

Parameters:

  • pr (Number)

    A number of issue or pull request for set label.

  • name (String)

    A new label name.

  • color (String)

    A color, in hex, without the leading #. Default is “fef2c0”



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/auto_label/plugin.rb', line 46

def set(pr, name, color)
  message = ""
  if label?(name)
    message = "Set #{name} label. (Color: #{color})"
  else
    message = "Add #{name} new label. (Color: #{color})"
    add_label(name, color)
  end
  github.api.add_labels_to_an_issue(repo, pr, [name])
  puts message
end

#wip=(pr) ⇒ void

This method returns an undefined value.

Set WIP label to PR.

Parameters:

  • pr (Number)

    A number of issue or pull request for set label.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/auto_label/plugin.rb', line 21

def wip=(pr)
  label_names = []
  labels.each do |label|
    label_names << label.name
  end
  puts("exist labels:" + label_names.join(", "))
  unless wip?
    begin
      add_label("WIP")
    rescue Octokit::UnprocessableEntity => e
      puts "WIP label is already exists."
      puts e
    end
  end
  github.api.add_labels_to_an_issue(repo, pr, [wip_label])
end