Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 62 lines (50 sloc) 1.453 kb
ffd87c8 @joshuaflanagan Move Github API calls to GitHub object
authored
1 require 'rubygems'
2 require 'httparty'
3
376745c @joshuaflanagan Add endpoint to delete a label from an issue closed via commit
authored
4 module HTTParty
5 class Request
6 def path=(uri)
7 @path = URI.parse(URI.escape(uri))
8 end
9 end
10 end
11
ffd87c8 @joshuaflanagan Move Github API calls to GitHub object
authored
12 class GitHub
13 include HTTParty
14 base_uri "https://github.com/api/v2/json"
15
376745c @joshuaflanagan Add endpoint to delete a label from an issue closed via commit
authored
16 def initialize(repo, user=nil, pass=nil)
ffd87c8 @joshuaflanagan Move Github API calls to GitHub object
authored
17 @user = user
18 @pass = pass
19 @repo = repo
20 end
21
22 def label_issue(issue, label)
23 self.class.post("/issues/label/add/#{@repo}/#{label}/#{issue}", options)
24 end
25
376745c @joshuaflanagan Add endpoint to delete a label from an issue closed via commit
authored
26 def remove_issue_label(issue, label)
27 self.class.post("/issues/label/remove/#{@repo}/#{label}/#{issue}", options)
28 end
29
52d620d @joshuaflanagan Reopen an issue closed by a commit
authored
30 def reopen_issue(issue)
31 self.class.post("/issues/reopen/#{@repo}/#{issue}", options)
32 end
33
5ccfb85 @joshuaflanagan Comment on issues mentioned in commits
authored
34 def comment_issue(issue, comment)
35 options[:body] = {"comment" => comment}
36 self.class.post("/issues/comment/#{@repo}/#{issue}", options)
37 end
38
ffd87c8 @joshuaflanagan Move Github API calls to GitHub object
authored
39 def self.issue(message)
40 message[/gh-(\d+)/i,1]
41 end
42
55b3c58 @joshuaflanagan Recognizes multiple issues within a single commit message. Closes gh-1
authored
43 def self.closed_issues(message)
44 issues = message.scan(/(closes|fixes) (gh-|#)(\d+)/i).map{|m| m[2]}
45 return issues unless block_given?
46 issues.each{ |issue| yield(issue) }
47 end
48
49 def self.nonclosing_issues(message)
50 issues = message.scan(/(closes|fixes)? (gh-|#)(\d+)/i).
51 select{|m| m[0].nil? && m[1] != "#"}.
52 map{|m| m[2]}
53 return issues unless block_given?
54 issues.each{ |issue| yield(issue) }
585e0d2 @joshuaflanagan Different actions to label issues via closing and non-closing commits
authored
55 end
8ae0bd4 @joshuaflanagan Removed duplication around building request options
authored
56
57 private
58 def options
59 @options ||= @user.nil? ? {} : { :basic_auth => {:username => @user, :password => @pass}}
60 end
ffd87c8 @joshuaflanagan Move Github API calls to GitHub object
authored
61 end
Something went wrong with that request. Please try again.