2020-09-15 11:10:08 -04:00
|
|
|
import { pick } from 'lodash';
|
|
|
|
import createGqClient, { fetchPolicies } from '~/lib/graphql';
|
2021-02-14 13:09:20 -05:00
|
|
|
import { truncateSha } from '~/lib/utils/text_utility';
|
2020-08-10 11:09:49 -04:00
|
|
|
|
2020-09-15 11:10:08 -04:00
|
|
|
export const gqClient = createGqClient({}, { fetchPolicy: fetchPolicies.NO_CACHE });
|
|
|
|
|
2020-12-23 19:10:25 -05:00
|
|
|
const convertScalarProperties = (graphQLRelease) =>
|
2020-09-15 11:10:08 -04:00
|
|
|
pick(graphQLRelease, [
|
|
|
|
'name',
|
|
|
|
'tagName',
|
|
|
|
'tagPath',
|
2021-04-26 14:09:45 -04:00
|
|
|
'description',
|
2020-09-15 11:10:08 -04:00
|
|
|
'descriptionHtml',
|
|
|
|
'releasedAt',
|
|
|
|
'upcomingRelease',
|
|
|
|
]);
|
|
|
|
|
2021-04-26 14:09:45 -04:00
|
|
|
const convertAssets = (graphQLRelease) => {
|
|
|
|
let sources = [];
|
|
|
|
if (graphQLRelease.assets.sources?.nodes) {
|
|
|
|
sources = [...graphQLRelease.assets.sources.nodes];
|
|
|
|
}
|
|
|
|
|
|
|
|
let links = [];
|
|
|
|
if (graphQLRelease.assets.links?.nodes) {
|
|
|
|
links = graphQLRelease.assets.links.nodes.map((l) => ({
|
2020-09-15 11:10:08 -04:00
|
|
|
...l,
|
|
|
|
linkType: l.linkType?.toLowerCase(),
|
2021-04-26 14:09:45 -04:00
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
assets: {
|
|
|
|
count: graphQLRelease.assets.count,
|
|
|
|
sources,
|
|
|
|
links,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
2020-09-15 11:10:08 -04:00
|
|
|
|
2020-12-23 19:10:25 -05:00
|
|
|
const convertEvidences = (graphQLRelease) => ({
|
2021-04-26 14:09:45 -04:00
|
|
|
evidences: (graphQLRelease.evidences?.nodes ?? []).map((e) => ({ ...e })),
|
2020-09-15 11:10:08 -04:00
|
|
|
});
|
|
|
|
|
2020-12-23 19:10:25 -05:00
|
|
|
const convertLinks = (graphQLRelease) => ({
|
2020-09-15 11:10:08 -04:00
|
|
|
_links: {
|
|
|
|
...graphQLRelease.links,
|
|
|
|
self: graphQLRelease.links?.selfUrl,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2020-12-23 19:10:25 -05:00
|
|
|
const convertCommit = (graphQLRelease) => {
|
2020-09-15 11:10:08 -04:00
|
|
|
if (!graphQLRelease.commit) {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
commit: {
|
|
|
|
shortId: truncateSha(graphQLRelease.commit.sha),
|
|
|
|
title: graphQLRelease.commit.title,
|
|
|
|
},
|
|
|
|
commitPath: graphQLRelease.commit.webUrl,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2020-12-23 19:10:25 -05:00
|
|
|
const convertAuthor = (graphQLRelease) => ({ author: graphQLRelease.author });
|
2020-09-15 11:10:08 -04:00
|
|
|
|
2020-12-23 19:10:25 -05:00
|
|
|
const convertMilestones = (graphQLRelease) => ({
|
|
|
|
milestones: graphQLRelease.milestones.nodes.map((m) => ({
|
2020-09-15 11:10:08 -04:00
|
|
|
...m,
|
|
|
|
webUrl: m.webPath,
|
|
|
|
webPath: undefined,
|
2021-04-26 14:09:45 -04:00
|
|
|
issueStats: m.stats
|
|
|
|
? {
|
|
|
|
total: m.stats.totalIssuesCount,
|
|
|
|
closed: m.stats.closedIssuesCount,
|
|
|
|
}
|
|
|
|
: {},
|
2020-09-15 11:10:08 -04:00
|
|
|
stats: undefined,
|
|
|
|
})),
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
2020-10-15 05:08:41 -04:00
|
|
|
* Converts a single release object fetched from GraphQL
|
2021-04-28 17:10:01 -04:00
|
|
|
* into a release object that matches the general structure of the REST API
|
2020-10-15 05:08:41 -04:00
|
|
|
*
|
|
|
|
* @param graphQLRelease The release object returned from a GraphQL query
|
|
|
|
*/
|
2020-12-23 19:10:25 -05:00
|
|
|
export const convertGraphQLRelease = (graphQLRelease) => ({
|
2020-10-15 05:08:41 -04:00
|
|
|
...convertScalarProperties(graphQLRelease),
|
|
|
|
...convertAssets(graphQLRelease),
|
|
|
|
...convertEvidences(graphQLRelease),
|
|
|
|
...convertLinks(graphQLRelease),
|
|
|
|
...convertCommit(graphQLRelease),
|
|
|
|
...convertAuthor(graphQLRelease),
|
|
|
|
...convertMilestones(graphQLRelease),
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Converts the response from all_releases.query.graphql into the
|
2020-09-15 11:10:08 -04:00
|
|
|
* same shape as is returned from the Releases REST API.
|
|
|
|
*
|
|
|
|
* This allows the release components to use the response
|
|
|
|
* from either endpoint interchangeably.
|
|
|
|
*
|
|
|
|
* @param response The response received from the GraphQL endpoint
|
|
|
|
*/
|
2020-12-23 19:10:25 -05:00
|
|
|
export const convertAllReleasesGraphQLResponse = (response) => {
|
2020-10-15 05:08:41 -04:00
|
|
|
const releases = response.data.project.releases.nodes.map(convertGraphQLRelease);
|
2020-09-15 11:10:08 -04:00
|
|
|
|
2020-09-18 11:09:22 -04:00
|
|
|
const paginationInfo = {
|
|
|
|
...response.data.project.releases.pageInfo,
|
|
|
|
};
|
|
|
|
|
|
|
|
return { data: releases, paginationInfo };
|
2020-09-15 11:10:08 -04:00
|
|
|
};
|
2020-10-15 05:08:41 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Converts the response from one_release.query.graphql into the
|
|
|
|
* same shape as is returned from the Releases REST API.
|
|
|
|
*
|
|
|
|
* This allows the release components to use the response
|
|
|
|
* from either endpoint interchangeably.
|
|
|
|
*
|
|
|
|
* @param response The response received from the GraphQL endpoint
|
|
|
|
*/
|
2020-12-23 19:10:25 -05:00
|
|
|
export const convertOneReleaseGraphQLResponse = (response) => {
|
2020-10-15 05:08:41 -04:00
|
|
|
const release = convertGraphQLRelease(response.data.project.release);
|
|
|
|
|
|
|
|
return { data: release };
|
|
|
|
};
|