Commit a7dac970 authored by Marius Bobin's avatar Marius Bobin

Return ETag cache path to the frontend component

Return ETag cache path to the frontend component
And refactor url helpers
parent cfab165a
......@@ -347,6 +347,11 @@ module GitlabRoutingHelper
Gitlab::UrlBuilder.wiki_page_url(wiki, page, only_path: true, **options)
end
# GraphQL ETag routes
def graphql_etag_pipeline_path(pipeline)
[api_graphql_path, "pipelines/id/#{pipeline.id}"].join(':')
end
private
def snippet_query_params(snippet, *args)
......
......@@ -2,6 +2,11 @@
module Ci
class ExpirePipelineCacheService
class UrlHelpers
include ::Gitlab::Routing
include ::GitlabRoutingHelper
end
def execute(pipeline, delete: false)
store = Gitlab::EtagCaching::Store.new
......@@ -17,27 +22,27 @@ module Ci
private
def project_pipelines_path(project)
Gitlab::Routing.url_helpers.project_pipelines_path(project, format: :json)
url_helpers.project_pipelines_path(project, format: :json)
end
def project_pipeline_path(project, pipeline)
Gitlab::Routing.url_helpers.project_pipeline_path(project, pipeline, format: :json)
url_helpers.project_pipeline_path(project, pipeline, format: :json)
end
def commit_pipelines_path(project, commit)
Gitlab::Routing.url_helpers.pipelines_project_commit_path(project, commit.id, format: :json)
url_helpers.pipelines_project_commit_path(project, commit.id, format: :json)
end
def new_merge_request_pipelines_path(project)
Gitlab::Routing.url_helpers.project_new_merge_request_path(project, format: :json)
url_helpers.project_new_merge_request_path(project, format: :json)
end
def pipelines_project_merge_request_path(merge_request)
Gitlab::Routing.url_helpers.pipelines_project_merge_request_path(merge_request.target_project, merge_request, format: :json)
url_helpers.pipelines_project_merge_request_path(merge_request.target_project, merge_request, format: :json)
end
def merge_request_widget_path(merge_request)
Gitlab::Routing.url_helpers.cached_widget_project_json_merge_request_path(merge_request.project, merge_request, format: :json)
url_helpers.cached_widget_project_json_merge_request_path(merge_request.project, merge_request, format: :json)
end
def each_pipelines_merge_request_path(pipeline)
......@@ -48,7 +53,7 @@ module Ci
end
def graphql_pipeline_path(pipeline)
[Gitlab::Routing.url_helpers.api_graphql_path, "pipelines/id/#{pipeline.id}"].join(':')
url_helpers.graphql_etag_pipeline_path(pipeline)
end
# Updates ETag caches of a pipeline.
......@@ -70,6 +75,10 @@ module Ci
store.touch(path)
end
end
def url_helpers
@url_helpers ||= UrlHelpers.new
end
end
end
......
......@@ -26,4 +26,4 @@
= render "projects/pipelines/with_tabs", pipeline: @pipeline, pipeline_has_errors: pipeline_has_errors
.js-pipeline-details-vue{ data: { endpoint: project_pipeline_path(@project, @pipeline, format: :json), metrics_path: namespace_project_ci_prometheus_metrics_histograms_path(namespace_id: @project.namespace, project_id: @project, format: :json), pipeline_project_path: @project.full_path, pipeline_iid: @pipeline.iid } }
.js-pipeline-details-vue{ data: { endpoint: project_pipeline_path(@project, @pipeline, format: :json), metrics_path: namespace_project_ci_prometheus_metrics_histograms_path(namespace_id: @project.namespace, project_id: @project, format: :json), pipeline_project_path: @project.full_path, pipeline_iid: @pipeline.iid, graphql_resource_etag: graphql_etag_pipeline_path(@pipeline) } }
......@@ -332,4 +332,14 @@ RSpec.describe GitlabRoutingHelper do
end
end
end
context 'GraphQL ETag paths' do
context 'with pipelines' do
let(:pipeline) { double(id: 5) }
it 'returns an ETag path for pipelines' do
expect(graphql_etag_pipeline_path(pipeline)).to eq('/api/graphql:pipelines/id/5')
end
end
end
end
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