-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
truncate gitlab project labels to 40 chars, create util method
- Loading branch information
Showing
5 changed files
with
52 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { formatLabels } from './format-labels'; | ||
|
||
describe('formatLabels', () => { | ||
it('should format labels correctly', () => { | ||
const input = ['Example Label', 'AnotherExampleLabelThatIsWayTooLongAndShouldBeTruncated']; | ||
const expectedOutput = ['example-label', 'anotherexamplelabelthatiswaytoolongandsh']; | ||
|
||
const result = formatLabels(input); | ||
|
||
expect(result).toEqual(expectedOutput); | ||
}); | ||
|
||
it('should handle empty array', () => { | ||
const input: string[] = []; | ||
const expectedOutput: string[] = []; | ||
|
||
const result = formatLabels(input); | ||
|
||
expect(result).toEqual(expectedOutput); | ||
}); | ||
|
||
it('should not alter labels shorter than 40 characters', () => { | ||
const input = ['short', 'medium length label']; | ||
const expectedOutput = ['short', 'medium-length-label']; | ||
|
||
const result = formatLabels(input); | ||
|
||
expect(result).toEqual(expectedOutput); | ||
}); | ||
|
||
it('should convert spaces to hyphens and lowercase all characters', () => { | ||
const input = ['Mixed CASE Label', 'Label With Spaces']; | ||
const expectedOutput = ['mixed-case-label', 'label-with-spaces']; | ||
|
||
const result = formatLabels(input); | ||
|
||
expect(result).toEqual(expectedOutput); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// Converts the topics from a GitLab project to a list of formatted labels for a Compass component. | ||
export const formatLabels = (labels: string[]): string[] => { | ||
return labels.map((label) => { | ||
const transformedLabel = label.split(' ').join('-').toLowerCase(); | ||
return transformedLabel.length > 40 ? transformedLabel.slice(0, 40) : transformedLabel; | ||
}); | ||
}; |