Skip to content

Commit b00bfd9

Browse files
committed
Start the implementation
1 parent 4e4e8ad commit b00bfd9

File tree

4 files changed

+86
-5
lines changed

4 files changed

+86
-5
lines changed

errbit_github_plugin.gemspec

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
88
spec.version = ErrbitGithubPlugin::VERSION
99
spec.authors = ["Cyril Mougel"]
1010
spec.email = ["cyril.mougel@gmail.com"]
11-
spec.description = %q{TODO: Write a gem description}
12-
spec.summary = %q{TODO: Write a gem summary}
11+
spec.description = %q{Add Github issue tracker plugin to errbit}
12+
spec.summary = %q{Add Github issue tracker plugin to errbit}
1313
spec.homepage = ""
1414
spec.license = "MIT"
1515

@@ -18,6 +18,9 @@ Gem::Specification.new do |spec|
1818
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
1919
spec.require_paths = ["lib"]
2020

21+
spec.add_dependency "errbit_plugin"
22+
spec.add_dependency "octokit"
23+
2124
spec.add_development_dependency "bundler", "~> 1.3"
2225
spec.add_development_dependency "rake"
2326
end

lib/errbit_github_plugin.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
require "errbit_github_plugin/version"
2+
require 'errbit_github_plugin/error'
3+
require 'errbit_github_plugin/issue_tracker'
24

3-
module ErrbitGithubPlugin
4-
# Your code goes here...
5-
end
5+
ErrbitPlugin::Register.add_issue_tracker(
6+
'IssueTrackers::GithubIssuesTracker',
7+
ErrbitGithubPlugin::IssueTracker
8+
)

lib/errbit_github_plugin/error.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module ErrbitGithubPlugin
2+
class AuthenticationError < Exception; end
3+
end
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
require 'octokit'
2+
3+
module ErrbitGithubPlugin
4+
class IssueTracker < ErrbitPlugin::IssueTracker
5+
6+
def label; 'github'; end
7+
def note
8+
'Please configure your github repository in the <strong>GITHUB REPO</strong> field above.<br/>' <<
9+
'Instead of providing your username & password, you can link your Github account ' <<
10+
'to your user profile, and allow Errbit to create issues using your OAuth token.'
11+
end
12+
13+
def fields
14+
{
15+
:username => {
16+
:placeholder => "Your username on GitHub"
17+
},
18+
:password => {
19+
:placeholder => "Password for your account"
20+
}
21+
}
22+
end
23+
24+
attr_accessor :oauth_token
25+
attr_reader :url
26+
27+
def configured?
28+
project_id.present?
29+
end
30+
31+
def comments_allowed?; false; end
32+
33+
def project_id
34+
app.github_repo
35+
end
36+
37+
def check_params
38+
if Fields.detect {|f| self[f[0]].blank? }
39+
errors.add :base, 'You must specify your GitHub username and password'
40+
end
41+
end
42+
43+
def create_issue(problem, reported_by = nil)
44+
# Login using OAuth token, if given.
45+
if oauth_token
46+
client = Octokit::Client.new(:login => username, :oauth_token => oauth_token)
47+
else
48+
client = Octokit::Client.new(:login => username, :password => password)
49+
end
50+
51+
begin
52+
issue = client.create_issue(
53+
project_id,
54+
issue_title(problem),
55+
body_template.result(binding).unpack('C*').pack('U*')
56+
)
57+
@url = issue.html_url
58+
problem.update_attributes(
59+
:issue_link => issue.html_url,
60+
:issue_type => Label
61+
)
62+
63+
rescue Octokit::Unauthorized
64+
raise ErrbitGithubPlugin::AuthenticationError, "Could not authenticate with GitHub. Please check your username and password."
65+
end
66+
end
67+
68+
def body_template
69+
@@body_template ||= ERB.new(File.read(Rails.root + "app/views/issue_trackers/github_issues_body.txt.erb").gsub(/^\s*/, ''))
70+
end
71+
end
72+
end

0 commit comments

Comments
 (0)