summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZeger-Jan van de Weg <zegerjan@gitlab.com>2016-05-04 20:56:11 +0200
committerConnor Shea <connor.james.shea@gmail.com>2016-06-02 10:38:08 -0600
commit5b322f0276878470f573c84e1f5bb4d27997f522 (patch)
tree1cc0d64248de9c8901572d146a2e1e5e7c350b10
parent47e67f3cc2dc395c887f4e8693ad224876519826 (diff)
downloadgitlab-ce-make_issue_from_line_comment.tar.gz
Notes can be used to create a new issuemake_issue_from_line_comment
-rw-r--r--app/controllers/projects/notes_controller.rb6
-rw-r--r--app/services/notes/create_service.rb19
-rw-r--r--db/schema.rb13
-rw-r--r--spec/services/notes/create_service_spec.rb34
4 files changed, 70 insertions, 2 deletions
diff --git a/app/controllers/projects/notes_controller.rb b/app/controllers/projects/notes_controller.rb
index 40b24d550e0..26fe79e56cb 100644
--- a/app/controllers/projects/notes_controller.rb
+++ b/app/controllers/projects/notes_controller.rb
@@ -20,7 +20,11 @@ class Projects::NotesController < Projects::ApplicationController
end
def create
- @note = Notes::CreateService.new(project, current_user, note_params).execute
+ @note = if params[:new_issue]
+ Notes::CreateService.new(project, current_user, note_params).new_issue
+ else
+ Notes::CreateService.new(project, current_user, note_params).execute
+ end
respond_to do |format|
format.json { render json: note_json(@note) }
diff --git a/app/services/notes/create_service.rb b/app/services/notes/create_service.rb
index 2bb312bb252..25fcac13540 100644
--- a/app/services/notes/create_service.rb
+++ b/app/services/notes/create_service.rb
@@ -13,5 +13,24 @@ module Notes
note
end
+
+ # An issue can be create from a line comment. This issue has the specified format:
+ #
+ #
+ # ## Title here
+ # ---
+ # description should be here
+ #
+ def new_issue
+ lines = params[:note].lines
+ title = lines[0].gsub(/\A.{3}\W*/, '').rstrip
+ description = lines[2..-1].join('\n').strip # lines[1] == '---' and is thus discarded
+
+ issue = Issues::CreateService.new(project, current_user, title: title, description: description).execute
+ return issue unless issue.valid?
+
+ params[:note] = "#{issue.to_reference} was created from this line comment."
+ execute
+ end
end
end
diff --git a/db/schema.rb b/db/schema.rb
index b2af810f600..30b5e9fc92e 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -100,6 +100,19 @@ ActiveRecord::Schema.define(version: 20160530150109) do
add_index "audit_events", ["entity_id", "entity_type"], name: "index_audit_events_on_entity_id_and_entity_type", using: :btree
add_index "audit_events", ["type"], name: "index_audit_events_on_type", using: :btree
+ create_table "award_emoji", force: :cascade do |t|
+ t.string "name"
+ t.integer "user_id"
+ t.integer "awardable_id"
+ t.string "awardable_type"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
+ add_index "award_emoji", ["awardable_id"], name: "index_award_emoji_on_awardable_id", using: :btree
+ add_index "award_emoji", ["awardable_type"], name: "index_award_emoji_on_awardable_type", using: :btree
+ add_index "award_emoji", ["user_id"], name: "index_award_emoji_on_user_id", using: :btree
+
create_table "broadcast_messages", force: :cascade do |t|
t.text "message", null: false
t.datetime "starts_at"
diff --git a/spec/services/notes/create_service_spec.rb b/spec/services/notes/create_service_spec.rb
index ff23f13e1cb..1e59ffa05bf 100644
--- a/spec/services/notes/create_service_spec.rb
+++ b/spec/services/notes/create_service_spec.rb
@@ -14,7 +14,7 @@ describe Notes::CreateService, services: true do
noteable_type: 'Issue',
noteable_id: issue.id
}
-
+
@note = Notes::CreateService.new(project, user, opts).execute
end
@@ -23,6 +23,38 @@ describe Notes::CreateService, services: true do
end
end
+ describe "#new_issue" do
+ let(:content) do
+ <<-NOTE
+ My new title
+ ---
+ This is my body
+ NOTE
+ end
+ let(:merge_request) { create(:merge_request) }
+ let(:params) { {note: content, noteable_type: "MergeRequest", noteable_id: merge_request.id} }
+
+ before do
+ project.team << [user, :master]
+ end
+
+ it "creates a new issue" do
+ expect { Notes::CreateService.new(project, user, params).new_issue }.to change { Issue.count }.by(1)
+ end
+
+ it 'sets a bota a note and a reference' do
+ expect { Notes::CreateService.new(project, user, params).new_issue }.to change { Note.count }.by(2)
+ end
+
+ it "parses the note" do
+ Notes::CreateService.new(project, user, params).new_issue
+ new_issue = Issue.last
+
+ expect(new_issue.title).to eq 'My new title'
+ expect(new_issue.description).to eq 'This is my body'
+ end
+ end
+
describe "award emoji" do
before do
project.team << [user, :master]