Skip to content

Commit a681614

Browse files
committed
fix: duplicated tags
1 parent acfd82b commit a681614

File tree

8 files changed

+117
-17
lines changed

8 files changed

+117
-17
lines changed

src/apitypes/graphql/graphql.changes.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export const compareDocuments = async (
3737
currDoc: ResolvedVersionDocument | undefined,
3838
ctx: CompareOperationsPairContext): Promise<{
3939
operationChanges: OperationChanges[]
40-
tags: string[]
40+
tags: Set<string>
4141
}> => {
4242
const { apiType, rawDocumentResolver, previousVersion, currentVersion, previousPackageId, currentPackageId } = ctx
4343
const prevFile = prevDoc && await rawDocumentResolver(previousVersion, previousPackageId, prevDoc.slug)
@@ -78,17 +78,15 @@ export const compareDocuments = async (
7878
) as { merged: GraphApiSchema; diffs: Diff[] }
7979

8080
if (isEmpty(diffs)) {
81-
return { operationChanges: [], tags: [] }
81+
return { operationChanges: [], tags: new Set() }
8282
}
8383

8484
let operationDiffs: Diff[] = []
8585

8686
const { currentGroup, previousGroup } = ctx
87-
const currGroupSlug = slugify(removeFirstSlash(currentGroup || ''))
88-
const prevGroupSlug = slugify(removeFirstSlash(previousGroup || ''))
8987

9088
const tags = new Set<string>()
91-
const changedOperations: OperationChanges[] = []
89+
const operationChanges: OperationChanges[] = []
9290

9391
for (const type of GRAPHQL_TYPE_KEYS) {
9492
const operationsByType = merged[type]
@@ -116,12 +114,12 @@ export const compareDocuments = async (
116114
continue
117115
}
118116

119-
changedOperations.push(createOperationChange(apiType, operationDiffs, previous, current, currentGroup, previousGroup))
117+
operationChanges.push(createOperationChange(apiType, operationDiffs, previous, current, currentGroup, previousGroup))
120118
getOperationTags(current ?? previous).forEach(tag => tags.add(tag))
121119
}
122120
}
123121

124-
return { operationChanges: changedOperations, tags: Array.from(tags) }
122+
return { operationChanges, tags }
125123
}
126124

