Skip to content
Snippets Groups Projects
Unverified Commit 5b322f02 authored by Zeger-Jan van de Weg's avatar Zeger-Jan van de Weg Committed by Connor Shea
Browse files

Notes can be used to create a new issue

parent 47e67f3c
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -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) }
Loading
Loading
Loading
Loading
@@ -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
Loading
Loading
@@ -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"
Loading
Loading
Loading
Loading
@@ -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
 
Loading
Loading
@@ -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]
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment