Skip to content

Commit 31cb9c3

Browse files
committed
feat: add method to get commit date from git
Signed-off-by: Trim21 <trim21.me@gmail.com>
1 parent 37b0f81 commit 31cb9c3

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

__tests__/git.test.ts

+7
Original file line numberDiff line numberDiff line change
@@ -279,3 +279,10 @@ describe('tag', () => {
279279
});
280280
});
281281
});
282+
283+
describe('getCommitDate', () => {
284+
it('head', async () => {
285+
const date = await Git.commitDate('HEAD');
286+
await expect(date).toBeInstanceOf(Date);
287+
});
288+
});

src/git.ts

+4
Original file line numberDiff line numberDiff line change
@@ -163,4 +163,8 @@ export class Git {
163163
return res.stdout.trim();
164164
});
165165
}
166+
167+
public static async commitDate(ref: string): Promise<Date> {
168+
return new Date(await Git.exec(['show', '-s', '--format="%ci"', ref]));
169+
}
166170
}

0 commit comments

Comments
 (0)