Skip to content

Commit be2ca6c

Browse files
authored
Merge pull request #1689 from github/koesie10/move-create-gist-to-gh-api-client
Move `createGist` to `gh-api-client`
2 parents bf1e3c1 + 6ccaf53 commit be2ca6c

File tree

4 files changed

+25
-24
lines changed

4 files changed

+25
-24
lines changed

extensions/ql-vscode/src/remote-queries/export-results.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { UserCancellationException } from '../commandRunner';
77
import { showInformationMessageWithAction } from '../helpers';
88
import { logger } from '../logging';
99
import { QueryHistoryManager } from '../query-history';
10-
import { createGist } from './gh-api/gh-actions-api-client';
10+
import { createGist } from './gh-api/gh-api-client';
1111
import { RemoteQueriesManager } from './remote-queries-manager';
1212
import { generateMarkdown } from './remote-queries-markdown-generation';
1313
import { RemoteQuery } from './remote-query';

extensions/ql-vscode/src/remote-queries/gh-api/gh-actions-api-client.ts

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -332,27 +332,6 @@ function getWorkflowError(conclusion: string | null): string {
332332
return `Unexpected variant analysis execution conclusion: ${conclusion}`;
333333
}
334334

335-
/**
336-
* Creates a gist with the given description and files.
337-
* Returns the URL of the created gist.
338-
*/
339-
export async function createGist(
340-
credentials: Credentials,
341-
description: string,
342-
files: { [key: string]: { content: string } }
343-
): Promise<string | undefined> {
344-
const octokit = await credentials.getOctokit();
345-
const response = await octokit.request('POST /gists', {
346-
description,
347-
files,
348-
public: false,
349-
});
350-
if (response.status >= 300) {
351-
throw new Error(`Error exporting variant analysis results: ${response.status} ${response?.data || ''}`);
352-
}
353-
return response.data.html_url;
354-
}
355-
356335
const repositoriesMetadataQuery = `query Stars($repos: String!, $pageSize: Int!, $cursor: String) {
357336
search(
358337
query: $repos

extensions/ql-vscode/src/remote-queries/gh-api/gh-api-client.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,25 @@ export async function getRepositoryFromNwo(
9494
const response = await octokit.rest.repos.get({ owner, repo });
9595
return response.data as Repository;
9696
}
97+
98+
99+
/**
100+
* Creates a gist with the given description and files.
101+
* Returns the URL of the created gist.
102+
*/
103+
export async function createGist(
104+
credentials: Credentials,
105+
description: string,
106+
files: { [key: string]: { content: string } }
107+
): Promise<string | undefined> {
108+
const octokit = await credentials.getOctokit();
109+
const response = await octokit.request('POST /gists', {
110+
description,
111+
files,
112+
public: false,
113+
});
114+
if (response.status >= 300) {
115+
throw new Error(`Error exporting variant analysis results: ${response.status} ${response?.data || ''}`);
116+
}
117+
return response.data.html_url;
118+
}

extensions/ql-vscode/src/vscode-tests/no-workspace/remote-queries/export-results.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { ExtensionContext } from 'vscode';
77
import { createMockExtensionContext } from '../index';
88
import { Credentials } from '../../../authentication';
99
import { MarkdownFile } from '../../../remote-queries/remote-queries-markdown-generation';
10-
import * as actionsApiClient from '../../../remote-queries/gh-api/gh-actions-api-client';
10+
import * as ghApiClient from '../../../remote-queries/gh-api/gh-api-client';
1111
import { exportResultsToGist } from '../../../remote-queries/export-results';
1212

1313
const proxyquire = pq.noPreserveCache();
@@ -41,7 +41,7 @@ describe('export results', async function() {
4141
});
4242

4343
it('should call the GitHub Actions API with the correct gist title', async function() {
44-
mockCreateGist = sinon.stub(actionsApiClient, 'createGist');
44+
mockCreateGist = sinon.stub(ghApiClient, 'createGist');
4545

4646
ctx = createMockExtensionContext();
4747
const query = JSON.parse(await fs.readFile(path.join(__dirname, '../data/remote-queries/query-with-results/query.json'), 'utf8'));

0 commit comments

Comments
 (0)