Commit dd2427c3 authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Merge branch 'lm-add-pl-sha-etag-cache' into 'master'

Adds pipeline sha to etag store

See merge request gitlab-org/gitlab!58931
parents a82fe262 5af28761
......@@ -5,6 +5,11 @@ module Mutations
class Create < BaseMutation
include FindsProject
class UrlHelpers
include GitlabRoutingHelper
include Gitlab::Routing
end
graphql_name 'CommitCreate'
argument :project_path, GraphQL::ID_TYPE,
......@@ -29,6 +34,11 @@ module Mutations
required: true,
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,
Types::CommitType,
null: true,
......@@ -50,6 +60,7 @@ module Mutations
{
commit: (project.repository.commit(result[:result]) if result[:status] == :success),
commit_pipeline_path: UrlHelpers.new.graphql_etag_pipeline_sha_path(result[:result]),
errors: Array.wrap(result[:message])
}
end
......
......@@ -364,6 +364,10 @@ module GitlabRoutingHelper
[api_graphql_path, "pipelines/id/#{pipeline.id}"].join(':')
end
def graphql_etag_pipeline_sha_path(sha)
[api_graphql_path, "pipelines/sha/#{sha}"].join(':')
end
private
def snippet_query_params(snippet, *args)
......
......@@ -56,6 +56,10 @@ module Ci
url_helpers.graphql_etag_pipeline_path(pipeline)
end
def graphql_pipeline_sha_path(sha)
url_helpers.graphql_etag_pipeline_sha_path(sha)
end
# Updates ETag caches of a pipeline.
#
# This logic resides in a separate method so that EE can more easily extend
......@@ -76,6 +80,7 @@ module Ci
pipeline.self_with_ancestors_and_descendants.each do |relative_pipeline|
store.touch(project_pipeline_path(relative_pipeline.project, relative_pipeline))
store.touch(graphql_pipeline_path(relative_pipeline))
store.touch(graphql_pipeline_sha_path(relative_pipeline.sha))
end
end
......
---
title: Add commmit_pipeline_path to CreateCommit mutation
merge_request: 58931
author:
type: added
......@@ -846,6 +846,7 @@ Input type: `CommitCreateInput`
| ---- | ---- | ----------- |
| <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="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. |
### `Mutation.configureSast`
......
......@@ -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
/* componentMountIndex.js */
......
......@@ -12,6 +12,11 @@ module Gitlab
%r(\Apipelines/id/\d+\z),
'pipelines_graph',
'continuous_integration'
],
[
%r(\Apipelines/sha/\w{7,40}\z),
'ci_editor',
'pipeline_authoring'
]
].map(&method(:build_route)).freeze
......
......@@ -237,7 +237,7 @@ FactoryBot.define do
trait :merged_result_pipeline do
detached_merge_request_pipeline
sha { 'test-merge-sha'}
sha { 'mergeSha' }
ref { merge_request.merge_ref_path }
source_sha { merge_request.source_branch_sha }
target_sha { merge_request.target_branch_sha }
......
......@@ -279,7 +279,7 @@ FactoryBot.define do
trait :with_merge_request_pipeline do
transient do
merge_sha { 'test-merge-sha' }
merge_sha { 'mergesha' }
source_sha { source_branch_sha }
target_sha { target_branch_sha }
end
......
......@@ -24,11 +24,12 @@ RSpec.describe Mutations::Commits::Create do
let(:branch) { 'master' }
let(:start_branch) { nil }
let(:message) { 'Commit message' }
let(:file_path) { "#{SecureRandom.uuid}.md" }
let(:actions) do
[
{
action: 'create',
file_path: 'NEW_FILE.md',
file_path: file_path,
content: 'Hello'
}
]
......@@ -68,12 +69,17 @@ RSpec.describe Mutations::Commits::Create do
end
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
expect(mutated_commit).to have_attributes(message: message, project: project)
expect(subject[:errors]).to be_empty
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
......
......@@ -353,7 +353,12 @@ RSpec.describe GitlabRoutingHelper do
context 'GraphQL ETag paths' 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
expect(graphql_etag_pipeline_path(pipeline)).to eq('/api/graphql:pipelines/id/5')
......
......@@ -22,6 +22,14 @@ RSpec.describe Gitlab::EtagCaching::Router do
expect(result.name).to eq 'pipelines_graph'
expect(result.router).to eq Gitlab::EtagCaching::Router::Graphql
end
it 'matches pipeline sha endpoint' do
result = match_route('/api/graphql', 'pipelines/sha/4asd12lla2jiwjdqw9as32glm8is8hiu8s2c5jsw')
expect(result).to be_present
expect(result.name).to eq 'ci_editor'
expect(result.router).to eq Gitlab::EtagCaching::Router::Graphql
end
end
end
......
......@@ -15,12 +15,14 @@ RSpec.describe Ci::ExpirePipelineCacheService do
new_mr_pipelines_path = "/#{project.full_path}/-/merge_requests/new.json"
pipeline_path = "/#{project.full_path}/-/pipelines/#{pipeline.id}.json"
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(store).to receive(:touch).with(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(graphql_pipeline_path)
expect(store).to receive(:touch).with(graphql_pipeline_sha_path)
end
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