Class: Cinch::Plugins::Github::Issue

Inherits:
Object
  • Object
show all
Includes:
Cinch::Plugin, Octopi
Defined in:
lib/cinch/plugins/github/issue.rb

Overview

Handles interaction with Issues API.

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.authorObject

Returns the value of attribute author.



13
14
15
# File 'lib/cinch/plugins/github/issue.rb', line 13

def author
  @author
end

.repoObject

Returns the value of attribute repo.



13
14
15
# File 'lib/cinch/plugins/github/issue.rb', line 13

def repo
  @repo
end

.tokenObject

Returns the value of attribute token.



13
14
15
# File 'lib/cinch/plugins/github/issue.rb', line 13

def token
  @token
end

.userObject

Returns the value of attribute user.



13
14
15
# File 'lib/cinch/plugins/github/issue.rb', line 13

def user
  @user
end

Class Method Details

.configure {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



15
16
17
# File 'lib/cinch/plugins/github/issue.rb', line 15

def configure(&block)
  yield self
end

Instance Method Details

#close_issue(m, number, comment = "") ⇒ Object

Closes issue



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/cinch/plugins/github/issue.rb', line 109

def close_issue(m, number, comment="")
  i = find_issue(number)
  authenticated_with :login => self.class.user, :token => self.class.token do

    if i.close!

      msg = "Closed via IRC by #{m.user.nick}"
      if comment != ""
        msg += "\n#{comment}"
      end
      i.comment msg
      m.reply("Marked as closed: #{issue_link(number)}")
    else
      m.reply("Sorry, close failed #{issue_link(number)}")
    end
  end
end

#comment_issue(m, number, comment) ⇒ Object

Comments on the issue



99
100
101
102
103
104
105
106
# File 'lib/cinch/plugins/github/issue.rb', line 99

def comment_issue(m, number, comment)
  i = find_issue(number)
  authenticated_with :login => self.class.user, :token => self.class.token do
    if i.comment "Via #{m.user.nick} on IRC: #{comment}"
      m.reply "Comment added. #{issue_link(number)}"
    end
  end
end

#display_help(m) ⇒ Object

Display Github Issue Help



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/cinch/plugins/github/issue.rb', line 31

def display_help(m)
  User(m.user.nick).send (<<-EOF).gsub(/^ {10}/,'')
  !issue state [open|closed] [query]        - query for a ticket with state closed
  !issue find [query]                       - query for a ticket with state open
  !issue show [number]                      - shows detail for issue
  !issue link [number]                      - returns link for issue number.
  !issue close [number] [optional comment]  - close an issue
  !issue reopen [number] [optional comment] - reopen an issue
  !issue comment [number] [comment]         - comment on an issue
  !issue new [title]                        - create a new issue
  EOF
end

#find_issue(number) ⇒ Object



79
80
81
82
83
# File 'lib/cinch/plugins/github/issue.rb', line 79

def find_issue(number)
  authenticated_with :login => self.class.user, :token => self.class.token do
    Octopi::Issue.find :user => self.class.author, :repo => self.class.repo, :number => number
  end
end

#get_ticket(m, *args) ⇒ Object

Find ticket with gieven



45
46
47
48
49
# File 'lib/cinch/plugins/github/issue.rb', line 45

def get_ticket(m, *args)
  query, state = args.reverse
  results = search_issue CGI.escape(query), state
  output m, results.first.last
end

Returns the issue as a link



75
76
77
# File 'lib/cinch/plugins/github/issue.rb', line 75

def issue_link(number)
  "https://www.github.com/#{self.class.author}/#{self.class.repo}/issues/#{number}"
end

#new_issue(m, title) ⇒ Object

Creates an issue



86
87
88
89
90
91
92
93
94
95
96
# File 'lib/cinch/plugins/github/issue.rb', line 86

def new_issue(m, title)
  authenticated_with :login => self.class.user, :token => self.class.token do
    params = { :title => title, :body => "Opened via #{m.user.nick} on IRC" }
    i = Octopi::Issue.open :user => self.class.author, :repo => self.class.repo, :params => params
    if i
      m.reply "Issue created: #{issue_link(i.number)}"
    else
      m.reply "Issue creation failed. Sorry."
    end
  end
end

#reopen_issue(m, number, comment = "") ⇒ Object

Closes the issue



128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/cinch/plugins/github/issue.rb', line 128

def reopen_issue(m, number, comment="")
  i = find_issue(number)
  authenticated_with :login => self.class.user, :token => self.class.token do

    if i.reopen!

      msg = "Reopened via IRC by #{m.user.nick}"
      if comment != ""
        msg += "\n#{comment}"
      end
      i.comment msg
      m.reply("Marked as reopened: #{issue_link(number)}")
    else
      m.reply("Sorry, reopen failed #{issue_link(number)}")
    end
  end
end

Return the link of the issue



63
64
65
# File 'lib/cinch/plugins/github/issue.rb', line 63

def reply_link(m, arg)
  arg =~ /\D+/ ? m.reply("You need to give me a number...") : m.reply(issue_link(arg))
end

#search_issue(query, state = 'open') ⇒ Object

Use Github API and Search for the Issue



68
69
70
71
72
# File 'lib/cinch/plugins/github/issue.rb', line 68

def search_issue(query, state = 'open')
  authenticated_with :login => self.class.user, :token => self.class.token do
    Octopi::Issue.search :user => self.class.author, :repo => self.class.repo, :state => state, :keyword => query
  end
end

#show_issue(m, arg) ⇒ Object

show ticket title



52
53
54
55
56
57
58
59
60
# File 'lib/cinch/plugins/github/issue.rb', line 52

def show_issue(m, arg)
  result = find_issue(arg)
  p result
  if result
    m.reply "##{arg} #{result.title} : #{issue_link(arg)}"
  else
    m.reply "Not found"
  end
end