Skip to content

Commit

Permalink
Minor edits to new gitlab milestones feature
Browse files Browse the repository at this point in the history
  • Loading branch information
webpro committed Mar 31, 2022
1 parent af0882f commit 63869b8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 22 deletions.
4 changes: 2 additions & 2 deletions docs/gitlab-releases.md
Expand Up @@ -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
{
Expand Down
37 changes: 17 additions & 20 deletions lib/plugin/gitlab/GitLab.js
Expand Up @@ -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) {
Expand Down

0 comments on commit 63869b8

Please sign in to comment.