From 84e406c8c4f3db3a10769f5b09d644d9c2c12e2a Mon Sep 17 00:00:00 2001 From: Arthur Neves Date: Tue, 23 Dec 2014 18:09:28 -0500 Subject: [PATCH] Replace issue creation interactor with Issue model --- app/controllers/problems_controller.rb | 7 ++++--- app/interactors/issue_creation.rb | 55 ------------------------------------------------------- app/models/issue.rb | 24 ++++++++++++++++++++++++ 3 files changed, 28 insertions(+), 58 deletions(-) delete mode 100644 app/interactors/issue_creation.rb create mode 100644 app/models/issue.rb diff --git a/app/controllers/problems_controller.rb b/app/controllers/problems_controller.rb index 5a61abd..a5054c4 100644 --- a/app/controllers/problems_controller.rb +++ b/app/controllers/problems_controller.rb @@ -62,9 +62,10 @@ class ProblemsController < ApplicationController end def create_issue - issue_creation = IssueCreation.new(problem, current_user, params[:tracker], request) - - unless issue_creation.execute + body = "" # TODO render_issue_body + title = "" # TODO generate_title + issue = Issue.new(problem: problem, user: current_user, title: title, body: body) + unless issue.save flash[:error] = issue_creation.errors.full_messages.join(', ') end diff --git a/app/interactors/issue_creation.rb b/app/interactors/issue_creation.rb deleted file mode 100644 index 880524d..0000000 --- a/app/interactors/issue_creation.rb +++ /dev/null @@ -1,55 +0,0 @@ -class IssueCreation - include ActiveModel::Validations - - attr_reader :problem, :user, :tracker_name - - delegate :app, :to => :problem - - def initialize(problem, user, tracker_name, request) - @problem = problem - @user = user - @tracker_name = tracker_name - IssueTracker.update_url_options(request) - end - - def execute - tracker.create_issue(problem, user) if tracker - errors.empty? - rescue => ex - Rails.logger.error "Error during issue creation: " << ex.message - errors.add :base, "There was an error during issue creation: #{ex.message}" - false - end - - private - - def tracker - return @tracker if @tracker - - # Create an issue on GitHub using user's github token - if tracker_name == 'user_github' - if !app.github_repo? - errors.add :base, "This app doesn't have a GitHub repo set up." - elsif !user.github_account? - errors.add :base, "You haven't linked your Github account." - else - @tracker = ErrbitGithubPlugin::IssueTracker.new( - app, { - :username => user.github_login, - :oauth_token => user.github_oauth_token - } - ) - end - - # Or, create an issue using the App's issue tracker - elsif app.issue_tracker_configured? - @tracker = app.issue_tracker - - # Otherwise, display error about missing tracker configuration. - else - errors.add :base, "This app has no issue tracker setup." - end - - @tracker - end -end diff --git a/app/models/issue.rb b/app/models/issue.rb new file mode 100644 index 0000000..8a3c281 --- /dev/null +++ b/app/models/issue.rb @@ -0,0 +1,24 @@ +class Issue + include ActiveModel::Model + attr_accessor :problem, :user, :title, :body + + def intialize(problem: nil, user: nil, title: nil, body: nil) + @problem, @user, @title, @body = problem, user, title, body + end + + def save + if tracker + tracker.create_issue(title, body, user.as_document) + else + errors.add :base, "This app has no issue tracker setup." + end + errors.empty? + rescue => ex + errors.add :base, "There was an error during issue creation: #{ex.message}" + false + end + + def tracker + problem.app.issue_tracker + end +end -- libgit2 0.21.2