33module 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
@@ -35,9 +54,11 @@ def project_id
3554 end
3655
3756 def check_params
38- if Fields . detect { |f | self [ f [ 0 ] ] . blank? }
39- errors . add :base , 'You must specify your GitHub username and password'
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
4364 def create_issue ( problem , reported_by = nil )
@@ -52,21 +73,17 @@ def create_issue(problem, reported_by = nil)
5273 issue = client . create_issue (
5374 project_id ,
5475 issue_title ( problem ) ,
55- body_template . result ( binding ) . unpack ( 'C*' ) . pack ( 'U*' )
76+ self . class . body_template . result ( binding ) . unpack ( 'C*' ) . pack ( 'U*' )
5677 )
5778 @url = issue . html_url
5879 problem . update_attributes (
5980 :issue_link => issue . html_url ,
60- :issue_type => Label
81+ :issue_type => self . class . label
6182 )
6283
6384 rescue Octokit ::Unauthorized
6485 raise ErrbitGithubPlugin ::AuthenticationError , "Could not authenticate with GitHub. Please check your username and password."
6586 end
6687 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
7188 end
7289end
0 commit comments