Skip to content
This repository was archived by the owner on Mar 10, 2022. It is now read-only.

Commit 7c69503

Browse files
committed
fix: prepare for commit views
1 parent 5fde9ad commit 7c69503

2 files changed

Lines changed: 72 additions & 7 deletions

File tree

src/log.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,20 @@ const outputChannel = vscode.window.createOutputChannel('Sourcegraph')
44
export const log = {
55
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any
66
error: (what: string, error?: any): void => {
7-
const errorMessage =
8-
error instanceof Error
9-
? ` ${error.message} ${error.stack || ''}`
10-
: error !== undefined
11-
? ` ${JSON.stringify(error)}`
12-
: ''
13-
outputChannel.appendLine(`ERROR ${what}${errorMessage}`)
7+
outputChannel.appendLine(`ERROR ${errorMessage(what, error)}`)
148
},
159
appendLine: (message: string): void => {
1610
outputChannel.appendLine(message)
1711
},
1812
}
13+
14+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
15+
function errorMessage(what: string, error?: any): string {
16+
const errorMessage =
17+
error instanceof Error
18+
? ` ${error.message} ${error.stack || ''}`
19+
: error !== undefined
20+
? ` ${JSON.stringify(error)}`
21+
: ''
22+
return what + errorMessage
23+
}

src/queries/treeCommitsQuery.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import * as vscode from 'vscode'
2+
import { graphqlQuery } from './graphqlQuery'
3+
import gql from 'tagged-template-noop'
4+
import { log } from '../log'
5+
6+
export async function treeCommitsQuery(
7+
parameters: TreeCommitsParameters,
8+
token: vscode.CancellationToken
9+
): Promise<string[]> {
10+
const response = await graphqlQuery<TreeCommitsParameters, TreeCommitsResult>(
11+
gql`
12+
query TreeCommits($repositoryId: ID!, $revision: String!, $filePath: String, $first: Int) {
13+
node(id: $repositoryId) {
14+
... on Repository {
15+
commit(rev: $revision) {
16+
ancestors(first: $first, path: $filePath) {
17+
nodes {
18+
...GitCommitFields
19+
}
20+
}
21+
}
22+
}
23+
}
24+
}
25+
26+
fragment GitCommitFields on GitCommit {
27+
oid
28+
}
29+
`,
30+
parameters,
31+
token
32+
)
33+
34+
const result = response?.data?.node?.commit?.ancestors?.nodes?.flatMap(node => (node.oid ? [node.oid] : [])) || []
35+
log.appendLine(`TREE_COMMITS ${JSON.stringify(result)}`)
36+
return result
37+
}
38+
39+
export interface TreeCommitsParameters {
40+
repositoryId: string
41+
revision: string
42+
filePath: string
43+
first: number
44+
}
45+
46+
interface TreeCommitsResult {
47+
data?: {
48+
node?: {
49+
commit?: {
50+
ancestors?: {
51+
nodes?: TreeCommitNode[]
52+
}
53+
}
54+
}
55+
}
56+
}
57+
58+
interface TreeCommitNode {
59+
oid?: string
60+
}

0 commit comments

Comments
 (0)