-
Notifications
You must be signed in to change notification settings - Fork 26
/
getBranchStatus.ts
37 lines (34 loc) · 1.01 KB
/
getBranchStatus.ts
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
36
37
import * as git from "isomorphic-git"
import flatten from "lodash/flatten"
import { CommitDescription } from "../../types"
import { getHistory } from "./getHistory"
import { getRemotes } from "./getRemotes"
import { listRemoteBranches } from "./listBranches"
export async function getBranchStatus(
projectRoot: string
): Promise<{
currentBranch: string
branches: string[]
history: CommitDescription[]
remotes: string[]
remoteBranches: string[]
}> {
const currentBranch = await git.currentBranch({ dir: projectRoot })
const branches = await git.listBranches({ dir: projectRoot })
const remotes: string[] = (await git.listRemotes({ dir: projectRoot })).map(
(a: { remote: string; url: string }) => a.remote
)
const remoteBranches = flatten(
await Promise.all(
remotes.map(remote => listRemoteBranches(projectRoot, remote))
)
)
const history = await getHistory(projectRoot, { ref: currentBranch })
return {
currentBranch,
branches,
remotes,
remoteBranches,
history
}
}