diff options
| author | Kevin J Hoerr <kjhoerr@protonmail.com> | 2021-09-16 16:52:14 -0400 |
|---|---|---|
| committer | Kevin J Hoerr <kjhoerr@protonmail.com> | 2021-09-16 16:52:14 -0400 |
| commit | 0d48769556db3ed313434c7e824339924c8df792 (patch) | |
| tree | ce584b7bd68c709beb2aad53bc0aa45f0165333d /src/metadata.ts | |
| parent | 6bbd3f03104e6dcd9da89a8ec5dcb5d992ee3ed5 (diff) | |
| download | ao-coverage-0d48769556db3ed313434c7e824339924c8df792.tar.gz ao-coverage-0d48769556db3ed313434c7e824339924c8df792.tar.bz2 ao-coverage-0d48769556db3ed313434c7e824339924c8df792.zip | |
Add format to head commit info
Diffstat (limited to 'src/metadata.ts')
| -rw-r--r-- | src/metadata.ts | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/src/metadata.ts b/src/metadata.ts index b7dbf19..6a0addc 100644 --- a/src/metadata.ts +++ b/src/metadata.ts @@ -5,8 +5,19 @@ import loggerConfig from "./util/logger"; import { BranchNotFoundError } from "./errors"; import { GradientStyle } from "./formats"; +interface HeadContext { + commit: string; + format: string; +} + +export const isError = ( + obj: HeadContext | BranchNotFoundError +): obj is BranchNotFoundError => { + return Object.keys(obj).includes("name"); +}; + interface Branch { - head: string; + head: HeadContext | string; } interface BranchList { @@ -17,7 +28,7 @@ export interface HeadIdentity { organization: string; repository: string; branch: string; - head: string; + head: HeadContext; } export interface Repository { @@ -73,7 +84,7 @@ class Metadata { organization: string, repository: string, branch: string - ): Promise<string | BranchNotFoundError> { + ): Promise<HeadContext | BranchNotFoundError> { const result = await this.database .collection<Repository>("repository") .findOne({ @@ -84,14 +95,18 @@ class Metadata { if (result !== null && Object.keys(result.branches).includes(branch)) { const limb = result.branches[branch]; + const head = typeof limb.head === "string" ? limb.head : limb.head.commit; + const format = + typeof limb.head === "string" ? "tarpaulin" : limb.head.format; logger.debug( - "Found commit %s for ORB %s/%s/%s", - limb.head, + "Found commit %s for ORB %s/%s/%s (format %s)", + head, organization, repository, - branch + branch, + format ); - return limb.head; + return { commit: head, format }; } else { return new BranchNotFoundError(); } |
