diff --git a/app/assets/stylesheets/errbit.css b/app/assets/stylesheets/errbit.css
index bc6cfb2..cf384dd 100644
--- a/app/assets/stylesheets/errbit.css
+++ b/app/assets/stylesheets/errbit.css
@@ -162,10 +162,10 @@ a.action { float: right; font-size: 0.9em;}
/* Content Title and Comments */
#content-title, #content-comments {
- padding: 30px 20px;
+ padding: 43px 24px 37px;
border-top: 1px solid #FFF;
border-bottom: 1px solid #FFF;
- background-color: #ececec;
+ background-color: #f2f2f2;
}
#content-comments {
background-color: #ffffff;
@@ -188,11 +188,13 @@ a.action { float: right; font-size: 0.9em;}
/* Action Bar */
#action-bar {
position: absolute;
- top: 25px; right: 20px;
+ text-align: right;
+ top: 22px; right: 24px;
}
#action-bar span {
display: inline-block;
margin-left: 18px;
+ margin-bottom: 16px;
text-decoration: none;
color: #666;
background: #FFF url(images/button-bg.png) 0 bottom repeat-x;
@@ -667,10 +669,11 @@ table.tally tbody tr:first-child th {
padding-top:0;
}
table.tally td.percent {
- width:4.5em;
+ padding-right: 10px;
}
table.tally th.value {
- text-transform:none;
+ width: 100%;
+ text-transform: none;
}
/* Deploys table */
diff --git a/app/controllers/errs_controller.rb b/app/controllers/errs_controller.rb
index 94c241e..8ec08fc 100644
--- a/app/controllers/errs_controller.rb
+++ b/app/controllers/errs_controller.rb
@@ -5,6 +5,7 @@ class ErrsController < ApplicationController
before_filter :find_problem, :except => [:index, :all, :destroy_several, :resolve_several, :unresolve_several, :merge_several, :unmerge_several]
before_filter :find_selected_problems, :only => [:destroy_several, :resolve_several, :unresolve_several, :merge_several, :unmerge_several]
before_filter :set_sorting_params, :only => [:index, :all]
+ before_filter :set_tracker_params, :only => [:create_issue]
def index
app_scope = current_user.admin? ? App.all : current_user.apps
@@ -36,21 +37,38 @@ class ErrsController < ApplicationController
end
def create_issue
- set_tracker_params
+ # Create an issue on GitHub using user's github token
+ if params[:tracker] == 'user_github'
+ if !@app.github_repo?
+ flash[:error] = "This app doesn't have a GitHub repo set up."
+ elsif !current_user.github_account?
+ flash[:error] = "You haven't linked your Github account."
+ else
+ @tracker = GithubIssuesTracker.new(
+ :app => @app,
+ :login => current_user.github_login,
+ :oauth_token => current_user.github_oauth_token
+ )
+ end
+
+ # Or, create an issue using the App's issue tracker
+ elsif @app.issue_tracker_configured?
+ @tracker = @app.issue_tracker
- if @app.issue_tracker
+ # Otherwise, display error about missing tracker configuration.
+ else
+ flash[:error] = "This app has no issue tracker setup."
+ end
+
+ if flash[:error].blank? && @tracker
begin
- @app.issue_tracker.create_issue @problem, current_user
+ @tracker.create_issue @problem, current_user
rescue Exception => ex
- flash[:error] = ex.message
+ Rails.logger.error "Error during issue creation: " << ex.message
+ flash[:error] = "There was an error during issue creation: #{ex.message}"
end
- else
- flash[:error] = "This app has no issue tracker setup."
end
- redirect_to app_err_path(@app, @problem)
- rescue ActiveResource::ConnectionError => e
- Rails.logger.error e.to_s
- flash[:error] = "There was an error during issue creation. Check your tracker settings or try again later."
+
redirect_to app_err_path(@app, @problem)
end
diff --git a/app/models/issue_trackers/github_issues_tracker.rb b/app/models/issue_trackers/github_issues_tracker.rb
index 7852e92..4dedcc5 100644
--- a/app/models/issue_trackers/github_issues_tracker.rb
+++ b/app/models/issue_trackers/github_issues_tracker.rb
@@ -1,10 +1,10 @@
class IssueTrackers::GithubIssuesTracker < IssueTracker
Label = "github"
+ Note = 'Please configure your github repository in the GITHUB REPO field above.
' <<
+ '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 = [
- [:project_id, {
- :label => "Account/Repository",
- :placeholder => "errbit/errbit from https://github.com/errbit/errbit"
- }],
[:username, {
:placeholder => "Your username on GitHub"
}],
@@ -13,6 +13,8 @@ class IssueTrackers::GithubIssuesTracker < IssueTracker
}]
]
+ attr_accessor :oauth_token
+
def check_params
if Fields.detect {|f| self[f[0]].blank? }
errors.add :base, 'You must specify your GitHub repository, username and password'
@@ -20,9 +22,15 @@ class IssueTrackers::GithubIssuesTracker < IssueTracker
end
def create_issue(problem, reported_by = nil)
- client = Octokit::Client.new(:login => username, :password => password)
+ # Login using OAuth token, if given.
+ if oauth_token
+ client = Octokit::Client.new(:login => username, :oauth_token => oauth_token)
+ else
+ client = Octokit::Client.new(:login => username, :password => password)
+ end
+
begin
- issue = client.create_issue(project_id, issue_title(problem), body_template.result(binding).unpack('C*').pack('U*'), options = {})
+ issue = client.create_issue(app.github_repo, issue_title(problem), body_template.result(binding).unpack('C*').pack('U*'), options = {})
problem.update_attribute :issue_link, issue.html_url
rescue Octokit::Unauthorized
raise IssueTrackers::AuthenticationError, "Could not authenticate with GitHub. Please check your username and password."
@@ -34,6 +42,6 @@ class IssueTrackers::GithubIssuesTracker < IssueTracker
end
def url
- "https://github.com/#{project_id}/issues"
+ "https://github.com/#{app.github_repo}/issues"
end
end
diff --git a/app/models/issue_trackers/mingle_tracker.rb b/app/models/issue_trackers/mingle_tracker.rb
index 11426f6..597948c 100644
--- a/app/models/issue_trackers/mingle_tracker.rb
+++ b/app/models/issue_trackers/mingle_tracker.rb
@@ -1,5 +1,7 @@
class IssueTrackers::MingleTracker < IssueTracker
Label = "mingle"
+ Note = "Note: CARD PROPERTIES must be comma separated key = value pairs"
+
Fields = [
[:account, {
:label => "Mingle URL",
@@ -9,7 +11,7 @@ class IssueTrackers::MingleTracker < IssueTracker
:placeholder => "Mingle project"
}],
[:ticket_properties, {
- :label => "Card Properties (comma separated key=value pairs)",
+ :label => "Card Properties",
:placeholder => "card_type = Defect, defect_status = Open, priority = Essential"
}],
[:username, {
diff --git a/app/models/user.rb b/app/models/user.rb
index a3b3222..c1611b2 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -44,6 +44,10 @@ class User
github_login.present? ? false : super
end
+ def github_account?
+ github_login.present? && github_oauth_token.present?
+ end
+
protected
def destroy_watchers
diff --git a/app/views/apps/_issue_tracker_fields.html.haml b/app/views/apps/_issue_tracker_fields.html.haml
index c80cbe1..ec9006d 100644
--- a/app/views/apps/_issue_tracker_fields.html.haml
+++ b/app/views/apps/_issue_tracker_fields.html.haml
@@ -15,6 +15,8 @@
%p When no issue tracker has been configured, you will be able to leave comments on errors.
- IssueTracker.subclasses.each do |tracker|
%div.tracker_params{:class => (w.object.is_a?(tracker) ? 'chosen ' : '') << tracker::Label}
+ - if defined?(tracker::Note)
+ %p= tracker::Note.html_safe
- tracker::Fields.each do |field, field_info|
= w.label field, field_info[:label] || field.to_s.titleize
- field_type = field == :password ? :password_field : :text_field
diff --git a/app/views/errs/_issue_tracker_links.html.haml b/app/views/errs/_issue_tracker_links.html.haml
new file mode 100644
index 0000000..7c6e6f2
--- /dev/null
+++ b/app/views/errs/_issue_tracker_links.html.haml
@@ -0,0 +1,12 @@
+- if @app.issue_tracker_configured? || current_user.github_account?
+ - if @problem.issue_link.present?
+ %span= link_to 'go to issue', @problem.issue_link, :class => "#{@app.issue_tracker.class::Label}_goto goto-issue"
+ = link_to 'unlink issue', unlink_issue_app_err_path(@app, @problem), :method => :delete, :confirm => "Unlink err issues?", :class => "unlink-issue"
+ - elsif @problem.issue_link == "pending"
+ %span.disabled= link_to 'creating...', '#', :class => "#{@app.issue_tracker.class::Label}_inactive create-issue"
+ = link_to 'retry', create_issue_app_err_path(@app, @problem), :method => :post
+ - else
+ - if current_user.github_account? && @app.github_repo?
+ %span= link_to 'create issue', create_issue_app_err_path(@app, @problem, :tracker => 'user_github'), :method => :post, :class => "github_create create-issue"
+ - if @app.issue_tracker_configured? && !@app.issue_tracker.is_a?(GithubIssuesTracker)
+ %span= link_to 'create issue', create_issue_app_err_path(@app, @problem), :method => :post, :class => "#{@app.issue_tracker.class::Label}_create create-issue"
diff --git a/app/views/errs/show.html.haml b/app/views/errs/show.html.haml
index 17a7cdd..0917d31 100644
--- a/app/views/errs/show.html.haml
+++ b/app/views/errs/show.html.haml
@@ -1,5 +1,5 @@
- content_for :page_title, @problem.message
-- content_for :title, @problem.error_class
+- content_for :title, @problem.error_class || truncate(@problem.message, :length => 32)
- content_for :meta do
%strong App:
= link_to @app.name, app_path(@app)
@@ -11,20 +11,13 @@
%strong Last Notice:
= last_notice_at(@problem).to_s(:precise)
- content_for :action_bar do
- - if current_user.authentication_token
- %span= link_to 'iCal', app_err_path(:app_id => @app.id, :id => @problem.id, :format => "ics", :auth_token => current_user.authentication_token), :class => "calendar_link"
- - if @problem.app.issue_tracker_configured?
- - if @problem.issue_link.blank?
- %span= link_to 'create issue', create_issue_app_err_path(@app, @problem), :method => :post, :class => "#{@app.issue_tracker.class::Label}_create create-issue"
- - elsif @problem.issue_link == "pending"
- %span.disabled= link_to 'creating...', '#', :class => "#{@app.issue_tracker.class::Label}_inactive create-issue"
- = link_to 'retry', create_issue_app_err_path(@app, @problem), :method => :post
- - else
- %span= link_to 'go to issue', @problem.issue_link, :class => "#{@app.issue_tracker.class::Label}_goto goto-issue"
- = link_to 'unlink issue', unlink_issue_app_err_path(@app, @problem), :method => :delete, :confirm => "Unlink err issues?", :class => "unlink-issue"
- if @problem.unresolved?
%span= link_to 'resolve', resolve_app_err_path(@app, @problem), :method => :put, :confirm => err_confirm, :class => 'resolve'
- %span= link_to 'up', (request.env['HTTP_REFERER'] ? :back : app_errs_path(@app)), :class => 'up'
+ - if current_user.authentication_token
+ %span= link_to 'iCal', app_err_path(:app_id => @app.id, :id => @problem.id, :format => "ics", :auth_token => current_user.authentication_token), :class => "calendar_link"
+ %span>= link_to 'up', (request.env['HTTP_REFERER'] ? :back : app_errs_path(@app)), :class => 'up'
+ %br
+ = render :partial => "issue_tracker_links"
- if Errbit::Config.allow_comments_with_issue_tracker || !@app.issue_tracker_configured? || @problem.comments.any?
- content_for :comments do
diff --git a/app/views/shared/_link_github_account.html.haml b/app/views/shared/_link_github_account.html.haml
index 704e273..65c0272 100644
--- a/app/views/shared/_link_github_account.html.haml
+++ b/app/views/shared/_link_github_account.html.haml
@@ -1,5 +1,5 @@
- if Errbit::Config.github_authentication && user == current_user
- - if user.github_login && user.github_oauth_token
+ - if user.github_account?
%span.unlink_github= link_to "Unlink GitHub account", unlink_github_user_path(user), :method => :delete, :confirm => "Are you sure?"
- else
%span.github= link_to "Link GitHub account", user_omniauth_authorize_path(:github)
diff --git a/spec/controllers/errs_controller_spec.rb b/spec/controllers/errs_controller_spec.rb
index c424919..61dfe5c 100644
--- a/spec/controllers/errs_controller_spec.rb
+++ b/spec/controllers/errs_controller_spec.rb
@@ -330,7 +330,7 @@ describe ErrsController do
end
it "should notify of connection error" do
- flash[:error].should == "There was an error during issue creation. Check your tracker settings or try again later."
+ flash[:error].should include("There was an error during issue creation:")
end
end
end
diff --git a/spec/models/issue_trackers/github_issues_tracker_spec.rb b/spec/models/issue_trackers/github_issues_tracker_spec.rb
index 28a73c4..6221d77 100644
--- a/spec/models/issue_trackers/github_issues_tracker_spec.rb
+++ b/spec/models/issue_trackers/github_issues_tracker_spec.rb
@@ -2,12 +2,14 @@ require 'spec_helper'
describe IssueTrackers::GithubIssuesTracker do
it "should create an issue on GitHub Issues with problem params, and set issue link for problem" do
+ repo = "test_user/test_repo"
notice = Fabricate :notice
+ notice.app.github_repo = repo
tracker = Fabricate :github_issues_tracker, :app => notice.app
problem = notice.problem
number = 5
- @issue_link = "https://github.com/#{tracker.project_id}/issues/#{number}"
+ @issue_link = "https://github.com/#{repo}/issues/#{number}"
body = < 201, :headers => {'Location' => @issue_link}, :body => body )
problem.app.issue_tracker.create_issue(problem)
problem.reload
- requested = have_requested(:post, "https://#{tracker.username}:#{tracker.password}@api.github.com/repos/#{tracker.project_id}/issues")
+ requested = have_requested(:post, "https://#{tracker.username}:#{tracker.password}@api.github.com/repos/#{repo}/issues")
WebMock.should requested.with(:body => /[production][foo#bar] FooError: Too Much Bar/)
WebMock.should requested.with(:body => /See this exception on Errbit/)
diff --git a/spec/views/errs/show.html.haml_spec.rb b/spec/views/errs/show.html.haml_spec.rb
index 0ffd99a..a2b9da5 100644
--- a/spec/views/errs/show.html.haml_spec.rb
+++ b/spec/views/errs/show.html.haml_spec.rb
@@ -56,6 +56,19 @@ describe "errs/show.html.haml" do
action_bar.should have_selector("span a.up[href='#{app_errs_path(problem.app)}']", :text => 'up')
end
+ context 'create issue links' do
+ it 'should allow creating issue for github if current user has linked their github account' do
+ user = Fabricate(:user, :github_login => 'test_user', :github_oauth_token => 'abcdef')
+ controller.stub(:current_user) { user }
+
+ problem = Fabricate(:problem_with_comments, :app => Fabricate(:app, :github_repo => "test_user/test_repo"))
+ assign :problem, problem
+ assign :app, problem.app
+ render
+
+ action_bar.should have_selector("span a.github_create.create-issue", :text => 'create issue')
+ end
+ end
end
describe "content_for :comments with comments disabled for configured issue tracker" do
--
libgit2 0.21.2