Skip to content

Commit

Permalink
feat: add method to get commit date from git
Browse files Browse the repository at this point in the history
Signed-off-by: Trim21 <[email protected]>
  • Loading branch information
trim21 committed Nov 13, 2024
1 parent 37b0f81 commit 31cb9c3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
7 changes: 7 additions & 0 deletions __tests__/git.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,3 +279,10 @@ describe('tag', () => {
});
});
});

describe('getCommitDate', () => {
it('head', async () => {
const date = await Git.commitDate('HEAD');
await expect(date).toBeInstanceOf(Date);
});
});
4 changes: 4 additions & 0 deletions src/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,8 @@ export class Git {
return res.stdout.trim();
});
}

public static async commitDate(ref: string): Promise<Date> {
return new Date(await Git.exec(['show', '-s', '--format="%ci"', ref]));
}
}

0 comments on commit 31cb9c3

Please sign in to comment.