summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2015-11-17 11:03:18 +0100
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2015-11-17 11:03:18 +0100
commit3cebe9e78064030553e62939ec3612993c63ad76 (patch)
tree68c82b2082315b554cb3c49b47665f12ed85df46
parent437d4c76ece4bdf89e3702b05d13027a9a6f63a1 (diff)
downloadgitlab-ce-3cebe9e78064030553e62939ec3612993c63ad76.tar.gz
Refactor duplciate code for groups_controller.rb and slack_service/note_message.rb
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
-rw-r--r--app/controllers/concerns/issues_action.rb14
-rw-r--r--app/controllers/concerns/merge_requests_action.rb9
-rw-r--r--app/controllers/dashboard_controller.rb20
-rw-r--r--app/controllers/groups_controller.rb20
-rw-r--r--app/helpers/gitlab_markdown_helper.rb2
-rw-r--r--app/models/project_services/slack_service/note_message.rb31
6 files changed, 46 insertions, 50 deletions
diff --git a/app/controllers/concerns/issues_action.rb b/app/controllers/concerns/issues_action.rb
new file mode 100644
index 00000000000..effd4721949
--- /dev/null
+++ b/app/controllers/concerns/issues_action.rb
@@ -0,0 +1,14 @@
+module IssuesAction
+ extend ActiveSupport::Concern
+
+ def issues
+ @issues = get_issues_collection
+ @issues = @issues.page(params[:page]).per(ApplicationController::PER_PAGE)
+ @issues = @issues.preload(:author, :project)
+
+ respond_to do |format|
+ format.html
+ format.atom { render layout: false }
+ end
+ end
+end
diff --git a/app/controllers/concerns/merge_requests_action.rb b/app/controllers/concerns/merge_requests_action.rb
new file mode 100644
index 00000000000..f7a25111db9
--- /dev/null
+++ b/app/controllers/concerns/merge_requests_action.rb
@@ -0,0 +1,9 @@
+module MergeRequestsAction
+ extend ActiveSupport::Concern
+
+ def merge_requests
+ @merge_requests = get_merge_requests_collection
+ @merge_requests = @merge_requests.page(params[:page]).per(ApplicationController::PER_PAGE)
+ @merge_requests = @merge_requests.preload(:author, :target_project)
+ end
+end
diff --git a/app/controllers/dashboard_controller.rb b/app/controllers/dashboard_controller.rb
index b2c1fa4230c..087da935087 100644
--- a/app/controllers/dashboard_controller.rb
+++ b/app/controllers/dashboard_controller.rb
@@ -1,26 +1,12 @@
class DashboardController < Dashboard::ApplicationController
+ include IssuesAction
+ include MergeRequestsAction
+
before_action :event_filter, only: :activity
before_action :projects, only: [:issues, :merge_requests]
respond_to :html
- def merge_requests
- @merge_requests = get_merge_requests_collection
- @merge_requests = @merge_requests.page(params[:page]).per(PER_PAGE)
- @merge_requests = @merge_requests.preload(:author, :target_project)
- end
-
- def issues
- @issues = get_issues_collection
- @issues = @issues.page(params[:page]).per(PER_PAGE)
- @issues = @issues.preload(:author, :project)
-
- respond_to do |format|
- format.html
- format.atom { render layout: false }
- end
- end
-
def activity
@last_push = current_user.recent_push
diff --git a/app/controllers/groups_controller.rb b/app/controllers/groups_controller.rb
index fb4eb094f27..fb26a4e6fc3 100644
--- a/app/controllers/groups_controller.rb
+++ b/app/controllers/groups_controller.rb
@@ -1,4 +1,7 @@
class GroupsController < Groups::ApplicationController
+ include IssuesAction
+ include MergeRequestsAction
+
skip_before_action :authenticate_user!, only: [:show, :issues, :merge_requests]
respond_to :html
before_action :group, except: [:new, :create]
@@ -53,23 +56,6 @@ class GroupsController < Groups::ApplicationController
end
end
- def merge_requests
- @merge_requests = get_merge_requests_collection
- @merge_requests = @merge_requests.page(params[:page]).per(PER_PAGE)
- @merge_requests = @merge_requests.preload(:author, :target_project)
- end
-
- def issues
- @issues = get_issues_collection
- @issues = @issues.page(params[:page]).per(PER_PAGE)
- @issues = @issues.preload(:author, :project)
-
- respond_to do |format|
- format.html
- format.atom { render layout: false }
- end
- end
-
def edit
end
diff --git a/app/helpers/gitlab_markdown_helper.rb b/app/helpers/gitlab_markdown_helper.rb
index a0f6b80e9eb..98c6d9d5d2e 100644
--- a/app/helpers/gitlab_markdown_helper.rb
+++ b/app/helpers/gitlab_markdown_helper.rb
@@ -46,7 +46,7 @@ module GitlabMarkdownHelper
end
def markdown(text, context = {})
- process_markdown(text, options)
+ process_markdown(text, context)
end
# TODO (rspeicher): Remove all usages of this helper and just call `markdown`
diff --git a/app/models/project_services/slack_service/note_message.rb b/app/models/project_services/slack_service/note_message.rb
index 074478b292d..b15d9a14677 100644
--- a/app/models/project_services/slack_service/note_message.rb
+++ b/app/models/project_services/slack_service/note_message.rb
@@ -45,30 +45,27 @@ class SlackService
def create_commit_note(commit)
commit_sha = commit[:id]
commit_sha = Commit.truncate_sha(commit_sha)
- commit_link = "[commit #{commit_sha}](#{@note_url})"
- title = format_title(commit[:message])
- @message = "#{@user_name} commented on #{commit_link} in #{project_link}: *#{title}*"
+ commented_on_message(
+ "[commit #{commit_sha}](#{@note_url})",
+ format_title(commit[:message]))
end
def create_issue_note(issue)
- issue_iid = issue[:iid]
- note_link = "[issue ##{issue_iid}](#{@note_url})"
- title = format_title(issue[:title])
- @message = "#{@user_name} commented on #{note_link} in #{project_link}: *#{title}*"
+ commented_on_message(
+ "[issue ##{issue[:iid]}](#{@note_url})",
+ format_title(issue[:title]))
end
def create_merge_note(merge_request)
- merge_request_id = merge_request[:iid]
- merge_request_link = "[merge request ##{merge_request_id}](#{@note_url})"
- title = format_title(merge_request[:title])
- @message = "#{@user_name} commented on #{merge_request_link} in #{project_link}: *#{title}*"
+ commented_on_message(
+ "[merge request ##{merge_request[:iid]}](#{@note_url})",
+ format_title(merge_request[:title]))
end
def create_snippet_note(snippet)
- snippet_id = snippet[:id]
- snippet_link = "[snippet ##{snippet_id}](#{@note_url})"
- title = format_title(snippet[:title])
- @message = "#{@user_name} commented on #{snippet_link} in #{project_link}: *#{title}*"
+ commented_on_message(
+ "[snippet ##{snippet[:id]}](#{@note_url})",
+ format_title(snippet[:title]))
end
def description_message
@@ -78,5 +75,9 @@ class SlackService
def project_link
"[#{@project_name}](#{@project_url})"
end
+
+ def commented_on_message(target_link, title)
+ @message = "#{@user_name} commented on #{target_link} in #{project_link}: *#{title}*"
+ end
end
end