From 0d48769556db3ed313434c7e824339924c8df792 Mon Sep 17 00:00:00 2001 From: Kevin J Hoerr Date: Thu, 16 Sep 2021 16:52:14 -0400 Subject: Add format to head commit info --- src/metadata.ts | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) (limited to 'src/metadata.ts') 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 { + ): Promise { const result = await this.database .collection("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(); } -- cgit