github_issues_tracker.rb
1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
if defined? Octokit
class IssueTrackers::GithubIssuesTracker < IssueTracker
Label = "github"
Note = 'Please configure your github repository in the <strong>GITHUB REPO</strong> field above.<br/>' <<
'Instead of providing your username & password, you can link your Github account ' <<
'to your user profile, and allow Errbit to create issues using your OAuth token.'
Fields = [
[:username, {
:placeholder => "Your username on GitHub"
}],
[:password, {
:placeholder => "Password for your account"
}]
]
attr_accessor :oauth_token
def project_id
app.github_repo
end
def check_params
if Fields.detect {|f| self[f[0]].blank? }
errors.add :base, 'You must specify your GitHub username and password'
end
end
def create_issue(problem, reported_by = nil)
# Login using OAuth token, if given.
if oauth_token
client = Octokit::Client.new(:login => username, :access_token => oauth_token)
else
client = Octokit::Client.new(:login => username, :password => password)
end
begin
issue = client.create_issue(
project_id,
issue_title(problem),
body_template.result(binding).unpack('C*').pack('U*')
)
problem.update_attributes(
:issue_link => issue.rels[:html].href,
:issue_type => Label
)
rescue Octokit::Unauthorized
raise IssueTrackers::AuthenticationError, "Could not authenticate with GitHub. Please check your username and password."
end
end
def body_template
@@body_template ||= ERB.new(File.read(Rails.root + "app/views/issue_trackers/github_issues_body.txt.erb").gsub(/^\s*/, ''))
end
def url
"https://github.com/#{project_id}/issues"
end
end
end