Skip to content
This repository was archived by the owner on Feb 14, 2025. It is now read-only.

Commit d5fbb19

Browse files
authored
Add ability to add multiple issues and prs (#43)
1 parent a817ef9 commit d5fbb19

8 files changed

+99
-18
lines changed

.azext/changelog-cache.json

+7
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,13 @@
8686
}
8787
],
8888
"pullRequests": [
89+
{
90+
"id": 816815655,
91+
"number": 43,
92+
"submitter": "joachimdalen",
93+
"title": "Add ability to add multiple issues and prs",
94+
"url": "https://github.com/joachimdalen/azext/pull/43"
95+
},
8996
{
9097
"id": 816809018,
9198
"number": 42,

.azext/changelog.json

+5
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020
"description": "Added the ability to define custom sections",
2121
"issue": 40,
2222
"pullRequest": 42
23+
},
24+
{
25+
"type": "feature",
26+
"description": "Added the ability to add multiple issues and pull requests per change",
27+
"pullRequest": 43
2328
}
2429
]
2530
}

CHANGELOG.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,18 @@
88

99
---
1010

11-
### 🚀 Features (1)
11+
### 🚀 Features (2)
1212

1313
1414

1515
- Added the ability to define custom sections
16+
1617
- Suggested in [GH#40 - Add ability to set a "Known issues" section on root](https://github.com/joachimdalen/azext/issues/40)
1718
- Added in [PR#42 - Add ability to define custom information sections at root level](https://github.com/joachimdalen/azext/pull/42)
1819

20+
- Added the ability to add multiple issues and pull requests per change
21+
- Added in [PR#43 - Add ability to add multiple issues and prs](https://github.com/joachimdalen/azext/pull/43)
22+
1923
---
2024

2125
## 0.4.0 (2022-01-05)

schemas/v1/changelog-schema.json

+10-2
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,17 @@
103103
"description": "An explanation about the purpose of this instance."
104104
},
105105
"issue": {
106-
"type": "integer",
107106
"title": "GitHub issue number",
108-
"description": "The GitHub issue number issue number of a releated GitHub issue"
107+
"description": "The GitHub issue number issue number of a releated GitHub issue",
108+
"oneOf": [
109+
{ "type": "integer" },
110+
{
111+
"type": "array",
112+
"items": {
113+
"type": "number"
114+
}
115+
}
116+
]
109117
},
110118
"pullRequest": {
111119
"type": "integer",

src/modules/changelog/changelog-service.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ class ChangelogService {
145145
if (cache.issues) {
146146
const allModules = getChangesForAllDefinition(changelog);
147147
const issueIds = allModules
148-
.map((x) => x.issue)
148+
.flatMap((x) => (Array.isArray(x.issue) ? x.issue : [x.issue]))
149149
.filter(isNumber)
150150
.filter(distinct)
151151
.filter((y) => !cache.issues?.some((x) => x.number === y));
@@ -168,7 +168,9 @@ class ChangelogService {
168168
const allModules = getChangesForAllDefinition(changelog);
169169

170170
const prIds = allModules
171-
.map((x) => x.pullRequest)
171+
.flatMap((x) =>
172+
Array.isArray(x.pullRequest) ? x.pullRequest : [x.pullRequest]
173+
)
172174
.filter(isNumber)
173175
.filter(distinct)
174176
.filter((y) => !cache.pullRequests?.some((x) => x.number === y));

src/modules/changelog/generator.ts

+64-9
Original file line numberDiff line numberDiff line change
@@ -134,25 +134,80 @@ class Generator {
134134
return typeMap;
135135
}
136136

137+
public getGithubIssue(
138+
issueId: number,
139+
resourceLink: TypeResourcePrefix,
140+
context: GeneratorContext,
141+
removePrefix: boolean
142+
) {
143+
const ghIssue = context.issues.get(issueId);
144+
145+
if (ghIssue) {
146+
const link = this.getIssueLink(ghIssue, context.config);
147+
return removePrefix ? link : `${resourceLink.issue} ${link}`;
148+
}
149+
150+
return undefined;
151+
}
152+
153+
public getGithubPr(
154+
prId: number,
155+
resourceLink: TypeResourcePrefix,
156+
context: GeneratorContext,
157+
removePrefix: boolean
158+
) {
159+
const ghPr = context.pullRequests.get(prId);
160+
161+
if (ghPr) {
162+
const link = this.getPrLink(ghPr, context.config);
163+
return removePrefix ? link : `${resourceLink.pullRequest} ${link}`;
164+
}
165+
166+
return undefined;
167+
}
168+
137169
public getGithubMeta(entry: ChangelogEntry, context: GeneratorContext) {
138170
const builder = new MarkdownBuilder();
139171
const resourceLink = this.getResourceLink(context.config, entry.type);
172+
140173
if (entry.issue !== undefined) {
141-
const ghIssue = context.issues.get(entry.issue);
174+
const isMultiple = Array.isArray(entry.issue);
175+
const issueIds: number[] = Array.isArray(entry.issue)
176+
? entry.issue
177+
: [entry.issue];
142178

143-
if (ghIssue) {
144-
builder.addSubListItem(
145-
`${resourceLink.issue} ${this.getIssueLink(ghIssue, context.config)}`
179+
if (isMultiple && resourceLink?.issue) {
180+
builder.addSubListItem(resourceLink.issue);
181+
}
182+
183+
for (const issueId of issueIds) {
184+
const issue = this.getGithubIssue(
185+
issueId,
186+
resourceLink,
187+
context,
188+
isMultiple
146189
);
190+
if (issue) {
191+
builder.addSubListItem(issue, isMultiple);
192+
}
147193
}
148194
}
149195

150196
if (entry.pullRequest !== undefined) {
151-
const ghPr = context.pullRequests.get(entry.pullRequest);
152-
if (ghPr) {
153-
builder.addSubListItem(
154-
`${resourceLink.pullRequest} ${this.getPrLink(ghPr, context.config)}`
155-
);
197+
const isMultiple = Array.isArray(entry.pullRequest);
198+
const prIds: number[] = Array.isArray(entry.pullRequest)
199+
? entry.pullRequest
200+
: [entry.pullRequest];
201+
202+
if (isMultiple && resourceLink?.pullRequest) {
203+
builder.addSubListItem(resourceLink.pullRequest);
204+
}
205+
206+
for (const prId of prIds) {
207+
const pr = this.getGithubPr(prId, resourceLink, context, isMultiple);
208+
if (pr) {
209+
builder.addSubListItem(pr, isMultiple);
210+
}
156211
}
157212
}
158213

src/modules/changelog/markdown-builder.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ export default class MarkdownBuilder {
5252
addListItem(text: string) {
5353
this.addRaw(`- ${text}`);
5454
}
55-
addSubListItem(text: string) {
56-
this.addRaw(`\t - ${text}`);
55+
addSubListItem(text: string, double = false) {
56+
this.addRaw(double ? `\t\t - ${text}` : `\t - ${text}`);
5757
}
5858
addRaw(text: string) {
5959
this._content = this._content + text + EOL;
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export default interface ChangelogEntry {
22
type: string;
3-
issue?: number;
4-
pullRequest?: number;
3+
issue?: number | number[];
4+
pullRequest?: number | number[];
55
description: string;
66
}

0 commit comments

Comments
 (0)