Commit e9b94670 authored by lauraMon's avatar lauraMon

Adds pipeline sha to etag store

* Adds the path to commit mutation
parent 4313ef4a
...@@ -4,6 +4,7 @@ module Mutations ...@@ -4,6 +4,7 @@ module Mutations
module Commits module Commits
class Create < BaseMutation class Create < BaseMutation
include FindsProject include FindsProject
include GitlabRoutingHelper
graphql_name 'CommitCreate' graphql_name 'CommitCreate'
...@@ -29,6 +30,11 @@ module Mutations ...@@ -29,6 +30,11 @@ module Mutations
required: true, required: true,
description: 'Array of action hashes to commit as a batch.' description: 'Array of action hashes to commit as a batch.'
field :commit_pipeline_path,
GraphQL::STRING_TYPE,
null: true,
description: "ETag path for the commit's pipeline."
field :commit, field :commit,
Types::CommitType, Types::CommitType,
null: true, null: true,
...@@ -50,6 +56,7 @@ module Mutations ...@@ -50,6 +56,7 @@ module Mutations
{ {
commit: (project.repository.commit(result[:result]) if result[:status] == :success), commit: (project.repository.commit(result[:result]) if result[:status] == :success),
commit_pipeline_path: graphql_etag_pipeline_sha_path(result[:result]),
errors: Array.wrap(result[:message]) errors: Array.wrap(result[:message])
} }
end end
......
...@@ -364,6 +364,10 @@ module GitlabRoutingHelper ...@@ -364,6 +364,10 @@ module GitlabRoutingHelper
[api_graphql_path, "pipelines/id/#{pipeline.id}"].join(':') [api_graphql_path, "pipelines/id/#{pipeline.id}"].join(':')
end end
def graphql_etag_pipeline_sha_path(sha)
[Gitlab::Routing.url_helpers.api_graphql_path, "pipelines/sha/#{sha}"].join(':')
end
private private
def snippet_query_params(snippet, *args) def snippet_query_params(snippet, *args)
......
...@@ -56,6 +56,10 @@ module Ci ...@@ -56,6 +56,10 @@ module Ci
url_helpers.graphql_etag_pipeline_path(pipeline) url_helpers.graphql_etag_pipeline_path(pipeline)
end end
def graphql_pipeline_sha_path(sha)
url_helpers.graphql_etag_pipeline_sha_path(sha)
end
# Updates ETag caches of a pipeline. # Updates ETag caches of a pipeline.
# #
# This logic resides in a separate method so that EE can more easily extend # This logic resides in a separate method so that EE can more easily extend
...@@ -72,6 +76,7 @@ module Ci ...@@ -72,6 +76,7 @@ module Ci
each_pipelines_merge_request_path(pipeline) do |path| each_pipelines_merge_request_path(pipeline) do |path|
store.touch(path) store.touch(path)
end end
store.touch(graphql_pipeline_sha_path(pipeline.sha))
pipeline.self_with_ancestors_and_descendants.each do |relative_pipeline| pipeline.self_with_ancestors_and_descendants.each do |relative_pipeline|
store.touch(project_pipeline_path(relative_pipeline.project, relative_pipeline)) store.touch(project_pipeline_path(relative_pipeline.project, relative_pipeline))
......
...@@ -834,6 +834,7 @@ Input type: `CommitCreateInput` ...@@ -834,6 +834,7 @@ Input type: `CommitCreateInput`
| ---- | ---- | ----------- | | ---- | ---- | ----------- |
| <a id="mutationcommitcreateclientmutationid"></a>`clientMutationId` | [`String`](#string) | A unique identifier for the client performing the mutation. | | <a id="mutationcommitcreateclientmutationid"></a>`clientMutationId` | [`String`](#string) | A unique identifier for the client performing the mutation. |
| <a id="mutationcommitcreatecommit"></a>`commit` | [`Commit`](#commit) | The commit after mutation. | | <a id="mutationcommitcreatecommit"></a>`commit` | [`Commit`](#commit) | The commit after mutation. |
| <a id="mutationcommitcreatecommitpipelinepath"></a>`commitPipelinePath` | [`String`](#string) | ETag path for the commit's pipeline. |
| <a id="mutationcommitcreateerrors"></a>`errors` | [`[String!]!`](#string) | Errors encountered during execution of the mutation. | | <a id="mutationcommitcreateerrors"></a>`errors` | [`[String!]!`](#string) | Errors encountered during execution of the mutation. |
### `Mutation.configureSast` ### `Mutation.configureSast`
......
...@@ -817,7 +817,7 @@ apollo: { ...@@ -817,7 +817,7 @@ apollo: {
}, },
``` ```
Then, because Etags depend on the request being a `GET` instead of GraphQL's usual `POST`, but our default link library does not support `GET` we need to let our defaut Apollo client know to use a different library. Then, because Etags depend on the request being a `GET` instead of GraphQL's usual `POST`, but our default link library does not support `GET` we need to let our default Apollo client know to use a different library.
```javascript ```javascript
/* componentMountIndex.js */ /* componentMountIndex.js */
......
...@@ -12,6 +12,11 @@ module Gitlab ...@@ -12,6 +12,11 @@ module Gitlab
%r(\Apipelines/id/\d+\z), %r(\Apipelines/id/\d+\z),
'pipelines_graph', 'pipelines_graph',
'continuous_integration' 'continuous_integration'
],
[
%r(\Apipelines/sha/\w+\z),
'ci_editor',
'pipeline_authoring'
] ]
].map(&method(:build_route)).freeze ].map(&method(:build_route)).freeze
......
...@@ -237,7 +237,7 @@ FactoryBot.define do ...@@ -237,7 +237,7 @@ FactoryBot.define do
trait :merged_result_pipeline do trait :merged_result_pipeline do
detached_merge_request_pipeline detached_merge_request_pipeline
sha { 'test-merge-sha'} sha { 'testMergeSha12312' }
ref { merge_request.merge_ref_path } ref { merge_request.merge_ref_path }
source_sha { merge_request.source_branch_sha } source_sha { merge_request.source_branch_sha }
target_sha { merge_request.target_branch_sha } target_sha { merge_request.target_branch_sha }
......
...@@ -279,7 +279,7 @@ FactoryBot.define do ...@@ -279,7 +279,7 @@ FactoryBot.define do
trait :with_merge_request_pipeline do trait :with_merge_request_pipeline do
transient do transient do
merge_sha { 'test-merge-sha' } merge_sha { 'testmergesha123' }
source_sha { source_branch_sha } source_sha { source_branch_sha }
target_sha { target_branch_sha } target_sha { target_branch_sha }
end end
......
...@@ -24,11 +24,12 @@ RSpec.describe Mutations::Commits::Create do ...@@ -24,11 +24,12 @@ RSpec.describe Mutations::Commits::Create do
let(:branch) { 'master' } let(:branch) { 'master' }
let(:start_branch) { nil } let(:start_branch) { nil }
let(:message) { 'Commit message' } let(:message) { 'Commit message' }
let(:file_path) { "#{SecureRandom.uuid}.md" }
let(:actions) do let(:actions) do
[ [
{ {
action: 'create', action: 'create',
file_path: 'NEW_FILE.md', file_path: file_path,
content: 'Hello' content: 'Hello'
} }
] ]
...@@ -68,12 +69,17 @@ RSpec.describe Mutations::Commits::Create do ...@@ -68,12 +69,17 @@ RSpec.describe Mutations::Commits::Create do
end end
context 'when service successfully creates a new commit' do context 'when service successfully creates a new commit' do
it "returns the ETag path for the commit's pipeline" do
commit_pipeline_path = subject[:commit_pipeline_path]
expect(commit_pipeline_path).to match(%r(pipelines/sha/\w+))
end
it 'returns a new commit' do it 'returns a new commit' do
expect(mutated_commit).to have_attributes(message: message, project: project) expect(mutated_commit).to have_attributes(message: message, project: project)
expect(subject[:errors]).to be_empty expect(subject[:errors]).to be_empty
expect_to_contain_deltas([ expect_to_contain_deltas([
a_hash_including(a_mode: '0', b_mode: '100644', new_file: true, new_path: 'NEW_FILE.md') a_hash_including(a_mode: '0', b_mode: '100644', new_file: true, new_path: file_path)
]) ])
end end
end end
......
...@@ -353,7 +353,12 @@ RSpec.describe GitlabRoutingHelper do ...@@ -353,7 +353,12 @@ RSpec.describe GitlabRoutingHelper do
context 'GraphQL ETag paths' do context 'GraphQL ETag paths' do
context 'with pipelines' do context 'with pipelines' do
let(:pipeline) { double(id: 5) } let(:sha) { 'b08774cb1a11ecdc27a82c5f444a69ea7e038ede' }
let(:pipeline) { double(id: 5 ) }
it 'returns an ETag path for a pipeline sha' do
expect(graphql_etag_pipeline_sha_path(sha)).to eq('/api/graphql:pipelines/sha/b08774cb1a11ecdc27a82c5f444a69ea7e038ede')
end
it 'returns an ETag path for pipelines' do it 'returns an ETag path for pipelines' do
expect(graphql_etag_pipeline_path(pipeline)).to eq('/api/graphql:pipelines/id/5') expect(graphql_etag_pipeline_path(pipeline)).to eq('/api/graphql:pipelines/id/5')
......
...@@ -22,6 +22,14 @@ RSpec.describe Gitlab::EtagCaching::Router do ...@@ -22,6 +22,14 @@ RSpec.describe Gitlab::EtagCaching::Router do
expect(result.name).to eq 'pipelines_graph' expect(result.name).to eq 'pipelines_graph'
expect(result.router).to eq Gitlab::EtagCaching::Router::Graphql expect(result.router).to eq Gitlab::EtagCaching::Router::Graphql
end end
it 'matches pipeline sha endpoint' do
result = match_route('/api/graphql', 'pipelines/sha/4asda2jiwjdqw0')
expect(result).to be_present
expect(result.name).to eq 'ci_editor'
expect(result.router).to eq Gitlab::EtagCaching::Router::Graphql
end
end end
end end
......
...@@ -15,12 +15,14 @@ RSpec.describe Ci::ExpirePipelineCacheService do ...@@ -15,12 +15,14 @@ RSpec.describe Ci::ExpirePipelineCacheService do
new_mr_pipelines_path = "/#{project.full_path}/-/merge_requests/new.json" new_mr_pipelines_path = "/#{project.full_path}/-/merge_requests/new.json"
pipeline_path = "/#{project.full_path}/-/pipelines/#{pipeline.id}.json" pipeline_path = "/#{project.full_path}/-/pipelines/#{pipeline.id}.json"
graphql_pipeline_path = "/api/graphql:pipelines/id/#{pipeline.id}" graphql_pipeline_path = "/api/graphql:pipelines/id/#{pipeline.id}"
graphql_pipeline_sha_path = "/api/graphql:pipelines/sha/#{pipeline.sha}"
expect_next_instance_of(Gitlab::EtagCaching::Store) do |store| expect_next_instance_of(Gitlab::EtagCaching::Store) do |store|
expect(store).to receive(:touch).with(pipelines_path) expect(store).to receive(:touch).with(pipelines_path)
expect(store).to receive(:touch).with(new_mr_pipelines_path) expect(store).to receive(:touch).with(new_mr_pipelines_path)
expect(store).to receive(:touch).with(pipeline_path) expect(store).to receive(:touch).with(pipeline_path)
expect(store).to receive(:touch).with(graphql_pipeline_path) expect(store).to receive(:touch).with(graphql_pipeline_path)
expect(store).to receive(:touch).with(graphql_pipeline_sha_path)
end end
subject.execute(pipeline) subject.execute(pipeline)
......
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