Commit 3cebe9e7 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Refactor duplciate code for groups_controller.rb and slack_service/note_message.rb

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 437d4c76
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
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
class DashboardController < Dashboard::ApplicationController class DashboardController < Dashboard::ApplicationController
include IssuesAction
include MergeRequestsAction
before_action :event_filter, only: :activity before_action :event_filter, only: :activity
before_action :projects, only: [:issues, :merge_requests] before_action :projects, only: [:issues, :merge_requests]
respond_to :html 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 def activity
@last_push = current_user.recent_push @last_push = current_user.recent_push
......
class GroupsController < Groups::ApplicationController class GroupsController < Groups::ApplicationController
include IssuesAction
include MergeRequestsAction
skip_before_action :authenticate_user!, only: [:show, :issues, :merge_requests] skip_before_action :authenticate_user!, only: [:show, :issues, :merge_requests]
respond_to :html respond_to :html
before_action :group, except: [:new, :create] before_action :group, except: [:new, :create]
...@@ -53,23 +56,6 @@ class GroupsController < Groups::ApplicationController ...@@ -53,23 +56,6 @@ class GroupsController < Groups::ApplicationController
end end
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 def edit
end end
......
...@@ -46,7 +46,7 @@ module GitlabMarkdownHelper ...@@ -46,7 +46,7 @@ module GitlabMarkdownHelper
end end
def markdown(text, context = {}) def markdown(text, context = {})
process_markdown(text, options) process_markdown(text, context)
end end
# TODO (rspeicher): Remove all usages of this helper and just call `markdown` # TODO (rspeicher): Remove all usages of this helper and just call `markdown`
......
...@@ -45,30 +45,27 @@ class SlackService ...@@ -45,30 +45,27 @@ class SlackService
def create_commit_note(commit) def create_commit_note(commit)
commit_sha = commit[:id] commit_sha = commit[:id]
commit_sha = Commit.truncate_sha(commit_sha) commit_sha = Commit.truncate_sha(commit_sha)
commit_link = "[commit #{commit_sha}](#{@note_url})" commented_on_message(
title = format_title(commit[:message]) "[commit #{commit_sha}](#{@note_url})",
@message = "#{@user_name} commented on #{commit_link} in #{project_link}: *#{title}*" format_title(commit[:message]))
end end
def create_issue_note(issue) def create_issue_note(issue)
issue_iid = issue[:iid] commented_on_message(
note_link = "[issue ##{issue_iid}](#{@note_url})" "[issue ##{issue[:iid]}](#{@note_url})",
title = format_title(issue[:title]) format_title(issue[:title]))
@message = "#{@user_name} commented on #{note_link} in #{project_link}: *#{title}*"
end end
def create_merge_note(merge_request) def create_merge_note(merge_request)
merge_request_id = merge_request[:iid] commented_on_message(
merge_request_link = "[merge request ##{merge_request_id}](#{@note_url})" "[merge request ##{merge_request[:iid]}](#{@note_url})",
title = format_title(merge_request[:title]) format_title(merge_request[:title]))
@message = "#{@user_name} commented on #{merge_request_link} in #{project_link}: *#{title}*"
end end
def create_snippet_note(snippet) def create_snippet_note(snippet)
snippet_id = snippet[:id] commented_on_message(
snippet_link = "[snippet ##{snippet_id}](#{@note_url})" "[snippet ##{snippet[:id]}](#{@note_url})",
title = format_title(snippet[:title]) format_title(snippet[:title]))
@message = "#{@user_name} commented on #{snippet_link} in #{project_link}: *#{title}*"
end end
def description_message def description_message
...@@ -78,5 +75,9 @@ class SlackService ...@@ -78,5 +75,9 @@ class SlackService
def project_link def project_link
"[#{@project_name}](#{@project_url})" "[#{@project_name}](#{@project_url})"
end end
def commented_on_message(target_link, title)
@message = "#{@user_name} commented on #{target_link} in #{project_link}: *#{title}*"
end
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment