summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/releases/util.js
diff options
context:
space:
mode:
Diffstat (limited to 'app/assets/javascripts/releases/util.js')
-rw-r--r--app/assets/javascripts/releases/util.js54
1 files changed, 41 insertions, 13 deletions
diff --git a/app/assets/javascripts/releases/util.js b/app/assets/javascripts/releases/util.js
index d7fac7a9b65..445c429fd96 100644
--- a/app/assets/javascripts/releases/util.js
+++ b/app/assets/javascripts/releases/util.js
@@ -107,7 +107,24 @@ const convertMilestones = graphQLRelease => ({
});
/**
- * Converts the response from the GraphQL endpoint into the
+ * Converts a single release object fetched from GraphQL
+ * into a release object that matches the shape of the REST API
+ * (the same shape that is returned by `apiJsonToRelease` above.)
+ *
+ * @param graphQLRelease The release object returned from a GraphQL query
+ */
+export const convertGraphQLRelease = graphQLRelease => ({
+ ...convertScalarProperties(graphQLRelease),
+ ...convertAssets(graphQLRelease),
+ ...convertEvidences(graphQLRelease),
+ ...convertLinks(graphQLRelease),
+ ...convertCommit(graphQLRelease),
+ ...convertAuthor(graphQLRelease),
+ ...convertMilestones(graphQLRelease),
+});
+
+/**
+ * Converts the response from all_releases.query.graphql into the
* same shape as is returned from the Releases REST API.
*
* This allows the release components to use the response
@@ -115,16 +132,27 @@ const convertMilestones = graphQLRelease => ({
*
* @param response The response received from the GraphQL endpoint
*/
-export const convertGraphQLResponse = response => {
- const releases = response.data.project.releases.nodes.map(r => ({
- ...convertScalarProperties(r),
- ...convertAssets(r),
- ...convertEvidences(r),
- ...convertLinks(r),
- ...convertCommit(r),
- ...convertAuthor(r),
- ...convertMilestones(r),
- }));
-
- return { data: releases };
+export const convertAllReleasesGraphQLResponse = response => {
+ const releases = response.data.project.releases.nodes.map(convertGraphQLRelease);
+
+ const paginationInfo = {
+ ...response.data.project.releases.pageInfo,
+ };
+
+ return { data: releases, paginationInfo };
+};
+
+/**
+ * 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
+ */
+export const convertOneReleaseGraphQLResponse = response => {
+ const release = convertGraphQLRelease(response.data.project.release);
+
+ return { data: release };
};