Skip to content

Instantly share code, notes, and snippets.

@leonardoeloy
Created September 26, 2012 12:08
Show Gist options
  • Save leonardoeloy/3787645 to your computer and use it in GitHub Desktop.
Save leonardoeloy/3787645 to your computer and use it in GitHub Desktop.
Create issue from note in Gitlab
--- gitlabhq_original/app/controllers/notes_controller.rb 2012-09-26 08:58:50.000000000 -0300
+++ gitlabhq/app/controllers/notes_controller.rb 2012-09-26 08:35:35.000000000 -0300
@@ -17,6 +17,17 @@
def create
@note = Notes::CreateContext.new(project, current_user, params).execute
+ if not params[:create_issue].nil?
+ issue_params = {
+ :title => params[:note][:note][0..40] + "...",
+ :description => "#{params[:note][:note]} \n\nNote %#{@note.id}",
+ :label_list => params[:label_list]
+ }
+ issue = @project.issues.new(issue_params)
+ issue.author = current_user
+ issue.save
+ end
+
respond_to do |format|
format.html {redirect_to :back}
format.js
--- gitlabhq_original/app/views/notes/_note.html.haml 2012-09-26 08:58:50.000000000 -0300
+++ gitlabhq/app/views/notes/_note.html.haml 2012-09-26 08:19:53.000000000 -0300
@@ -1,6 +1,7 @@
%li{id: dom_id(note), class: "note #{note_vote_class(note)}"}
= image_tag gravatar_icon(note.author.email), class: "avatar s32"
%div.note-author
+ %span= "##{note.id}"
%strong= note.author_name
= link_to "##{dom_id(note)}", name: dom_id(note) do
%cite.cgray
--- gitlabhq_original/app/views/notes/_per_line_form.html.haml 2012-09-26 08:58:50.000000000 -0300
+++ gitlabhq/app/views/notes/_per_line_form.html.haml 2012-09-26 08:12:47.000000000 -0300
@@ -29,7 +29,14 @@
= label_tag :notify_author do
= check_box_tag :notify_author, 1 , @note.noteable_type == "Commit"
%span Commit author
-
+ .options
+ %div
+ %h6.left Issue:
+ .labels
+ = label_tag :issue do
+ = check_box_tag :create_issue, 1
+ %span Create issue
+ = text_field_tag :label_list, "", :placeholder => "Separate with comma"
:javascript
$(function(){
$(".per_line_form .hide-button").bind("click", function(){
--- gitlabhq_original/lib/gitlab/markdown.rb 2012-09-26 08:58:50.000000000 -0300
+++ gitlabhq/lib/gitlab/markdown.rb 2012-09-25 19:01:27.000000000 -0300
@@ -10,6 +10,7 @@
# * !123 for merge requests
# * $123 for snippets
# * 123456 for commits
+ # * %1234:123 for notes within commits
#
# It also parses Emoji codes to insert images. See
# http://www.emoji-cheat-sheet.com/ for a list of the supported icons.
@@ -29,7 +30,7 @@
(\W)? # Prefix (1)
( # Reference (2)
@([\w\._]+) # User name (3)
- |[#!$](\d+) # Issue/MR/Snippet ID (4)
+ |[#%!$](\d+) # Issue/MR/Snippet ID (4)
|([\h]{6,40}) # Commit ID (5)
)
(\W)? # Suffix (6)
@@ -140,6 +141,7 @@
def reference_link(reference, identifier)
case reference
when /^@/ then reference_user(identifier)
+ when /^%/ then reference_note(identifier)
when /^#/ then reference_issue(identifier)
when /^!/ then reference_merge_request(identifier)
when /^\$/ then reference_snippet(identifier)
@@ -160,6 +162,13 @@
end
end
+ def reference_note(identifier)
+ if note = @project.notes.find(identifier)
+ commit = @project.commit(note.noteable_id)
+ link_to("%#{note.id}", "#{project_commit_path(@project, id: commit.id)}#note_#{note.id}", html_options.merge(title: CommitDecorator.new(commit).link_title, class: "gfm gfm-issue #{html_options[:class]}"))
+ end
+ end
+
def reference_merge_request(identifier)
if merge_request = @project.merge_requests.where(id: identifier).first
link_to("!#{identifier}", project_merge_request_path(@project, merge_request), html_options.merge(title: "Merge Request: #{merge_request.title}", class: "gfm gfm-merge_request #{html_options[:class]}"))
@leonardoeloy
Copy link
Author

Usage:

$ cd gitlabhq/
$ patch -p1 < create_issue_from_note_gitlab.patch 

@leonardoeloy
Copy link
Author

This patch works fine for GitLab 3.0 as of today.

@davrodpin
Copy link

This patch works fine for GitLab 3.1 as of today.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment