Commit 3f68c499 authored by Kushal Pandya's avatar Kushal Pandya

Merge branch 'nfriend-fix-milestone-array-payload' into 'master'

Fix milestone payload when updating releases through the UI

See merge request gitlab-org/gitlab!47222
parents 2116bb0c 1101fa16
...@@ -15,13 +15,17 @@ import { ...@@ -15,13 +15,17 @@ import {
export const releaseToApiJson = (release, createFrom = null) => { export const releaseToApiJson = (release, createFrom = null) => {
const name = release.name?.trim().length > 0 ? release.name.trim() : null; const name = release.name?.trim().length > 0 ? release.name.trim() : null;
// Milestones may be either a list of milestone objects OR just a list
// of milestone titles. The API requires only the titles be sent.
const milestones = (release.milestones || []).map(m => m.title || m);
return convertObjectPropsToSnakeCase( return convertObjectPropsToSnakeCase(
{ {
name, name,
tagName: release.tagName, tagName: release.tagName,
ref: createFrom, ref: createFrom,
description: release.description, description: release.description,
milestones: release.milestones, milestones,
assets: release.assets, assets: release.assets,
}, },
{ deep: true }, { deep: true },
......
---
title: Fix error when updating releases with milestone associations through the UI
merge_request: 47222
author:
type: fixed
...@@ -4,7 +4,7 @@ require 'spec_helper' ...@@ -4,7 +4,7 @@ require 'spec_helper'
RSpec.describe 'User edits Release', :js do RSpec.describe 'User edits Release', :js do
let_it_be(:project) { create(:project, :repository) } let_it_be(:project) { create(:project, :repository) }
let_it_be(:release) { create(:release, project: project, name: 'The first release' ) } let_it_be(:release) { create(:release, :with_milestones, milestones_count: 1, project: project, name: 'The first release' ) }
let_it_be(:user) { create(:user) } let_it_be(:user) { create(:user) }
before do before do
......
...@@ -73,6 +73,18 @@ describe('releases/util.js', () => { ...@@ -73,6 +73,18 @@ describe('releases/util.js', () => {
expect(releaseToApiJson(release)).toMatchObject(expectedJson); expect(releaseToApiJson(release)).toMatchObject(expectedJson);
}); });
}); });
describe('when milestones contains full milestone objects', () => {
it('converts the milestone objects into titles', () => {
const release = {
milestones: [{ title: '13.2' }, { title: '13.3' }, '13.4'],
};
const expectedJson = { milestones: ['13.2', '13.3', '13.4'] };
expect(releaseToApiJson(release)).toMatchObject(expectedJson);
});
});
}); });
describe('apiJsonToRelease', () => { describe('apiJsonToRelease', () => {
......
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