Skip to content

Commit 1d74a96

Browse files
committed
Merge pull request #1 from brandedcrate/master
transfer improvements back to errbit organization
2 parents c0f3b36 + a1562ab commit 1d74a96

5 files changed

Lines changed: 108 additions & 38 deletions

File tree

errbit_github_plugin.gemspec

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ require 'errbit_github_plugin/version'
66
Gem::Specification.new do |spec|
77
spec.name = "errbit_github_plugin"
88
spec.version = ErrbitGithubPlugin::VERSION
9-
spec.authors = ["Cyril Mougel"]
10-
spec.email = ["cyril.mougel@gmail.com"]
11-
spec.description = %q{Add Github issue tracker plugin to errbit}
12-
spec.summary = %q{Add Github issue tracker plugin to errbit}
13-
spec.homepage = ""
9+
spec.authors = ["Stephen Crosby", "Cyril Mougel"]
10+
spec.email = ["stevecrozz@gmail.com", "cyril.mougel@gmail.com"]
11+
12+
spec.description = %q{GitHub integration for Errbit}
13+
spec.summary = %q{GitHub integration for Errbit}
14+
spec.homepage = "https://github.com/brandedcrate/errbit_github_plugin"
1415
spec.license = "MIT"
1516

1617
spec.files = `git ls-files`.split($/)

lib/errbit_github_plugin.rb

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
require 'errbit_github_plugin/issue_tracker'
44
require 'errbit_github_plugin/rails'
55

6-
ErrbitPlugin::Register.add_issue_tracker(
7-
'IssueTrackers::GithubIssuesTracker',
8-
ErrbitGithubPlugin::IssueTracker
9-
)
6+
module ErrbitGithubPlugin
7+
def self.root
8+
File.expand_path '../..', __FILE__
9+
end
10+
end
11+
12+
ErrbitPlugin::Registry.add_issue_tracker(ErrbitGithubPlugin::IssueTracker)

lib/errbit_github_plugin/issue_tracker.rb

Lines changed: 49 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,41 @@
33
module ErrbitGithubPlugin
44
class IssueTracker < ErrbitPlugin::IssueTracker
55

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
6+
LABEL = 'github'
7+
8+
NOTE = 'Please configure your github repository in the <strong>GITHUB ' <<
9+
'REPO</strong> field above.<br/> Instead of providing your ' <<
10+
'username & password, you can link your Github account to your ' <<
11+
'user profile, and allow Errbit to create issues using your ' <<
12+
'OAuth token.'
1213

13-
def fields
14-
{
15-
:username => {
16-
:placeholder => "Your username on GitHub"
17-
},
18-
:password => {
19-
:placeholder => "Password for your account"
20-
}
14+
FIELDS = {
15+
:username => {
16+
:placeholder => "Your username on GitHub"
17+
},
18+
:password => {
19+
:placeholder => "Password for your account"
2120
}
21+
}
22+
23+
def self.label
24+
LABEL
25+
end
26+
27+
def self.note
28+
NOTE
29+
end
30+
31+
def self.fields
32+
FIELDS
33+
end
34+
35+
def self.body_template
36+
@body_template ||= ERB.new(File.read(
37+
File.join(
38+
ErrbitGithubPlugin.root, 'views', 'github_issues_body.txt.erb'
39+
)
40+
))
2241
end
2342

2443
attr_accessor :oauth_token
@@ -34,39 +53,41 @@ def project_id
3453
app.github_repo
3554
end
3655

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'
56+
def errors
57+
errors = []
58+
if self.class.fields.detect {|f| params[f[0]].blank? }
59+
errors << [:base, 'You must specify your GitHub username and password']
4060
end
61+
errors
4162
end
4263

43-
def create_issue(problem, reported_by = nil)
64+
def github_client
4465
# Login using OAuth token, if given.
4566
if oauth_token
46-
client = Octokit::Client.new(:login => username, :oauth_token => oauth_token)
67+
Octokit::Client.new(
68+
:login => params['username'], :oauth_token => oauth_token)
4769
else
48-
client = Octokit::Client.new(:login => username, :password => password)
70+
Octokit::Client.new(
71+
:login => params['username'], :password => params['password'])
4972
end
73+
end
5074

75+
def create_issue(problem, reported_by = nil)
5176
begin
52-
issue = client.create_issue(
77+
issue = github_client.create_issue(
5378
project_id,
54-
issue_title(problem),
55-
body_template.result(binding).unpack('C*').pack('U*')
79+
"[#{ problem.environment }][#{ problem.where }] #{problem.message.to_s.truncate(100)}",
80+
self.class.body_template.result(binding).unpack('C*').pack('U*')
5681
)
5782
@url = issue.html_url
5883
problem.update_attributes(
5984
:issue_link => issue.html_url,
60-
:issue_type => Label
85+
:issue_type => self.class.label
6186
)
6287

6388
rescue Octokit::Unauthorized
6489
raise ErrbitGithubPlugin::AuthenticationError, "Could not authenticate with GitHub. Please check your username and password."
6590
end
6691
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
7192
end
7293
end
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module ErrbitGithubPlugin
2-
VERSION = "0.0.1"
2+
VERSION = "0.1.0"
33
end

views/github_issues_body.txt.erb

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
[See this exception on Errbit](<%= problem.url %> "See this exception on Errbit")
2+
<% if notice = problem.notices.first %>
3+
# <%= notice.message %> #
4+
## Summary ##
5+
<% if notice.request['url'].present? %>
6+
### URL ###
7+
[<%= notice.request['url'] %>](<%= notice.request['url'] %>)"
8+
<% end %>
9+
### Where ###
10+
<%= notice.where %>
11+
12+
### Occured ###
13+
<%= notice.created_at.to_s(:micro) %>
14+
15+
### Similar ###
16+
<%= (notice.problem.notices_count - 1).to_s %>
17+
18+
## Params ##
19+
```
20+
<%= pretty_hash(notice.params) %>
21+
```
22+
23+
## Session ##
24+
```
25+
<%= pretty_hash(notice.session) %>
26+
```
27+
28+
## Backtrace ##
29+
```
30+
<% notice.backtrace_lines.each do |line| %><%= line.number %>: <%= line.file_relative %> -> **<%= line.method %>**
31+
<% end %>
32+
```
33+
34+
## Environment ##
35+
36+
<table>
37+
<% for key, val in notice.env_vars %>
38+
<tr>
39+
<td><%= key %>:</td>
40+
<td><%= val %></td>
41+
</tr>
42+
<% end %>
43+
</table>
44+
<% end %>
45+

0 commit comments

Comments
 (0)