Merge pull request #1689 from github/koesie10/move-create-gist-to-gh-api-client

Move `createGist` to `gh-api-client`
This commit is contained in:
Koen Vlaswinkel
2022-11-01 11:03:00 +01:00
committed by GitHub
4 changed files with 25 additions and 24 deletions

View File

@@ -7,7 +7,7 @@ import { UserCancellationException } from '../commandRunner';
import { showInformationMessageWithAction } from '../helpers';
import { logger } from '../logging';
import { QueryHistoryManager } from '../query-history';
import { createGist } from './gh-api/gh-actions-api-client';
import { createGist } from './gh-api/gh-api-client';
import { RemoteQueriesManager } from './remote-queries-manager';
import { generateMarkdown } from './remote-queries-markdown-generation';
import { RemoteQuery } from './remote-query';

View File

@@ -332,27 +332,6 @@ function getWorkflowError(conclusion: string | null): string {
return `Unexpected variant analysis execution conclusion: ${conclusion}`;
}
/**
* Creates a gist with the given description and files.
* Returns the URL of the created gist.
*/
export async function createGist(
credentials: Credentials,
description: string,
files: { [key: string]: { content: string } }
): Promise<string | undefined> {
const octokit = await credentials.getOctokit();
const response = await octokit.request('POST /gists', {
description,
files,
public: false,
});
if (response.status >= 300) {
throw new Error(`Error exporting variant analysis results: ${response.status} ${response?.data || ''}`);
}
return response.data.html_url;
}
const repositoriesMetadataQuery = `query Stars($repos: String!, $pageSize: Int!, $cursor: String) {
search(
query: $repos

View File

@@ -94,3 +94,25 @@ export async function getRepositoryFromNwo(
const response = await octokit.rest.repos.get({ owner, repo });
return response.data as Repository;
}
/**
* Creates a gist with the given description and files.
* Returns the URL of the created gist.
*/
export async function createGist(
credentials: Credentials,
description: string,
files: { [key: string]: { content: string } }
): Promise<string | undefined> {
const octokit = await credentials.getOctokit();
const response = await octokit.request('POST /gists', {
description,
files,
public: false,
});
if (response.status >= 300) {
throw new Error(`Error exporting variant analysis results: ${response.status} ${response?.data || ''}`);
}
return response.data.html_url;
}

View File

@@ -7,7 +7,7 @@ import { ExtensionContext } from 'vscode';
import { createMockExtensionContext } from '../index';
import { Credentials } from '../../../authentication';
import { MarkdownFile } from '../../../remote-queries/remote-queries-markdown-generation';
import * as actionsApiClient from '../../../remote-queries/gh-api/gh-actions-api-client';
import * as ghApiClient from '../../../remote-queries/gh-api/gh-api-client';
import { exportResultsToGist } from '../../../remote-queries/export-results';
const proxyquire = pq.noPreserveCache();
@@ -41,7 +41,7 @@ describe('export results', async function() {
});
it('should call the GitHub Actions API with the correct gist title', async function() {
mockCreateGist = sinon.stub(actionsApiClient, 'createGist');
mockCreateGist = sinon.stub(ghApiClient, 'createGist');
ctx = createMockExtensionContext();
const query = JSON.parse(await fs.readFile(path.join(__dirname, '../data/remote-queries/query-with-results/query.json'), 'utf8'));