Commit fa3fb097 authored by David O'Regan's avatar David O'Regan

Merge branch 'nfriend-update-release-utils' into 'master'

Add new GraphQL query for release editing

See merge request gitlab-org/gitlab!59515
parents c154bd57 21c3cbec
#import "./release_for_editing.fragment.graphql"
query oneReleaseForEditing($fullPath: ID!, $tagName: String!) {
project(fullPath: $fullPath) {
release(tagName: $tagName) {
...ReleaseForEditing
}
}
}
fragment ReleaseForEditing on Release {
name
tagName
description
assets {
links {
nodes {
id
name
url
linkType
}
}
}
links {
selfUrl
}
milestones {
nodes {
title
}
}
}
...@@ -52,24 +52,37 @@ const convertScalarProperties = (graphQLRelease) => ...@@ -52,24 +52,37 @@ const convertScalarProperties = (graphQLRelease) =>
'name', 'name',
'tagName', 'tagName',
'tagPath', 'tagPath',
'description',
'descriptionHtml', 'descriptionHtml',
'releasedAt', 'releasedAt',
'upcomingRelease', 'upcomingRelease',
]); ]);
const convertAssets = (graphQLRelease) => ({ const convertAssets = (graphQLRelease) => {
assets: { let sources = [];
count: graphQLRelease.assets.count, if (graphQLRelease.assets.sources?.nodes) {
sources: [...graphQLRelease.assets.sources.nodes], sources = [...graphQLRelease.assets.sources.nodes];
links: graphQLRelease.assets.links.nodes.map((l) => ({ }
let links = [];
if (graphQLRelease.assets.links?.nodes) {
links = graphQLRelease.assets.links.nodes.map((l) => ({
...l, ...l,
linkType: l.linkType?.toLowerCase(), linkType: l.linkType?.toLowerCase(),
})), }));
}, }
});
return {
assets: {
count: graphQLRelease.assets.count,
sources,
links,
},
};
};
const convertEvidences = (graphQLRelease) => ({ const convertEvidences = (graphQLRelease) => ({
evidences: graphQLRelease.evidences.nodes.map((e) => e), evidences: (graphQLRelease.evidences?.nodes ?? []).map((e) => ({ ...e })),
}); });
const convertLinks = (graphQLRelease) => ({ const convertLinks = (graphQLRelease) => ({
...@@ -100,10 +113,12 @@ const convertMilestones = (graphQLRelease) => ({ ...@@ -100,10 +113,12 @@ const convertMilestones = (graphQLRelease) => ({
...m, ...m,
webUrl: m.webPath, webUrl: m.webPath,
webPath: undefined, webPath: undefined,
issueStats: { issueStats: m.stats
total: m.stats.totalIssuesCount, ? {
closed: m.stats.closedIssuesCount, total: m.stats.totalIssuesCount,
}, closed: m.stats.closedIssuesCount,
}
: {},
stats: undefined, stats: undefined,
})), })),
}); });
......
...@@ -121,14 +121,16 @@ RSpec.describe 'Releases (JavaScript fixtures)' do ...@@ -121,14 +121,16 @@ RSpec.describe 'Releases (JavaScript fixtures)' do
all_releases_query_path = 'releases/queries/all_releases.query.graphql' all_releases_query_path = 'releases/queries/all_releases.query.graphql'
one_release_query_path = 'releases/queries/one_release.query.graphql' one_release_query_path = 'releases/queries/one_release.query.graphql'
fragment_paths = ['releases/queries/release.fragment.graphql'] one_release_for_editing_query_path = 'releases/queries/one_release_for_editing.query.graphql'
release_fragment_path = 'releases/queries/release.fragment.graphql'
release_for_editing_fragment_path = 'releases/queries/release_for_editing.fragment.graphql'
before(:all) do before(:all) do
clean_frontend_fixtures('graphql/releases/') clean_frontend_fixtures('graphql/releases/')
end end
it "graphql/#{all_releases_query_path}.json" do it "graphql/#{all_releases_query_path}.json" do
query = get_graphql_query_as_string(all_releases_query_path, fragment_paths) query = get_graphql_query_as_string(all_releases_query_path, [release_fragment_path])
post_graphql(query, current_user: admin, variables: { fullPath: project.full_path }) post_graphql(query, current_user: admin, variables: { fullPath: project.full_path })
...@@ -136,7 +138,15 @@ RSpec.describe 'Releases (JavaScript fixtures)' do ...@@ -136,7 +138,15 @@ RSpec.describe 'Releases (JavaScript fixtures)' do
end end
it "graphql/#{one_release_query_path}.json" do it "graphql/#{one_release_query_path}.json" do
query = get_graphql_query_as_string(one_release_query_path, fragment_paths) query = get_graphql_query_as_string(one_release_query_path, [release_fragment_path])
post_graphql(query, current_user: admin, variables: { fullPath: project.full_path, tagName: release.tag })
expect_graphql_errors_to_be_empty
end
it "graphql/#{one_release_for_editing_query_path}.json" do
query = get_graphql_query_as_string(one_release_for_editing_query_path, [release_for_editing_fragment_path])
post_graphql(query, current_user: admin, variables: { fullPath: project.full_path, tagName: release.tag }) post_graphql(query, current_user: admin, variables: { fullPath: project.full_path, tagName: release.tag })
......
...@@ -129,6 +129,68 @@ Object { ...@@ -129,6 +129,68 @@ Object {
} }
`; `;
exports[`releases/util.js convertOneReleaseForEditingGraphQLResponse matches snapshot 1`] = `
Object {
"data": Object {
"_links": Object {
"self": "http://localhost/releases-namespace/releases-project/-/releases/v1.1",
"selfUrl": "http://localhost/releases-namespace/releases-project/-/releases/v1.1",
},
"assets": Object {
"count": undefined,
"links": Array [
Object {
"id": "gid://gitlab/Releases::Link/13",
"linkType": "image",
"name": "Image",
"url": "https://example.com/image",
},
Object {
"id": "gid://gitlab/Releases::Link/12",
"linkType": "package",
"name": "Package",
"url": "https://example.com/package",
},
Object {
"id": "gid://gitlab/Releases::Link/11",
"linkType": "runbook",
"name": "Runbook",
"url": "http://localhost/releases-namespace/releases-project/runbook",
},
Object {
"id": "gid://gitlab/Releases::Link/10",
"linkType": "other",
"name": "linux-amd64 binaries",
"url": "https://downloads.example.com/bin/gitlab-linux-amd64",
},
],
"sources": Array [],
},
"author": undefined,
"description": "Best. Release. **Ever.** :rocket:",
"evidences": Array [],
"milestones": Array [
Object {
"issueStats": Object {},
"stats": undefined,
"title": "12.3",
"webPath": undefined,
"webUrl": undefined,
},
Object {
"issueStats": Object {},
"stats": undefined,
"title": "12.4",
"webPath": undefined,
"webUrl": undefined,
},
],
"name": "The first release",
"tagName": "v1.1",
},
}
`;
exports[`releases/util.js convertOneReleaseGraphQLResponse matches snapshot 1`] = ` exports[`releases/util.js convertOneReleaseGraphQLResponse matches snapshot 1`] = `
Object { Object {
"data": Object { "data": Object {
......
...@@ -14,6 +14,9 @@ const originalAllReleasesQueryResponse = getJSONFixture( ...@@ -14,6 +14,9 @@ const originalAllReleasesQueryResponse = getJSONFixture(
const originalOneReleaseQueryResponse = getJSONFixture( const originalOneReleaseQueryResponse = getJSONFixture(
'graphql/releases/queries/one_release.query.graphql.json', 'graphql/releases/queries/one_release.query.graphql.json',
); );
const originalOneReleaseForEditingQueryResponse = getJSONFixture(
'graphql/releases/queries/one_release_for_editing.query.graphql.json',
);
describe('releases/util.js', () => { describe('releases/util.js', () => {
describe('releaseToApiJson', () => { describe('releaseToApiJson', () => {
...@@ -135,6 +138,26 @@ describe('releases/util.js', () => { ...@@ -135,6 +138,26 @@ describe('releases/util.js', () => {
expect(convertedRelease.assets.links[0].linkType).toBeUndefined(); expect(convertedRelease.assets.links[0].linkType).toBeUndefined();
}); });
it('handles assets that have no links', () => {
expect(convertedRelease.assets.links[0]).not.toBeUndefined();
delete releaseFromResponse.assets.links;
convertedRelease = convertGraphQLRelease(releaseFromResponse);
expect(convertedRelease.assets.links).toEqual([]);
});
it('handles assets that have no sources', () => {
expect(convertedRelease.assets.sources[0]).not.toBeUndefined();
delete releaseFromResponse.assets.sources;
convertedRelease = convertGraphQLRelease(releaseFromResponse);
expect(convertedRelease.assets.sources).toEqual([]);
});
}); });
describe('_links', () => { describe('_links', () => {
...@@ -160,6 +183,33 @@ describe('releases/util.js', () => { ...@@ -160,6 +183,33 @@ describe('releases/util.js', () => {
expect(convertedRelease.commit).toBeUndefined(); expect(convertedRelease.commit).toBeUndefined();
}); });
}); });
describe('milestones', () => {
it("handles releases that don't have any milestone stats", () => {
expect(convertedRelease.milestones[0].issueStats).not.toBeUndefined();
releaseFromResponse.milestones.nodes = releaseFromResponse.milestones.nodes.map((n) => ({
...n,
stats: undefined,
}));
convertedRelease = convertGraphQLRelease(releaseFromResponse);
expect(convertedRelease.milestones[0].issueStats).toEqual({});
});
});
describe('evidences', () => {
it("handles releases that don't have any evidences", () => {
expect(convertedRelease.evidences).not.toBeUndefined();
delete releaseFromResponse.evidences;
convertedRelease = convertGraphQLRelease(releaseFromResponse);
expect(convertedRelease.evidences).toEqual([]);
});
});
}); });
describe('convertAllReleasesGraphQLResponse', () => { describe('convertAllReleasesGraphQLResponse', () => {
...@@ -173,4 +223,12 @@ describe('releases/util.js', () => { ...@@ -173,4 +223,12 @@ describe('releases/util.js', () => {
expect(convertOneReleaseGraphQLResponse(originalOneReleaseQueryResponse)).toMatchSnapshot(); expect(convertOneReleaseGraphQLResponse(originalOneReleaseQueryResponse)).toMatchSnapshot();
}); });
}); });
describe('convertOneReleaseForEditingGraphQLResponse', () => {
it('matches snapshot', () => {
expect(
convertOneReleaseGraphQLResponse(originalOneReleaseForEditingQueryResponse),
).toMatchSnapshot();
});
});
}); });
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