summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOswaldo Ferreira <oswaldo@gitlab.com>2019-01-23 12:42:26 -0200
committerOswaldo Ferreira <oswaldo@gitlab.com>2019-01-25 11:30:44 -0200
commit1b93b3b640c6dd6377bdddb8beb77f7c3d0da3fc (patch)
tree48826d924b61eb2cae2e3f951ce13cac9efa36d6
parentdc6091876d1c70e25f2153d24dbe04f8b4b875a9 (diff)
downloadgitlab-ce-1b93b3b640c6dd6377bdddb8beb77f7c3d0da3fc.tar.gz
Adjusts suggestions unable to be applied
1. Presents the system error message when available, when applying suggestions 2. Adjusts target branch updates affecting MRs pointing to it when there are previously created suggestions in the MR. We just need to compare the HEAD shas from position and MR source branch.
-rw-r--r--app/assets/javascripts/notes/stores/actions.js11
-rw-r--r--app/services/suggestions/apply_service.rb15
-rw-r--r--changelogs/unreleased/osw-adjusts-suggestions-unable-to-be-applied.yml5
-rw-r--r--spec/services/suggestions/apply_service_spec.rb7
4 files changed, 22 insertions, 16 deletions
diff --git a/app/assets/javascripts/notes/stores/actions.js b/app/assets/javascripts/notes/stores/actions.js
index 65f85314fa0..2105a62cecb 100644
--- a/app/assets/javascripts/notes/stores/actions.js
+++ b/app/assets/javascripts/notes/stores/actions.js
@@ -415,12 +415,13 @@ export const submitSuggestion = (
commit(types.APPLY_SUGGESTION, { discussionId, noteId, suggestionId });
callback();
})
- .catch(() => {
- Flash(
- __('Something went wrong while applying the suggestion. Please try again.'),
- 'alert',
- flashContainer,
+ .catch(err => {
+ const defaultMessage = __(
+ 'Something went wrong while applying the suggestion. Please try again.',
);
+ const flashMessage = err.response.data ? `${err.response.data.message}.` : defaultMessage;
+
+ Flash(__(flashMessage), 'alert', flashContainer);
callback();
});
};
diff --git a/app/services/suggestions/apply_service.rb b/app/services/suggestions/apply_service.rb
index cc47b46b527..1f720fc835f 100644
--- a/app/services/suggestions/apply_service.rb
+++ b/app/services/suggestions/apply_service.rb
@@ -11,7 +11,7 @@ module Suggestions
return error('Suggestion is not appliable')
end
- unless latest_diff_refs?(suggestion)
+ unless latest_source_head?(suggestion)
return error('The file has been changed')
end
@@ -29,12 +29,13 @@ module Suggestions
private
- # Checks whether the latest diff refs for the branch matches with
- # the position refs we're using to update the file content. Since
- # the persisted refs are updated async (for MergeRequest),
- # it's more consistent to fetch this data directly from the repository.
- def latest_diff_refs?(suggestion)
- suggestion.position.diff_refs == suggestion.noteable.repository_diff_refs
+ # Checks whether the latest source branch HEAD matches with
+ # the position HEAD we're using to update the file content. Since
+ # the persisted HEAD is updated async (for MergeRequest),
+ # it's more consistent to fetch this data directly from the
+ # repository.
+ def latest_source_head?(suggestion)
+ suggestion.position.head_sha == suggestion.noteable.source_branch_sha
end
def file_update_params(suggestion)
diff --git a/changelogs/unreleased/osw-adjusts-suggestions-unable-to-be-applied.yml b/changelogs/unreleased/osw-adjusts-suggestions-unable-to-be-applied.yml
new file mode 100644
index 00000000000..3ba62b92413
--- /dev/null
+++ b/changelogs/unreleased/osw-adjusts-suggestions-unable-to-be-applied.yml
@@ -0,0 +1,5 @@
+---
+title: Adjusts suggestions unable to be applied
+merge_request: 24603
+author:
+type: fixed
diff --git a/spec/services/suggestions/apply_service_spec.rb b/spec/services/suggestions/apply_service_spec.rb
index e5ca1c155ed..8e77d582eb4 100644
--- a/spec/services/suggestions/apply_service_spec.rb
+++ b/spec/services/suggestions/apply_service_spec.rb
@@ -134,12 +134,11 @@ describe Suggestions::ApplyService do
end
end
- context 'when diff ref from position is different from repo diff refs' do
+ context 'when HEAD from position is different from source branch HEAD on repo' do
it 'returns error message' do
- outdated_refs = Gitlab::Diff::DiffRefs.new(base_sha: 'foo', start_sha: 'bar', head_sha: 'outdated')
-
allow(suggestion).to receive(:appliable?) { true }
- allow(suggestion.position).to receive(:diff_refs) { outdated_refs }
+ allow(suggestion.position).to receive(:head_sha) { 'old-sha' }
+ allow(suggestion.noteable).to receive(:source_branch_sha) { 'new-sha' }
result = subject.execute(suggestion)