Skip to content
This repository has been archived by the owner on Mar 18, 2024. It is now read-only.

Commit

Permalink
fix(publish): Add limitTag function
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeffreyChaucer committed Mar 21, 2023
1 parent 6c9563e commit 6736263
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions packages/core/src/git/GitTags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,35 @@ export default class GitTags {
}


public async filteredOldTags(daysToKeep: number, limit: number): Promise<string[]> {
public async limitTags(limit: number): Promise<string[]>{
let rawTags = await this.listTagsOnBranch();

if (rawTags.length <= limit) {
return [];
}

const tags:string [] = rawTags.slice(0, Math.abs(limit) * -1);
return tags;
}


public async filteredOldTags(daysToKeep: number, limit?: number): Promise<string[]> {
const currentTimestamp = Math.floor(Date.now() / 1000);

let rawTags = await this.listTagsOnBranch();
const tags: string[] = await this.getTagsWithTimestamps(rawTags)
let rawTags: string[];
if (limit) {
rawTags = await this.limitTags(limit);
} else {
rawTags = await this.listTagsOnBranch();
}

if (rawTags.length < 0) {
return [];
}

let tags: string[] = await this.getTagsWithTimestamps(rawTags);

const filteredTags = tags
.slice(0, Math.abs(limit) * -1)
.map(tagStr => {
const [name, timestampStr] = tagStr.split(' ');
const timestamp = parseInt(timestampStr, 10);
Expand All @@ -110,8 +131,6 @@ export default class GitTags {
return filteredTags.map(tag => tag.name);
}



private async getTagsWithTimestamps(tags: string[]): Promise<string[]> {
const timestampPromises: Promise<number>[] = [];

Expand Down

0 comments on commit 6736263

Please sign in to comment.