From 31cb9c3bdeccc18d9752347be21a2b42e1921634 Mon Sep 17 00:00:00 2001 From: Trim21 Date: Mon, 11 Nov 2024 00:50:46 +0800 Subject: [PATCH] feat: add method to get commit date from git Signed-off-by: Trim21 --- __tests__/git.test.ts | 7 +++++++ src/git.ts | 4 ++++ 2 files changed, 11 insertions(+) diff --git a/__tests__/git.test.ts b/__tests__/git.test.ts index 8beb864..b562802 100644 --- a/__tests__/git.test.ts +++ b/__tests__/git.test.ts @@ -279,3 +279,10 @@ describe('tag', () => { }); }); }); + +describe('getCommitDate', () => { + it('head', async () => { + const date = await Git.commitDate('HEAD'); + await expect(date).toBeInstanceOf(Date); + }); +}); diff --git a/src/git.ts b/src/git.ts index 33d89c0..b2c7595 100644 --- a/src/git.ts +++ b/src/git.ts @@ -163,4 +163,8 @@ export class Git { return res.stdout.trim(); }); } + + public static async commitDate(ref: string): Promise { + return new Date(await Git.exec(['show', '-s', '--format="%ci"', ref])); + } }