From 63869b8f35de6ed765c643f38c273014ac709efe Mon Sep 17 00:00:00 2001 From: Lars Kappert Date: Thu, 31 Mar 2022 18:42:39 -0300 Subject: [PATCH] Minor edits to new gitlab milestones feature --- docs/gitlab-releases.md | 4 ++-- lib/plugin/gitlab/GitLab.js | 37 +++++++++++++++++-------------------- 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/docs/gitlab-releases.md b/docs/gitlab-releases.md index a23b3821..9f5ce3e0 100644 --- a/docs/gitlab-releases.md +++ b/docs/gitlab-releases.md @@ -42,8 +42,8 @@ See [Changelog](./changelog.md) for more information about generating changelogs ## Milestones -To associate one or more milestones with a GitLab release, set the `gitlab.milestones` option to an array of the -titles of the corresponding milestones, for example: +To associate one or more milestones with a GitLab release, set the `gitlab.milestones` option to an array of the titles +of the corresponding milestones, for example: ```json { diff --git a/lib/plugin/gitlab/GitLab.js b/lib/plugin/gitlab/GitLab.js index 89d6900d..6ab7ebf1 100644 --- a/lib/plugin/gitlab/GitLab.js +++ b/lib/plugin/gitlab/GitLab.js @@ -124,32 +124,29 @@ class GitLab extends Release { const { id } = this.getContext(); const endpoint = `projects/${id}/milestones`; - const requests = []; - for (let releaseMilestone of releaseMilestones) { + const requests = releaseMilestones.map(milestone => { const options = { method: 'GET', searchParams: { - title: releaseMilestone, + title: milestone, include_parent_milestones: true } }; - requests.push( - this.request(endpoint, options).then(response => { - if (!Array.isArray(response)) { - const { baseUrl } = this.getContext(); - throw new Error( - `Unexpected response from ${baseUrl}/${endpoint}. Expected an array but got: ${JSON.stringify(response)}` - ); - } - if (response.length === 0) { - const error = new Error(`Milestone '${releaseMilestone}' does not exist!`); - this.log.warn(error.message); - throw error; - } - this.log.verbose(`gitlab releases#checkReleaseMilestones: milestone '${releaseMilestone}' exists`); - }) - ); - } + return this.request(endpoint, options).then(response => { + if (!Array.isArray(response)) { + const { baseUrl } = this.getContext(); + throw new Error( + `Unexpected response from ${baseUrl}/${endpoint}. Expected an array but got: ${JSON.stringify(response)}` + ); + } + if (response.length === 0) { + const error = new Error(`Milestone '${milestone}' does not exist.`); + this.log.warn(error.message); + throw error; + } + this.log.verbose(`gitlab releases#checkReleaseMilestones: milestone '${milestone}' exists`); + }); + }); try { await Promise.allSettled(requests).then(results => { for (const result of results) {