Commit bddb425e authored by Nathan Friend's avatar Nathan Friend

Add release direct_asset_url to GraphQL

This commit adds the release direct_asset_url field to GraphQL.
parent 4fe0a254
...@@ -17,5 +17,17 @@ module Types ...@@ -17,5 +17,17 @@ module Types
description: 'Type of the link: `other`, `runbook`, `image`, `package`; defaults to `other`' description: 'Type of the link: `other`, `runbook`, `image`, `package`; defaults to `other`'
field :external, GraphQL::BOOLEAN_TYPE, null: true, method: :external?, field :external, GraphQL::BOOLEAN_TYPE, null: true, method: :external?,
description: 'Indicates the link points to an external resource' description: 'Indicates the link points to an external resource'
field :direct_asset_url, GraphQL::STRING_TYPE, null: true,
description: 'Direct asset URL of the link'
def direct_asset_url
return object.url unless object.filepath
release = object.release
project = release.project
Gitlab::Routing.url_helpers.project_release_url(project, release) << object.filepath
end
end end
end end
---
title: Add release direct asset link info to GraphQL endpoint
merge_request: 41170
author:
type: added
...@@ -13351,6 +13351,11 @@ type Release { ...@@ -13351,6 +13351,11 @@ type Release {
Represents an asset link associated with a release Represents an asset link associated with a release
""" """
type ReleaseAssetLink { type ReleaseAssetLink {
"""
Direct asset URL of the link
"""
directAssetUrl: String
""" """
Indicates the link points to an external resource Indicates the link points to an external resource
""" """
......
...@@ -39075,6 +39075,20 @@ ...@@ -39075,6 +39075,20 @@
"name": "ReleaseAssetLink", "name": "ReleaseAssetLink",
"description": "Represents an asset link associated with a release", "description": "Represents an asset link associated with a release",
"fields": [ "fields": [
{
"name": "directAssetUrl",
"description": "Direct asset URL of the link",
"args": [
],
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{ {
"name": "external", "name": "external",
"description": "Indicates the link points to an external resource", "description": "Indicates the link points to an external resource",
...@@ -1883,6 +1883,7 @@ Represents an asset link associated with a release ...@@ -1883,6 +1883,7 @@ Represents an asset link associated with a release
| Name | Type | Description | | Name | Type | Description |
| --- | ---- | ---------- | | --- | ---- | ---------- |
| `directAssetUrl` | String | Direct asset URL of the link |
| `external` | Boolean | Indicates the link points to an external resource | | `external` | Boolean | Indicates the link points to an external resource |
| `id` | ID! | ID of the link | | `id` | ID! | ID of the link |
| `linkType` | ReleaseAssetLinkType | Type of the link: `other`, `runbook`, `image`, `package`; defaults to `other` | | `linkType` | ReleaseAssetLinkType | Type of the link: `other`, `runbook`, `image`, `package`; defaults to `other` |
......
...@@ -7,7 +7,7 @@ RSpec.describe GitlabSchema.types['ReleaseAssetLink'] do ...@@ -7,7 +7,7 @@ RSpec.describe GitlabSchema.types['ReleaseAssetLink'] do
it 'has the expected fields' do it 'has the expected fields' do
expected_fields = %w[ expected_fields = %w[
id name url external link_type id name url external link_type direct_asset_url
] ]
expect(described_class).to include_graphql_fields(*expected_fields) expect(described_class).to include_graphql_fields(*expected_fields)
......
...@@ -10,6 +10,7 @@ RSpec.describe 'Query.project(fullPath).release(tagName)' do ...@@ -10,6 +10,7 @@ RSpec.describe 'Query.project(fullPath).release(tagName)' do
let_it_be(:guest) { create(:user) } let_it_be(:guest) { create(:user) }
let_it_be(:reporter) { create(:user) } let_it_be(:reporter) { create(:user) }
let_it_be(:stranger) { create(:user) } let_it_be(:stranger) { create(:user) }
let_it_be(:link_filepath) { '/direct/asset/link/path' }
let(:params_for_issues_and_mrs) { { scope: 'all', state: 'opened', release_tag: release.tag } } let(:params_for_issues_and_mrs) { { scope: 'all', state: 'opened', release_tag: release.tag } }
let(:post_query) { post_graphql(query, current_user: current_user) } let(:post_query) { post_graphql(query, current_user: current_user) }
...@@ -127,7 +128,7 @@ RSpec.describe 'Query.project(fullPath).release(tagName)' do ...@@ -127,7 +128,7 @@ RSpec.describe 'Query.project(fullPath).release(tagName)' do
let(:release_fields) do let(:release_fields) do
query_graphql_field(:assets, nil, query_graphql_field(:assets, nil,
query_graphql_field(:links, nil, 'nodes { id name url external }')) query_graphql_field(:links, nil, 'nodes { id name url external, directAssetUrl }'))
end end
it 'finds all release links' do it 'finds all release links' do
...@@ -138,7 +139,8 @@ RSpec.describe 'Query.project(fullPath).release(tagName)' do ...@@ -138,7 +139,8 @@ RSpec.describe 'Query.project(fullPath).release(tagName)' do
'id' => global_id_of(link), 'id' => global_id_of(link),
'name' => link.name, 'name' => link.name,
'url' => link.url, 'url' => link.url,
'external' => link.external? 'external' => link.external?,
'directAssetUrl' => link.filepath ? Gitlab::Routing.url_helpers.project_release_url(project, release) << link.filepath : link.url
} }
end end
...@@ -270,7 +272,7 @@ RSpec.describe 'Query.project(fullPath).release(tagName)' do ...@@ -270,7 +272,7 @@ RSpec.describe 'Query.project(fullPath).release(tagName)' do
let_it_be(:milestone_2) { create(:milestone, project: project) } let_it_be(:milestone_2) { create(:milestone, project: project) }
let_it_be(:release) { create(:release, :with_evidence, project: project, milestones: [milestone_1, milestone_2]) } let_it_be(:release) { create(:release, :with_evidence, project: project, milestones: [milestone_1, milestone_2]) }
let_it_be(:release_link_1) { create(:release_link, release: release) } let_it_be(:release_link_1) { create(:release_link, release: release) }
let_it_be(:release_link_2) { create(:release_link, release: release) } let_it_be(:release_link_2) { create(:release_link, release: release, filepath: link_filepath) }
before_all do before_all do
project.add_developer(developer) project.add_developer(developer)
...@@ -311,7 +313,7 @@ RSpec.describe 'Query.project(fullPath).release(tagName)' do ...@@ -311,7 +313,7 @@ RSpec.describe 'Query.project(fullPath).release(tagName)' do
let_it_be(:milestone_2) { create(:milestone, project: project) } let_it_be(:milestone_2) { create(:milestone, project: project) }
let_it_be(:release) { create(:release, :with_evidence, project: project, milestones: [milestone_1, milestone_2]) } let_it_be(:release) { create(:release, :with_evidence, project: project, milestones: [milestone_1, milestone_2]) }
let_it_be(:release_link_1) { create(:release_link, release: release) } let_it_be(:release_link_1) { create(:release_link, release: release) }
let_it_be(:release_link_2) { create(:release_link, release: release) } let_it_be(:release_link_2) { create(:release_link, release: release, filepath: link_filepath) }
before_all do before_all do
project.add_developer(developer) project.add_developer(developer)
......
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