Introduce createVariantAnalysis method in actions API
This will allow us to make an API call to cancel a variant analysis.
This commit is contained in:
@@ -9,6 +9,7 @@ import { RemoteQuery } from '../remote-query';
|
||||
import { RemoteQueryFailureIndexItem, RemoteQueryResultIndex, RemoteQuerySuccessIndexItem } from '../remote-query-result-index';
|
||||
import { getErrorMessage } from '../../pure/helpers-pure';
|
||||
import { unzipFile } from '../../pure/zip';
|
||||
import { VariantAnalysis } from '../shared/variant-analysis';
|
||||
|
||||
export const RESULT_INDEX_ARTIFACT_NAME = 'result-index';
|
||||
|
||||
@@ -94,6 +95,18 @@ export async function cancelRemoteQuery(
|
||||
}
|
||||
}
|
||||
|
||||
export async function cancelVariantAnalysis(
|
||||
credentials: Credentials,
|
||||
variantAnalysis: VariantAnalysis
|
||||
): Promise<void> {
|
||||
const octokit = await credentials.getOctokit();
|
||||
const { actionsWorkflowRunId, controllerRepo: { fullName } } = variantAnalysis;
|
||||
const response = await octokit.request(`POST /repos/${fullName}/actions/runs/${actionsWorkflowRunId}/cancel`);
|
||||
if (response.status >= 300) {
|
||||
throw new Error(`Error cancelling variant analysis: ${response.status} ${response?.data?.message || ''}`);
|
||||
}
|
||||
}
|
||||
|
||||
export async function downloadArtifactFromLink(
|
||||
credentials: Credentials,
|
||||
storagePath: string,
|
||||
|
||||
@@ -2,8 +2,14 @@ import { fail } from 'assert';
|
||||
import { expect } from 'chai';
|
||||
import * as sinon from 'sinon';
|
||||
import { Credentials } from '../../../../authentication';
|
||||
import { cancelRemoteQuery, getRepositoriesMetadata } from '../../../../remote-queries/gh-api/gh-actions-api-client';
|
||||
import {
|
||||
cancelRemoteQuery,
|
||||
cancelVariantAnalysis,
|
||||
getRepositoriesMetadata
|
||||
} from '../../../../remote-queries/gh-api/gh-actions-api-client';
|
||||
import { RemoteQuery } from '../../../../remote-queries/remote-query';
|
||||
import { createMockVariantAnalysis } from '../../../factories/remote-queries/shared/variant-analysis';
|
||||
import { VariantAnalysis } from '../../../../remote-queries/shared/variant-analysis';
|
||||
|
||||
describe('gh-actions-api-client mock responses', () => {
|
||||
let sandbox: sinon.SinonSandbox;
|
||||
@@ -50,6 +56,29 @@ describe('gh-actions-api-client mock responses', () => {
|
||||
} as unknown as RemoteQuery;
|
||||
}
|
||||
});
|
||||
|
||||
describe('cancelVariantAnalysis', () => {
|
||||
let variantAnalysis: VariantAnalysis;
|
||||
before(() => {
|
||||
variantAnalysis = createMockVariantAnalysis({});
|
||||
});
|
||||
|
||||
it('should cancel a variant analysis', async () => {
|
||||
mockResponse = sinon.stub().resolves({ status: 202 });
|
||||
await cancelVariantAnalysis(mockCredentials, variantAnalysis);
|
||||
|
||||
expect(mockResponse.calledOnce).to.be.true;
|
||||
expect(mockResponse.firstCall.args[0]).to.equal(`POST /repos/${variantAnalysis.controllerRepo.fullName}/actions/runs/${variantAnalysis.actionsWorkflowRunId}/cancel`);
|
||||
});
|
||||
|
||||
it('should fail to cancel a variant analysis', async () => {
|
||||
mockResponse = sinon.stub().resolves({ status: 409, data: { message: 'Uh oh!' } });
|
||||
|
||||
await expect(cancelVariantAnalysis(mockCredentials, variantAnalysis)).to.be.rejectedWith(/Error cancelling variant analysis: 409 Uh oh!/);
|
||||
expect(mockResponse.calledOnce).to.be.true;
|
||||
expect(mockResponse.firstCall.args[0]).to.equal(`POST /repos/${variantAnalysis.controllerRepo.fullName}/actions/runs/${variantAnalysis.actionsWorkflowRunId}/cancel`);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('gh-actions-api-client real responses', function() {
|
||||
|
||||
Reference in New Issue
Block a user