1- // TODO: This file is allllll copypasta (kind of)!
2-
3- import * as sourcegraph from 'sourcegraph'
1+ import { queryGraphQL } from '../graphql'
42import { createAggregateError } from './errors'
53
6- async function queryGraphQL ( query : string , variables : any = { } ) {
7- return sourcegraph . commands . executeCommand < any > ( 'queryGraphQL' , query , variables )
8- }
9-
104const discussionCommentFieldsFragment = `
115 fragment DiscussionCommentFields on DiscussionComment {
126 id
@@ -21,7 +15,7 @@ const discussionCommentFieldsFragment = `
2115 `
2216
2317function discussionThreadFieldsFragment ( relativeRev ?: string ) : string {
24- var relativeRevFields : string = ''
18+ let relativeRevFields = ''
2519 if ( relativeRev ) {
2620 relativeRevFields = `
2721 relativePath(rev: $relativeRev)
@@ -84,11 +78,11 @@ function discussionThreadFieldsFragment(relativeRev?: string): string {
8478 *
8579 * @return Promise that emits the new discussion thread.
8680 */
87- async function createThread (
81+ export async function createThread (
8882 input : SourcegraphGQL . IDiscussionThreadCreateInput ,
89- relativeRev : string = ''
83+ relativeRev = ''
9084) : Promise < SourcegraphGQL . IDiscussionThread > {
91- let { data, errors } = await queryGraphQL (
85+ const { data, errors } = await queryGraphQL (
9286 `
9387 mutation CreateThread($input: DiscussionThreadCreateInput!, $relativeRev: String!) {
9488 discussions {
@@ -125,7 +119,7 @@ export async function fetchDiscussionThreads(opts: {
125119 relativeRev ?: string
126120} ) : Promise < SourcegraphGQL . IDiscussionThreadConnection > {
127121 opts . relativeRev = opts . relativeRev || ''
128- let { data, errors } = await queryGraphQL (
122+ const { data, errors } = await queryGraphQL (
129123 `
130124 query DiscussionThreads(
131125 $first: Int
@@ -175,9 +169,9 @@ export async function fetchDiscussionThreads(opts: {
175169 */
176170export async function fetchDiscussionThreadAndComments (
177171 threadID : string ,
178- relativeRev : string = ''
172+ relativeRev = ''
179173) : Promise < SourcegraphGQL . IDiscussionThread > {
180- let { data, errors } = await queryGraphQL (
174+ const { data, errors } = await queryGraphQL (
181175 `
182176 query DiscussionThreadComments($threadID: ID!, $relativeRev: String!) {
183177 discussionThreads(threadID: $threadID) {
@@ -217,9 +211,9 @@ export async function fetchDiscussionThreadAndComments(
217211export async function addCommentToThread (
218212 threadID : string ,
219213 contents : string ,
220- relativeRev : string = ''
214+ relativeRev = ''
221215) : Promise < SourcegraphGQL . IDiscussionThread > {
222- let { data, errors } = await queryGraphQL (
216+ const { data, errors } = await queryGraphQL (
223217 `
224218 mutation AddCommentToThread($threadID: ID!, $contents: String!, $relativeRev: String!) {
225219 discussions {
@@ -251,7 +245,7 @@ export async function addCommentToThread(
251245 * @return Promise that emits the HTML string, which is already sanitized and escaped and thus is always safe to render.
252246 */
253247export async function renderMarkdown ( markdown : string , options ?: SourcegraphGQL . IMarkdownOptions ) : Promise < string > {
254- let { data, errors } = await queryGraphQL (
248+ const { data, errors } = await queryGraphQL (
255249 `
256250 query RenderMarkdown($markdown: String!, $options: MarkdownOptions) {
257251 renderMarkdown(markdown: $markdown, options: $options)
0 commit comments