Class: ErrbitGithubPlugin::IssueTracker
- Inherits:
-
ErrbitPlugin::IssueTracker
- Object
- ErrbitPlugin::IssueTracker
- ErrbitGithubPlugin::IssueTracker
- Defined in:
- lib/errbit_github_plugin/issue_tracker.rb
Constant Summary collapse
- 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" } }
Class Method Summary collapse
Instance Method Summary collapse
- #close_issue(url, user: {}) ⇒ Object
- #configured? ⇒ Boolean
- #create_issue(title, body, user: {}) ⇒ Object
- #errors ⇒ Object
- #repo ⇒ Object
- #url ⇒ Object
Class Method Details
.fields ⇒ Object
31 32 33 |
# File 'lib/errbit_github_plugin/issue_tracker.rb', line 31 def self.fields FIELDS end |
.icons ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/errbit_github_plugin/issue_tracker.rb', line 35 def self.icons @icons ||= { create: [ 'image/png', ErrbitGithubPlugin.read_static_file('github_create.png') ], goto: [ 'image/png', ErrbitGithubPlugin.read_static_file('github_goto.png'), ], inactive: [ 'image/png', ErrbitGithubPlugin.read_static_file('github_inactive.png'), ] } end |
.label ⇒ Object
23 24 25 |
# File 'lib/errbit_github_plugin/issue_tracker.rb', line 23 def self.label LABEL end |
.note ⇒ Object
27 28 29 |
# File 'lib/errbit_github_plugin/issue_tracker.rb', line 27 def self.note NOTE end |
Instance Method Details
#close_issue(url, user: {}) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/errbit_github_plugin/issue_tracker.rb', line 86 def close_issue(url, user: {}) if user['github_login'] && user['github_oauth_token'] github_client = Octokit::Client.new( login: user['github_login'], access_token: user['github_oauth_token']) else github_client = Octokit::Client.new( login: ['username'], password: ['password']) end # It would be better to get the number from issue.number when we create the issue, # however, since we only have the url, get the number from it. # ex: "https://github.com/octocat/Hello-World/issues/1347" issue_number = url.split("/").last issue = github_client.close_issue(repo, issue_number) issue.html_url rescue Octokit::Unauthorized raise ErrbitGithubPlugin::AuthenticationError, "Could not authenticate with GitHub. Please check your username and password." end |
#configured? ⇒ Boolean
49 50 51 |
# File 'lib/errbit_github_plugin/issue_tracker.rb', line 49 def configured? errors.empty? end |
#create_issue(title, body, user: {}) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/errbit_github_plugin/issue_tracker.rb', line 72 def create_issue(title, body, user: {}) if user['github_login'] && user['github_oauth_token'] github_client = Octokit::Client.new( login: user['github_login'], access_token: user['github_oauth_token']) else github_client = Octokit::Client.new( login: ['username'], password: ['password']) end issue = github_client.create_issue(repo, title, body) issue.html_url rescue Octokit::Unauthorized raise ErrbitGithubPlugin::AuthenticationError, "Could not authenticate with GitHub. Please check your username and password." end |
#errors ⇒ Object
57 58 59 60 61 62 63 64 65 66 |
# File 'lib/errbit_github_plugin/issue_tracker.rb', line 57 def errors errors = [] if self.class.fields.detect {|f| [f[0]].blank? } errors << [:base, 'You must specify your GitHub username and password'] end if repo.blank? errors << [:base, 'You must specify your GitHub repository url.'] end errors end |
#repo ⇒ Object
68 69 70 |
# File 'lib/errbit_github_plugin/issue_tracker.rb', line 68 def repo [:github_repo] end |
#url ⇒ Object
53 54 55 |
# File 'lib/errbit_github_plugin/issue_tracker.rb', line 53 def url "https://github.com/#{repo}/issues" end |