127125
function getCopyWithEmptyOperations(template: GraphApiSchema): GraphApiSchema {

src/apitypes/rest/rest.changes.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export const compareDocuments = async (
7171
ctx: CompareOperationsPairContext,
7272
): Promise<{
7373
operationChanges: OperationChanges[]
74-
tags: string[]
74+
tags: Set<string>
7575
}> => {
7676
const {
7777
apiType,
@@ -118,11 +118,11 @@ export const compareDocuments = async (
118118
) as { merged: OpenAPIV3.Document; diffs: Diff[] }
119119

120120
if (isEmpty(diffs)) {
121-
return { operationChanges: [], tags: [] }
121+
return { operationChanges: [], tags: new Set() }
122122
}
123123

124124
const tags = new Set<string>()
125-
const changedOperations: OperationChanges[] = []
125+
const operationChanges: OperationChanges[] = []
126126

127127
for (const path of Object.keys(merged.paths)) {
128128
const pathData = merged.paths[path]
@@ -172,12 +172,12 @@ export const compareDocuments = async (
172172

173173
await reclassifyBreakingChanges(previous?.operationId, merged, operationDiffs, ctx)
174174

175-
changedOperations.push(createOperationChange(apiType, operationDiffs, previous, current, currentGroup, previousGroup))
175+
operationChanges.push(createOperationChange(apiType, operationDiffs, previous, current, currentGroup, previousGroup))
176176
getOperationTags(current ?? previous).forEach(tag => tags.add(tag))
177177
}
178178
}
179179

180-
return { operationChanges: changedOperations, tags: Array.from(tags) }
180+
return { operationChanges, tags }
181181
}
182182

183183
async function reclassifyBreakingChanges(

src/components/compare/compare.operations.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ async function compareCurrentApiType(
160160
apiType,
161161
changesSummary,
162162
numberOfImpactedOperations,
163-
tags: tags.sort(),
163+
tags,
164164
apiAudienceTransitions,
165165
},
166166
operationChanges,

src/components/compare/compare.utils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ export const comparePairedDocs = async (
210210
ctx: CompareOperationsPairContext,
211211
): Promise<[OperationChanges[], string[]]> => {
212212
const operationChanges: OperationChanges[] = []
213-
const tags: string[] = []
213+
const tags = new Set<string>()
214214

215215
for (const [prevDoc, currDoc] of pairedDocs) {
216216
const {
@@ -219,10 +219,10 @@ export const comparePairedDocs = async (
219219
} = await apiBuilder.compareDocuments!(operationsMap, prevDoc, currDoc, ctx)
220220

221221
operationChanges.push(...docsPairOperationChanges)
222-
tags.push(...docsPairTags)
222+
docsPairTags.forEach(tag => tags.add(tag))
223223
}
224224

225-
return [operationChanges, tags]
225+
return [operationChanges, Array.from(tags).sort()]
226226
}
227227

228228
export function createOperationChange(

src/types/internal/apiBuilder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ export type DocumentDumper<T> = (document: ZippableDocument<T>, format?: typeof
111111
export type OperationDataCompare<T> = (current: T, previous: T, ctx: CompareOperationsPairContext) => Promise<Diff[]>
112112
export type DocumentsCompare = (operationsMap: OperationsMap, currDoc: ResolvedVersionDocument | undefined, prevDoc: ResolvedVersionDocument | undefined, ctx: CompareOperationsPairContext) => Promise<{
113113
operationChanges: OperationChanges[]
114-
tags: string[]
114+
tags: Set<string>
115115
}>
116116
export type OperationIdNormalizer = (operation: ResolvedOperation) => NormalizedOperationId
117117
export type DocumentExporter = (

test/changes.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,4 +262,20 @@ describe('Changes test', () => {
262262
}),
263263
]))
264264
})
265+
266+
test('Tags are not duplicated', async () => {
267+
const result = await buildChangelogPackage('changelog/tags')
268+
269+
expect(result).toEqual(operationTypeMatcher({
270+
tags: expect.toIncludeSameMembers([
271+
'sameTagInDifferentPaths1',
272+
'sameTagInDifferentPaths2',
273+
'sameTagInDifferentPaths3',
274+
'sameTagInMethodSiblings1',
275+
'sameTagInMethodSiblings2',
276+
'sameTagInMethodSiblings3',
277+
'tag',
278+
]),
279+
}))
280+
})
265281
})
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
openapi: 3.0.3
2+
info:
3+
title: test
4+
version: 0.1.0
5+
paths:
6+
/added1:
7+
get:
8+
responses:
9+
'200':
10+
content: { }
11+
tags:
12+
- sameTagInDifferentPaths1
13+
- sameTagInDifferentPaths3
14+
/added2:
15+
get:
16+
responses:
17+
'200':
18+
content: { }
19+
tags:
20+
- sameTagInDifferentPaths1
21+
- sameTagInDifferentPaths3
22+
- sameTagInMethodSiblings2
23+
post:
24+
responses:
25+
'200':
26+
content: { }
27+
tags:
28+
- sameTagInMethodSiblings2
29+
/changed1:
30+
get:
31+
responses:
32+
'200':
33+
content: { }
34+
tags:
35+
- sameTagInDifferentPaths1
36+
- sameTagInMethodSiblings3
37+
- tag
38+
post:
39+
responses:
40+
'200':
41+
content: { }
42+
tags:
43+
- sameTagInMethodSiblings3
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
openapi: 3.0.3
2+
info:
3+
title: test
4+
version: 0.1.0
5+
paths:
6+
/removed1:
7+
get:
8+
responses:
9+
'200':
10+
content: { }
11+
tags:
12+
- sameTagInDifferentPaths1
13+
- sameTagInDifferentPaths2
14+
/removed2:
15+
get:
16+
responses:
17+
'200':
18+
content: { }
19+
tags:
20+
- sameTagInDifferentPaths1
21+
- sameTagInDifferentPaths2
22+
- sameTagInMethodSiblings1
23+
post:
24+
responses:
25+
'200':
26+
content: { }
27+
tags:
28+
- sameTagInMethodSiblings1
29+
/changed1:
30+
get:
31+
responses:
32+
'200':
33+
content: { }
34+
tags:
35+
- sameTagInDifferentPaths1
36+
- tag
37+
- missingByDesign
38+
post:
39+
responses:
40+
'200':
41+
content: { }
42+
tags:
43+
- missingByDesign

0 commit comments

Comments
 (0)