Skip to content

Commit

Permalink
getValidTags() should exclude tags that do not match the prefixRegex (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
duality72 authored Jan 22, 2023
1 parent 6644374 commit ac8cb38
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 8 deletions.
8 changes: 6 additions & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,17 @@ export async function getValidTags(
const tags = await listTags(shouldFetchAllTags);

const invalidTags = tags.filter(
(tag) => !valid(tag.name.replace(prefixRegex, ''))
(tag) =>
!prefixRegex.test(tag.name) || !valid(tag.name.replace(prefixRegex, ''))
);

invalidTags.forEach((name) => core.debug(`Found Invalid Tag: ${name}.`));

const validTags = tags
.filter((tag) => valid(tag.name.replace(prefixRegex, '')))
.filter(
(tag) =>
prefixRegex.test(tag.name) && valid(tag.name.replace(prefixRegex, ''))
)
.sort((a, b) =>
rcompare(a.name.replace(prefixRegex, ''), b.name.replace(prefixRegex, ''))
);
Expand Down
60 changes: 54 additions & 6 deletions tests/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ describe('utils', () => {
node_id: 'string',
},
{
name: '1.2.3',
name: 'v1.2.3',
commit: { sha: 'string', url: 'string' },
zipball_url: 'string',
tarball_url: 'string',
Expand Down Expand Up @@ -86,28 +86,28 @@ describe('utils', () => {
*/
const testTags = [
{
name: '1.2.4-prerelease.1',
name: 'v1.2.4-prerelease.1',
commit: { sha: 'string', url: 'string' },
zipball_url: 'string',
tarball_url: 'string',
node_id: 'string',
},
{
name: '1.2.4-prerelease.2',
name: 'v1.2.4-prerelease.2',
commit: { sha: 'string', url: 'string' },
zipball_url: 'string',
tarball_url: 'string',
node_id: 'string',
},
{
name: '1.2.4-prerelease.0',
name: 'v1.2.4-prerelease.0',
commit: { sha: 'string', url: 'string' },
zipball_url: 'string',
tarball_url: 'string',
node_id: 'string',
},
{
name: '1.2.3',
name: 'v1.2.3',
commit: { sha: 'string', url: 'string' },
zipball_url: 'string',
tarball_url: 'string',
Expand All @@ -128,7 +128,55 @@ describe('utils', () => {
*/
expect(mockListTags).toHaveBeenCalled();
expect(validTags[0]).toEqual({
name: '1.2.4-prerelease.2',
name: 'v1.2.4-prerelease.2',
commit: { sha: 'string', url: 'string' },
zipball_url: 'string',
tarball_url: 'string',
node_id: 'string',
});
});

it('returns only prefixed tags', async () => {
/*
* Given
*/
const testTags = [
{
name: 'app2/5.0.0',
commit: { sha: 'string', url: 'string' },
zipball_url: 'string',
tarball_url: 'string',
node_id: 'string',
},
{
name: '7.0.0',
commit: { sha: 'string', url: 'string' },
zipball_url: 'string',
tarball_url: 'string',
node_id: 'string',
},
{
name: 'app1/3.0.0',
commit: { sha: 'string', url: 'string' },
zipball_url: 'string',
tarball_url: 'string',
node_id: 'string',
},
];
const mockListTags = jest
.spyOn(github, 'listTags')
.mockImplementation(async () => testTags);
/*
* When
*/
const validTags = await getValidTags(/^app1\//, false);
/*
* Then
*/
expect(mockListTags).toHaveBeenCalled();
expect(validTags).toHaveLength(1);
expect(validTags[0]).toEqual({
name: 'app1/3.0.0',
commit: { sha: 'string', url: 'string' },
zipball_url: 'string',
tarball_url: 'string',
Expand Down

0 comments on commit ac8cb38

Please sign in to comment.