Move createGist to gh-api-client
The `createGist` functionw was part of `gh-actions-api-client`, while it didn't actually involve anything related to the GitHub Actions API. This moves it to the non-Actions-specific `gh-api-client` module. Another candidate for moving to `gh-api-client` is `getRepositoriesMetadata`, but that one is a bit more involved since it uses `showAndLogErrorMessage`, so depends on the `vscode` module. This means it would not be possible to test in the "pure" tests and we would need to move all our `gh-actions-api` tests to the integration tests. It will not be used for variant analysis queries anymore, so I don't think it's worth moving or refactoring to not depend on `vscode`.
This commit is contained in:
@@ -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';
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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'));
|
||||
|
||||
Reference in New Issue
Block a user