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: {}) ⇒ String
The URL of the closed issue.
- #configured? ⇒ Boolean
- #create_issue(title, body, user: {}) ⇒ Object
- #errors ⇒ Object
- #repo ⇒ Object
- #url ⇒ Object
Class Method Details
.fields ⇒ Object
33 34 35 |
# File 'lib/errbit_github_plugin/issue_tracker.rb', line 33 def self.fields FIELDS end |
.icons ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/errbit_github_plugin/issue_tracker.rb', line 37 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
25 26 27 |
# File 'lib/errbit_github_plugin/issue_tracker.rb', line 25 def self.label LABEL end |
.note ⇒ Object
29 30 31 |
# File 'lib/errbit_github_plugin/issue_tracker.rb', line 29 def self.note NOTE end |
Instance Method Details
#close_issue(url, user: {}) ⇒ String
Returns The URL of the closed issue.
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/errbit_github_plugin/issue_tracker.rb', line 96 def close_issue(url, user: {}) github_client = if user["github_login"] && user["github_oauth_token"] Octokit::Client.new( login: user["github_login"], access_token: user["github_oauth_token"] ) else 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
51 52 53 |
# File 'lib/errbit_github_plugin/issue_tracker.rb', line 51 def configured? errors.empty? end |
#create_issue(title, body, user: {}) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/errbit_github_plugin/issue_tracker.rb', line 77 def create_issue(title, body, user: {}) github_client = if user["github_login"] && user["github_oauth_token"] Octokit::Client.new( login: user["github_login"], access_token: user["github_oauth_token"] ) else 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
59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/errbit_github_plugin/issue_tracker.rb', line 59 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
73 74 75 |
# File 'lib/errbit_github_plugin/issue_tracker.rb', line 73 def repo [:github_repo] end |
#url ⇒ Object
55 56 57 |
# File 'lib/errbit_github_plugin/issue_tracker.rb', line 55 def url "https://github.com/#{repo}/issues" end |