Class: Octopolo::GitHub::Issue

Inherits:
Object
  • Object
show all
Defined in:
lib/octopolo/github/issue.rb

Direct Known Subclasses

PullRequest

Constant Summary collapse

MissingParameter =
Class.new StandardError
NotFound =
Class.new StandardError
CommentFailed =
Class.new StandardError

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repo_name, number, data = nil) ⇒ Issue

Returns a new instance of Issue.

Raises:



10
11
12
13
14
15
16
# File 'lib/octopolo/github/issue.rb', line 10

def initialize repo_name, number, data = nil
  raise MissingParameter if repo_name.nil? or number.nil?

  self.repo_name = repo_name
  self.number = number
  self.data = data
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



6
7
8
# File 'lib/octopolo/github/issue.rb', line 6

def data
  @data
end

#numberObject

Returns the value of attribute number.



8
9
10
# File 'lib/octopolo/github/issue.rb', line 8

def number
  @number
end

#repo_nameObject

Returns the value of attribute repo_name.



7
8
9
# File 'lib/octopolo/github/issue.rb', line 7

def repo_name
  @repo_name
end

Class Method Details

.create(repo_name, options) ⇒ Object

Public: Create a issue for the given repo

repo_name - Full name (“account/repo”) of the repo in question options - Hash of issue information

title: Title of the issue
description: Brief description of the issue

Returns a Issue instance



26
27
28
29
30
31
# File 'lib/octopolo/github/issue.rb', line 26

def self.create(repo_name, options)
  # create via the API
  creator = IssueCreator.perform(repo_name, options)
  # wrap in our class
  new repo_name, creator.number, creator.data
end

Instance Method Details

#add_labels(*labels) ⇒ Object

Public: Adds labels to a pull-request

labels - label objects, can be a single label, an array of labels,

or a list of labels


86
87
88
89
# File 'lib/octopolo/github/issue.rb', line 86

def add_labels(*labels)
  built_labels = Label.build_label_array(labels)
  GitHub.add_labels_to_issue(repo_name, number, built_labels.map(&:name) )
end

#bodyObject



55
56
57
# File 'lib/octopolo/github/issue.rb', line 55

def body
  data.body || ""
end

#commenter_namesObject



47
48
49
# File 'lib/octopolo/github/issue.rb', line 47

def commenter_names
  exclude_octopolo_user (comments.map{ |comment| GitHub::User.new(comment.user.).author_name }.uniq)
end

#commentsObject



69
70
71
# File 'lib/octopolo/github/issue.rb', line 69

def comments
  @comments ||= GitHub.issue_comments(repo_name, number)
end

#exclude_octopolo_user(user_list) ⇒ Object



51
52
53
# File 'lib/octopolo/github/issue.rb', line 51

def exclude_octopolo_user(user_list)
  user_list.reject{|u| GitHub.excluded_users.include?(u) }
end

#external_urlsObject



59
60
61
62
# File 'lib/octopolo/github/issue.rb', line 59

def external_urls
  # extract http and https URLs from the body
  URI.extract body, %w(http https)
end

#human_app_nameObject



64
65
66
67
# File 'lib/octopolo/github/issue.rb', line 64

def human_app_name
  repo = repo_name.split("/").last
  repo.split("_").map(&:capitalize).join(" ")
end

#remove_labels(*labels) ⇒ Object

Public: Removes labels from a pull-request,

labels - label objects, can be a single label, an array of labels,

or a list of labels


95
96
97
98
99
# File 'lib/octopolo/github/issue.rb', line 95

def remove_labels(*labels)
  Label.build_label_array(labels).each do |built_label|
    GitHub.remove_label(repo_name, number, built_label.name)
  end
end

#titleObject



39
40
41
# File 'lib/octopolo/github/issue.rb', line 39

def title
  data.title
end

#urlObject



43
44
45
# File 'lib/octopolo/github/issue.rb', line 43

def url
  data.html_url
end

#write_comment(message) ⇒ Object

Public: Add a comment to the issue

message - A String containing the desired comment body



76
77
78
79
80
# File 'lib/octopolo/github/issue.rb', line 76

def write_comment(message)
  GitHub.add_comment repo_name, number, ":octocat: #{message}"
rescue Octokit::UnprocessableEntity => error
  raise CommentFailed, "Unable to write the comment: '#{error.message}'"
end