@@ -40,54 +40,41 @@ def self.body_template
4040 ) )
4141 end
4242
43- attr_accessor :oauth_token
44- attr_reader :url
45-
4643 def configured?
47- project_id . present ?
44+ errors . empty ?
4845 end
4946
50- def comments_allowed? ; false ; end
51-
52- def project_id
53- app . github_repo
47+ def url
48+ '' # TODO
5449 end
5550
5651 def errors
5752 errors = [ ]
58- if self . class . fields . detect { |f | params [ f [ 0 ] ] . blank? }
53+ if self . class . fields . detect { |f | options [ f [ 0 ] ] . blank? }
5954 errors << [ :base , 'You must specify your GitHub username and password' ]
6055 end
56+ if repo . blank?
57+ errors << [ :base , 'You must specify your GitHub repository url.' ]
58+ end
6159 errors
6260 end
6361
64- def github_client
65- # Login using OAuth token, if given.
66- if oauth_token
67- Octokit ::Client . new (
68- :login => params [ 'username' ] , :oauth_token => oauth_token )
69- else
70- Octokit ::Client . new (
71- :login => params [ 'username' ] , :password => params [ 'password' ] )
72- end
62+ def repo
63+ options [ :github_repo ]
7364 end
7465
75- def create_issue ( problem , reported_by = nil )
76- begin
77- issue = github_client . create_issue (
78- project_id ,
79- "[#{ problem . environment } ][#{ problem . where } ] #{ problem . message . to_s . truncate ( 100 ) } " ,
80- self . class . body_template . result ( binding ) . unpack ( 'C*' ) . pack ( 'U*' )
81- )
82- @url = issue . html_url
83- problem . update_attributes (
84- :issue_link => issue . html_url ,
85- :issue_type => self . class . label
86- )
87-
88- rescue Octokit ::Unauthorized
89- raise ErrbitGithubPlugin ::AuthenticationError , "Could not authenticate with GitHub. Please check your username and password."
66+ def create_issue ( title , body , user : { } )
67+ if user [ 'github_login' ] && user [ 'github_oauth_token' ]
68+ github_client = Octokit ::Client . new (
69+ login : user [ 'github_login' ] , access_token : user [ 'github_oauth_token' ] )
70+ else
71+ github_client = Octokit ::Client . new (
72+ login : options [ 'username' ] , password : options [ 'password' ] )
9073 end
74+ issue = github_client . create_issue ( repo , title , body )
75+ issue . html_url
76+ rescue Octokit ::Unauthorized
77+ raise ErrbitGithubPlugin ::AuthenticationError , "Could not authenticate with GitHub. Please check your username and password."
9178 end
9279 end
9380end
0 commit comments