diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/assets/javascripts/vue_merge_request_widget/components/mr_widget_pipeline.vue | 5 | ||||
-rw-r--r-- | app/services/git/base_hooks_service.rb | 9 | ||||
-rw-r--r-- | app/services/git/branch_push_service.rb | 7 | ||||
-rw-r--r-- | app/services/system_note_service.rb | 90 | ||||
-rw-r--r-- | app/services/system_notes/base_service.rb | 30 | ||||
-rw-r--r-- | app/services/system_notes/commit_service.rb | 112 | ||||
-rw-r--r-- | app/workers/post_receive.rb | 11 |
7 files changed, 159 insertions, 105 deletions
diff --git a/app/assets/javascripts/vue_merge_request_widget/components/mr_widget_pipeline.vue b/app/assets/javascripts/vue_merge_request_widget/components/mr_widget_pipeline.vue index ebedd4842c9..7c5f35579b8 100644 --- a/app/assets/javascripts/vue_merge_request_widget/components/mr_widget_pipeline.vue +++ b/app/assets/javascripts/vue_merge_request_widget/components/mr_widget_pipeline.vue @@ -115,7 +115,10 @@ export default { data-qa-selector="merge_request_pipeline_info_content" > {{ pipeline.details.name }} - <gl-link :href="pipeline.path" class="pipeline-id font-weight-normal pipeline-number" + <gl-link + :href="pipeline.path" + class="pipeline-id font-weight-normal pipeline-number" + data-qa-selector="pipeline_link" >#{{ pipeline.id }}</gl-link > {{ pipeline.details.status.label }} diff --git a/app/services/git/base_hooks_service.rb b/app/services/git/base_hooks_service.rb index 35a4d2015fa..0d320e96b2e 100644 --- a/app/services/git/base_hooks_service.rb +++ b/app/services/git/base_hooks_service.rb @@ -15,8 +15,6 @@ module Git # Not a hook, but it needs access to the list of changed commits enqueue_invalidate_cache - update_remote_mirrors - success end @@ -121,13 +119,6 @@ module Git {} end - def update_remote_mirrors - return unless project.has_remote_mirror? - - project.mark_stuck_remote_mirrors_as_failed! - project.update_remote_mirrors - end - def log_pipeline_errors(exception) data = { class: self.class.name, diff --git a/app/services/git/branch_push_service.rb b/app/services/git/branch_push_service.rb index 49c54e42b7c..7adc3320e06 100644 --- a/app/services/git/branch_push_service.rb +++ b/app/services/git/branch_push_service.rb @@ -57,13 +57,6 @@ module Git Ci::StopEnvironmentsService.new(project, current_user).execute(branch_name) end - def update_remote_mirrors - return unless project.has_remote_mirror? - - project.mark_stuck_remote_mirrors_as_failed! - project.update_remote_mirrors - end - def execute_related_hooks BranchHooksService.new(project, current_user, params).execute end diff --git a/app/services/system_note_service.rb b/app/services/system_note_service.rb index c01094bd689..2cc8771bfe8 100644 --- a/app/services/system_note_service.rb +++ b/app/services/system_note_service.rb @@ -16,20 +16,9 @@ module SystemNoteService # existing_commits - Array of Commits added in a previous push # oldrev - Optional String SHA of a previous Commit # - # See new_commit_summary and existing_commit_summary. - # # Returns the created Note object def add_commits(noteable, project, author, new_commits, existing_commits = [], oldrev = nil) - total_count = new_commits.length + existing_commits.length - commits_text = "#{total_count} commit".pluralize(total_count) - - text_parts = ["added #{commits_text}"] - text_parts << commits_list(noteable, new_commits, existing_commits, oldrev) - text_parts << "[Compare with previous version](#{diff_comparison_path(noteable, project, oldrev)})" - - body = text_parts.join("\n\n") - - create_note(NoteSummary.new(noteable, project, author, body, action: 'commit', commit_count: total_count)) + ::SystemNotes::CommitService.new(noteable: noteable, project: project, author: author).add_commits(new_commits, existing_commits, oldrev) end # Called when a commit was tagged @@ -41,10 +30,7 @@ module SystemNoteService # # Returns the created Note object def tag_commit(noteable, project, author, tag_name) - link = url_helpers.project_tag_path(project, id: tag_name) - body = "tagged commit #{noteable.sha} to [`#{tag_name}`](#{link})" - - create_note(NoteSummary.new(noteable, project, author, body, action: 'tag')) + ::SystemNotes::CommitService.new(noteable: noteable, project: project, author: author).tag_commit(tag_name) end # Called when the assignee of a Noteable is changed or removed @@ -497,17 +483,6 @@ module SystemNoteService notes_for_mentioner(mentioner, noteable, notes).exists? end - # Build an Array of lines detailing each commit added in a merge request - # - # new_commits - Array of new Commit objects - # - # Returns an Array of Strings - def new_commit_summary(new_commits) - new_commits.collect do |commit| - content_tag('li', "#{commit.short_id} - #{commit.title}") - end - end - # Called when the status of a Task has changed # # noteable - Noteable object. @@ -637,71 +612,10 @@ module SystemNoteService "#{cross_reference_note_prefix}#{gfm_reference}" end - # Builds a list of existing and new commits according to existing_commits and - # new_commits methods. - # Returns a String wrapped in `ul` and `li` tags. - def commits_list(noteable, new_commits, existing_commits, oldrev) - existing_commit_summary = existing_commit_summary(noteable, existing_commits, oldrev) - new_commit_summary = new_commit_summary(new_commits).join - - content_tag('ul', "#{existing_commit_summary}#{new_commit_summary}".html_safe) - end - - # Build a single line summarizing existing commits being added in a merge - # request - # - # noteable - MergeRequest object - # existing_commits - Array of existing Commit objects - # oldrev - Optional String SHA of a previous Commit - # - # Examples: - # - # "* ea0f8418...2f4426b7 - 24 commits from branch `master`" - # - # "* ea0f8418..4188f0ea - 15 commits from branch `fork:master`" - # - # "* ea0f8418 - 1 commit from branch `feature`" - # - # Returns a newline-terminated String - def existing_commit_summary(noteable, existing_commits, oldrev = nil) - return '' if existing_commits.empty? - - count = existing_commits.size - - commit_ids = if count == 1 - existing_commits.first.short_id - else - if oldrev && !Gitlab::Git.blank_ref?(oldrev) - "#{Commit.truncate_sha(oldrev)}...#{existing_commits.last.short_id}" - else - "#{existing_commits.first.short_id}..#{existing_commits.last.short_id}" - end - end - - commits_text = "#{count} commit".pluralize(count) - - branch = noteable.target_branch - branch = "#{noteable.target_project_namespace}:#{branch}" if noteable.for_fork? - - branch_name = content_tag('code', branch) - content_tag('li', "#{commit_ids} - #{commits_text} from branch #{branch_name}".html_safe) - end - def url_helpers @url_helpers ||= Gitlab::Routing.url_helpers end - def diff_comparison_path(merge_request, project, oldrev) - diff_id = merge_request.merge_request_diff.id - - url_helpers.diffs_project_merge_request_path( - project, - merge_request, - diff_id: diff_id, - start_sha: oldrev - ) - end - def content_tag(*args) ActionController::Base.helpers.content_tag(*args) end diff --git a/app/services/system_notes/base_service.rb b/app/services/system_notes/base_service.rb new file mode 100644 index 00000000000..7341a25b133 --- /dev/null +++ b/app/services/system_notes/base_service.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +module SystemNotes + class BaseService + attr_reader :noteable, :project, :author + + def initialize(noteable: nil, author: nil, project: nil) + @noteable = noteable + @project = project + @author = author + end + + protected + + def create_note(note_summary) + note = Note.create(note_summary.note.merge(system: true)) + note.system_note_metadata = SystemNoteMetadata.new(note_summary.metadata) if note_summary.metadata? + + note + end + + def content_tag(*args) + ActionController::Base.helpers.content_tag(*args) + end + + def url_helpers + @url_helpers ||= Gitlab::Routing.url_helpers + end + end +end diff --git a/app/services/system_notes/commit_service.rb b/app/services/system_notes/commit_service.rb new file mode 100644 index 00000000000..11119956e0f --- /dev/null +++ b/app/services/system_notes/commit_service.rb @@ -0,0 +1,112 @@ +# frozen_string_literal: true + +module SystemNotes + class CommitService < ::SystemNotes::BaseService + # Called when commits are added to a Merge Request + # + # new_commits - Array of Commits added since last push + # existing_commits - Array of Commits added in a previous push + # oldrev - Optional String SHA of a previous Commit + # + # See new_commit_summary and existing_commit_summary. + # + # Returns the created Note object + def add_commits(new_commits, existing_commits = [], oldrev = nil) + total_count = new_commits.length + existing_commits.length + commits_text = "#{total_count} commit".pluralize(total_count) + + text_parts = ["added #{commits_text}"] + text_parts << commits_list(noteable, new_commits, existing_commits, oldrev) + text_parts << "[Compare with previous version](#{diff_comparison_path(noteable, project, oldrev)})" + + body = text_parts.join("\n\n") + + create_note(NoteSummary.new(noteable, project, author, body, action: 'commit', commit_count: total_count)) + end + + # Called when a commit was tagged + # + # tag_name - The created tag name + # + # Returns the created Note object + def tag_commit(tag_name) + link = url_helpers.project_tag_path(project, id: tag_name) + body = "tagged commit #{noteable.sha} to [`#{tag_name}`](#{link})" + + create_note(NoteSummary.new(noteable, project, author, body, action: 'tag')) + end + + # Build an Array of lines detailing each commit added in a merge request + # + # new_commits - Array of new Commit objects + # + # Returns an Array of Strings + def new_commit_summary(new_commits) + new_commits.collect do |commit| + content_tag('li', "#{commit.short_id} - #{commit.title}") + end + end + + private + + # Builds a list of existing and new commits according to existing_commits and + # new_commits methods. + # Returns a String wrapped in `ul` and `li` tags. + def commits_list(noteable, new_commits, existing_commits, oldrev) + existing_commit_summary = existing_commit_summary(noteable, existing_commits, oldrev) + new_commit_summary = new_commit_summary(new_commits).join + + content_tag('ul', "#{existing_commit_summary}#{new_commit_summary}".html_safe) + end + + # Build a single line summarizing existing commits being added in a merge + # request + # + # existing_commits - Array of existing Commit objects + # oldrev - Optional String SHA of a previous Commit + # + # Examples: + # + # "* ea0f8418...2f4426b7 - 24 commits from branch `master`" + # + # "* ea0f8418..4188f0ea - 15 commits from branch `fork:master`" + # + # "* ea0f8418 - 1 commit from branch `feature`" + # + # Returns a newline-terminated String + def existing_commit_summary(noteable, existing_commits, oldrev = nil) + return '' if existing_commits.empty? + + count = existing_commits.size + + commit_ids = if count == 1 + existing_commits.first.short_id + else + if oldrev && !Gitlab::Git.blank_ref?(oldrev) + "#{Commit.truncate_sha(oldrev)}...#{existing_commits.last.short_id}" + else + "#{existing_commits.first.short_id}..#{existing_commits.last.short_id}" + end + end + + commits_text = "#{count} commit".pluralize(count) + + branch = noteable.target_branch + branch = "#{noteable.target_project_namespace}:#{branch}" if noteable.for_fork? + + branch_name = content_tag('code', branch) + content_tag('li', "#{commit_ids} - #{commits_text} from branch #{branch_name}".html_safe) + end + + def diff_comparison_path(merge_request, project, oldrev) + diff_id = merge_request.merge_request_diff.id + + url_helpers.diffs_project_merge_request_path( + project, + merge_request, + diff_id: diff_id, + start_sha: oldrev + ) + end + end +end diff --git a/app/workers/post_receive.rb b/app/workers/post_receive.rb index 63a32083b5d..cae3cb45c45 100644 --- a/app/workers/post_receive.rb +++ b/app/workers/post_receive.rb @@ -70,6 +70,7 @@ class PostReceive refs << ref end + update_remote_mirrors(post_received) after_project_changes_hooks(post_received, user, refs.to_a, changes) end @@ -93,6 +94,16 @@ class PostReceive ) end + def update_remote_mirrors(post_received) + return unless post_received.includes_branches? || post_received.includes_tags? + + project = post_received.project + return unless project.has_remote_mirror? + + project.mark_stuck_remote_mirrors_as_failed! + project.update_remote_mirrors + end + def after_project_changes_hooks(post_received, user, refs, changes) hook_data = Gitlab::DataBuilder::Repository.update(post_received.project, user, changes, refs) SystemHooksService.new.execute_hooks(hook_data, :repository_update_hooks) |