File size: 1,057 Bytes
e079a73
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
export type AppBuildInfo = {
  appVersion: string
  buildCommit: string
  buildBranch: string
  buildTime: string
  buildUser: string
}

export function packagedBuildInfo(extra: Record<string, unknown> | undefined, embedded: AppBuildInfo): AppBuildInfo {
  const contract = extra?.mentraPrBuild
  if (
    !contract ||
    typeof contract !== "object" ||
    !("schemaVersion" in contract) ||
    contract.schemaVersion !== 1 ||
    !("buildInfo" in contract)
  )
    return embedded
  const info = contract.buildInfo
  if (!info || typeof info !== "object") return embedded
  if (
    !("commit" in info) ||
    typeof info.commit !== "string" ||
    !/^[a-f0-9]{40}$/.test(info.commit) ||
    !("branch" in info) ||
    typeof info.branch !== "string" ||
    !("time" in info) ||
    typeof info.time !== "string" ||
    !("user" in info) ||
    typeof info.user !== "string"
  )
    return embedded
  return {...embedded, buildCommit: info.commit, buildBranch: info.branch, buildTime: info.time, buildUser: info.user}
}