Skip to content

feat: configure tag validation#38

Open
jajera wants to merge 5 commits intosinedied:mainfrom
jdevto:test
Open

feat: configure tag validation#38
jajera wants to merge 5 commits intosinedied:mainfrom
jdevto:test

Conversation

@jajera
Copy link
Copy Markdown

@jajera jajera commented Dec 17, 2024

  • allows tag validation
  • good to run validation on dry-run to catch errors before merge to main branch

@jajera jajera changed the title Test Configure tag validation Dec 17, 2024
@jajera jajera changed the title Configure tag validation feat: configure tag validation Dec 17, 2024
@jajera
Copy link
Copy Markdown
Author

jajera commented Dec 17, 2024

supports: #37

Copy link
Copy Markdown
Owner

@sinedied sinedied left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR and sorry for the long delay!

Caught a small issue as tags weren't assigned after validation, otherwise looks good!


const tags: string[] = [];
try {
validateTags(remoteData.tag_list.join(', '));
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
validateTags(remoteData.tag_list.join(', '));
tags = validateTags(remoteData.tag_list.join(', '));

export function validateTags(tags: string): string[] {
const tagsArray = tags.split(',').map((tag) => tag.trim());
const MAX_TAGS = 4;
const INVALID_TAGS = tagsArray.filter((tag) => !/^[a-z\d-]+$/i.test(tag));
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const INVALID_TAGS = tagsArray.filter((tag) => !/^[a-z\d-]+$/i.test(tag));
const invalidTags = tagsArray.filter((tag) => !/^[a-z\d-]+$/i.test(tag));

throw new Error(`Too many tags. Max allowed: ${MAX_TAGS}`);
}

if (INVALID_TAGS.length > 0) {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (INVALID_TAGS.length > 0) {
if (invalidTags.length > 0) {

}

if (INVALID_TAGS.length > 0) {
throw new Error(`Invalid tags: ${INVALID_TAGS.join(', ')}`);
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
throw new Error(`Invalid tags: ${INVALID_TAGS.join(', ')}`);
throw new Error(`Invalid tags: ${invalidTags.join(', ')}`);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants