diff options
author | Rubén Dávila <rdavila84@gmail.com> | 2016-02-14 22:36:30 -0500 |
---|---|---|
committer | Robert Speicher <rspeicher@gmail.com> | 2016-02-19 13:14:54 -0500 |
commit | d34733efc4ac24979587a7ce6ac69db41a2003c3 (patch) | |
tree | 6676c82cdc7736e37a36a9a083851a9c8c097c68 /app/models | |
parent | e8d15f1339b1dac1c97516c320631e04c3e5e4d7 (diff) | |
download | gitlab-ce-d34733efc4ac24979587a7ce6ac69db41a2003c3.tar.gz |
Don't show revert button if commit/MR has already been reverted.
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/commit.rb | 26 | ||||
-rw-r--r-- | app/models/merge_request.rb | 10 |
2 files changed, 30 insertions, 6 deletions
diff --git a/app/models/commit.rb b/app/models/commit.rb index 38bbc24fbfc..628926e4886 100644 --- a/app/models/commit.rb +++ b/app/models/commit.rb @@ -219,14 +219,20 @@ class Commit "revert-#{short_id}" end + def revert_description + if merged_merge_request + "This reverts merge request #{merged_merge_request.to_reference}" + else + "This reverts commit #{sha}" + end + end + def revert_message - description = if merged_merge_request - "This reverts merge request #{merged_merge_request.to_reference}" - else - "This reverts commit #{sha}" - end + "Revert \"#{title}\"" + "\n\n#{revert_description}" + end - "Revert \"#{title}\"" + "\n\n#{description}" + def reverts_commit?(commit) + description.include?(commit.revert_description) end def merge_commit? @@ -239,6 +245,14 @@ class Commit @merged_merge_request = merge_commit? && MergeRequest.find_by(merge_commit_sha: id) end + def has_been_reverted?(current_user = nil, noteable = self) + Gitlab::ReferenceExtractor.lazily do + [self, *noteable.notes].flat_map do |note| + note.all_references(current_user).commits + end + end.any? { |commit_ref| commit_ref.reverts_commit?(self) } + end + private def repo_changes diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb index 8eb201b154d..82d096989cf 100644 --- a/app/models/merge_request.rb +++ b/app/models/merge_request.rb @@ -533,4 +533,14 @@ class MergeRequest < ActiveRecord::Base [diff_base_commit, last_commit] end + + def merge_commit + @merge_commit ||= project.commit(merge_commit_sha) if merge_commit_sha + end + + def has_been_reverted?(current_user = nil) + if merge_commit + merge_commit.has_been_reverted?(current_user, self) + end + end end |