Commit 242f6aa218da6385b08d28705eb42297d899c089

Authored by Andrew8xx8
1 parent 90db28d6

New issue button was not follows to external tracker if it is selected. fixed #3386

app/helpers/issues_helper.rb
@@ -54,6 +54,18 @@ module IssuesHelper @@ -54,6 +54,18 @@ module IssuesHelper
54 end 54 end
55 end 55 end
56 56
  57 + def url_for_new_issue
  58 + return "" if @project.nil?
  59 +
  60 + if @project.used_default_issues_tracker?
  61 + url = new_project_issue_path project_id: @project
  62 + else
  63 + url = Settings[:issues_tracker][@project.issues_tracker]["new_issue_url"]
  64 + url.gsub(':project_id', @project.id.to_s)
  65 + .gsub(':issues_tracker_id', @project.issues_tracker_id.to_s)
  66 + end
  67 + end
  68 +
57 def url_for_issue(issue_id) 69 def url_for_issue(issue_id)
58 return "" if @project.nil? 70 return "" if @project.nil?
59 71
app/views/projects/_clone_panel.html.haml
@@ -13,5 +13,5 @@ @@ -13,5 +13,5 @@
13 = link_to new_project_merge_request_path(@project), title: "New Merge Request", class: "btn-small btn grouped" do 13 = link_to new_project_merge_request_path(@project), title: "New Merge Request", class: "btn-small btn grouped" do
14 Merge Request 14 Merge Request
15 - if @project.issues_enabled && can?(current_user, :write_issue, @project) 15 - if @project.issues_enabled && can?(current_user, :write_issue, @project)
16 - = link_to new_project_issue_path(@project), title: "New Issue", class: "btn-small btn grouped" do 16 + = link_to url_for_new_issue, title: "New Issue", class: "btn-small btn grouped" do
17 Issue 17 Issue
config/gitlab.yml.example
@@ -46,12 +46,19 @@ production: &base @@ -46,12 +46,19 @@ production: &base
46 # ## :project_id - GitLab project identifier 46 # ## :project_id - GitLab project identifier
47 # ## :issues_tracker_id - Project Name or Id in external issue tracker 47 # ## :issues_tracker_id - Project Name or Id in external issue tracker
48 # project_url: "http://redmine.sample/projects/:issues_tracker_id" 48 # project_url: "http://redmine.sample/projects/:issues_tracker_id"
  49 + #
49 # ## If not nil, links from /#\d/ entities from commit messages will replaced with this 50 # ## If not nil, links from /#\d/ entities from commit messages will replaced with this
50 # ## Use placeholders: 51 # ## Use placeholders:
51 # ## :project_id - GitLab project identifier 52 # ## :project_id - GitLab project identifier
52 # ## :issues_tracker_id - Project Name or Id in external issue tracker 53 # ## :issues_tracker_id - Project Name or Id in external issue tracker
53 # ## :id - Issue id (from commit messages) 54 # ## :id - Issue id (from commit messages)
54 # issues_url: "http://redmine.sample/issues/:id" 55 # issues_url: "http://redmine.sample/issues/:id"
  56 + #
  57 + # ## If not nil, linkis to creating new issues will be replaced with this
  58 + # ## Use placeholders:
  59 + # ## :project_id - GitLab project identifier
  60 + # ## :issues_tracker_id - Project Name or Id in external issue tracker
  61 + # new_issue_url: "http://redmine.sample/projects/:issues_tracker_id/issues/new"
55 62
56 ## Gravatar 63 ## Gravatar
57 gravatar: 64 gravatar:
@@ -152,6 +159,7 @@ test: @@ -152,6 +159,7 @@ test:
152 redmine: 159 redmine:
153 project_url: "http://redmine/projects/:issues_tracker_id" 160 project_url: "http://redmine/projects/:issues_tracker_id"
154 issues_url: "http://redmine/:project_id/:issues_tracker_id/:id" 161 issues_url: "http://redmine/:project_id/:issues_tracker_id/:id"
  162 + new_issue_url: "http://redmine/projects/:issues_tracker_id/insues/new"
155 163
156 staging: 164 staging:
157 <<: *base 165 <<: *base
spec/helpers/issues_helper_spec.rb
@@ -76,4 +76,31 @@ describe IssuesHelper do @@ -76,4 +76,31 @@ describe IssuesHelper do
76 url_for_issue(issue.id).should eq "" 76 url_for_issue(issue.id).should eq ""
77 end 77 end
78 end 78 end
  79 +
  80 + describe :url_for_new_issue do
  81 + let(:issues_url) { Gitlab.config.issues_tracker.redmine.new_issue_url}
  82 + let(:ext_expected) do
  83 + issues_url.gsub(':project_id', ext_project.id.to_s)
  84 + .gsub(':issues_tracker_id', ext_project.issues_tracker_id.to_s)
  85 + end
  86 + let(:int_expected) { new_project_issue_path(project) }
  87 +
  88 + it "should return internal path if used internal tracker" do
  89 + @project = project
  90 + url_for_new_issue.should match(int_expected)
  91 + end
  92 +
  93 + it "should return path to external tracker" do
  94 + @project = ext_project
  95 +
  96 + url_for_new_issue.should match(ext_expected)
  97 + end
  98 +
  99 + it "should return empty string if project nil" do
  100 + @project = nil
  101 +
  102 + url_for_new_issue.should eq ""
  103 + end
  104 + end
  105 +
79 end 106 end