Add new GitHub API client with functions for new MRVA flow (#1527)
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
import { Credentials } from '../../authentication';
|
||||
import { OctokitResponse } from '@octokit/types/dist-types';
|
||||
import { VariantAnalysisSubmission } from '../shared/variant-analysis';
|
||||
import {
|
||||
VariantAnalysis,
|
||||
VariantAnalysisRepoTask,
|
||||
VariantAnalysisSubmissionRequest
|
||||
} from './variant-analysis';
|
||||
|
||||
export async function submitVariantAnalysis(
|
||||
credentials: Credentials,
|
||||
submissionDetails: VariantAnalysisSubmission
|
||||
): Promise<VariantAnalysis> {
|
||||
const octokit = await credentials.getOctokit();
|
||||
|
||||
const { actionRepoRef, query, databases, controllerRepoId } = submissionDetails;
|
||||
|
||||
const data: VariantAnalysisSubmissionRequest = {
|
||||
action_repo_ref: actionRepoRef,
|
||||
language: query.language,
|
||||
query_pack: query.pack,
|
||||
repositories: databases.repositories,
|
||||
repository_lists: databases.repositoryLists,
|
||||
repository_owners: databases.repositoryOwners,
|
||||
};
|
||||
|
||||
const response: OctokitResponse<VariantAnalysis> = await octokit.request(
|
||||
'POST /repositories/:controllerRepoId/code-scanning/codeql/variant-analyses',
|
||||
{
|
||||
controllerRepoId,
|
||||
data
|
||||
}
|
||||
);
|
||||
|
||||
return response.data;
|
||||
}
|
||||
|
||||
export async function getVariantAnalysis(
|
||||
credentials: Credentials,
|
||||
controllerRepoId: number,
|
||||
variantAnalysisId: number
|
||||
): Promise<VariantAnalysis> {
|
||||
const octokit = await credentials.getOctokit();
|
||||
|
||||
const response: OctokitResponse<VariantAnalysis> = await octokit.request(
|
||||
'GET /repositories/:controllerRepoId/code-scanning/codeql/variant-analyses/:variantAnalysisId',
|
||||
{
|
||||
controllerRepoId,
|
||||
variantAnalysisId
|
||||
}
|
||||
);
|
||||
|
||||
return response.data;
|
||||
}
|
||||
|
||||
export async function getVariantAnalysisRepo(
|
||||
credentials: Credentials,
|
||||
controllerRepoId: number,
|
||||
variantAnalysisId: number,
|
||||
repoId: number
|
||||
): Promise<VariantAnalysisRepoTask> {
|
||||
const octokit = await credentials.getOctokit();
|
||||
|
||||
const response: OctokitResponse<VariantAnalysisRepoTask> = await octokit.request(
|
||||
'GET /repositories/:controllerRepoId/code-scanning/codeql/variant-analyses/:variantAnalysisId/repositories/:repoId',
|
||||
{
|
||||
controllerRepoId,
|
||||
variantAnalysisId,
|
||||
repoId
|
||||
}
|
||||
);
|
||||
|
||||
return response.data;
|
||||
}
|
||||
|
||||
export async function getRepositoryIdFromNwo(
|
||||
credentials: Credentials,
|
||||
owner: string,
|
||||
repo: string
|
||||
): Promise<number> {
|
||||
const octokit = await credentials.getOctokit();
|
||||
|
||||
const response = await octokit.rest.repos.get({ owner, repo });
|
||||
return response.data.id;
|
||||
}
|
||||
13
extensions/ql-vscode/src/remote-queries/gh-api/repository.ts
Normal file
13
extensions/ql-vscode/src/remote-queries/gh-api/repository.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
/**
|
||||
* Defines basic information about a repository.
|
||||
*
|
||||
* Different parts of the API may return different subsets of information
|
||||
* about a repository, but this model represents the very basic information
|
||||
* that will always be available.
|
||||
*/
|
||||
export interface Repository {
|
||||
id: number,
|
||||
name: string,
|
||||
full_name: string,
|
||||
private: boolean,
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
import { Repository } from './repository';
|
||||
|
||||
export interface VariantAnalysisSubmissionRequest {
|
||||
action_repo_ref: string,
|
||||
language: VariantAnalysisQueryLanguage,
|
||||
query_pack: string,
|
||||
repositories?: string[],
|
||||
repository_lists?: string[],
|
||||
repository_owners?: string[]
|
||||
}
|
||||
|
||||
export type VariantAnalysisQueryLanguage =
|
||||
| 'csharp'
|
||||
| 'cpp'
|
||||
| 'go'
|
||||
| 'java'
|
||||
| 'javascript'
|
||||
| 'python'
|
||||
| 'ruby';
|
||||
|
||||
export interface VariantAnalysis {
|
||||
id: number,
|
||||
controller_repo: Repository,
|
||||
actor_id: number,
|
||||
query_language: VariantAnalysisQueryLanguage,
|
||||
query_pack_url: string,
|
||||
status: VariantAnalysisStatus,
|
||||
actions_workflow_run_id?: number,
|
||||
failure_reason?: VariantAnalysisFailureReason,
|
||||
scanned_repositories?: VariantAnalysisScannedRepository[],
|
||||
skipped_repositories?: VariantAnalysisSkippedRepositories
|
||||
}
|
||||
|
||||
export type VariantAnalysisStatus =
|
||||
| 'in_progress'
|
||||
| 'completed';
|
||||
|
||||
export type VariantAnalysisFailureReason =
|
||||
| 'no_repos_queried'
|
||||
| 'internal_error';
|
||||
|
||||
export type VariantAnalysisRepoStatus =
|
||||
| 'pending'
|
||||
| 'in_progress'
|
||||
| 'succeeded'
|
||||
| 'failed'
|
||||
| 'canceled'
|
||||
| 'timed_out';
|
||||
|
||||
export interface VariantAnalysisScannedRepository {
|
||||
repository: Repository,
|
||||
analysis_status: VariantAnalysisRepoStatus,
|
||||
result_count?: number,
|
||||
artifact_size_in_bytes?: number,
|
||||
failure_message?: string
|
||||
}
|
||||
|
||||
export interface VariantAnalysisSkippedRepositoryGroup {
|
||||
repository_count: number,
|
||||
repositories: Array<{
|
||||
id?: number,
|
||||
full_name: string
|
||||
}>
|
||||
}
|
||||
|
||||
export interface VariantAnalysisRepoTask {
|
||||
repository: Repository,
|
||||
analysis_status: VariantAnalysisRepoStatus,
|
||||
artifact_size_in_bytes?: number,
|
||||
result_count?: number,
|
||||
failure_message?: string,
|
||||
database_commit_sha?: string,
|
||||
source_location_prefix?: string,
|
||||
artifact_url?: string
|
||||
}
|
||||
|
||||
export interface VariantAnalysisSkippedRepositories {
|
||||
access_mismatch_repos: VariantAnalysisSkippedRepositoryGroup,
|
||||
not_found_repos: VariantAnalysisSkippedRepositoryGroup,
|
||||
no_codeql_db_repos: VariantAnalysisSkippedRepositoryGroup,
|
||||
over_limit_repos: VariantAnalysisSkippedRepositoryGroup
|
||||
}
|
||||
@@ -72,3 +72,26 @@ export interface VariantAnalysisSkippedRepositoryGroup {
|
||||
fullName: string
|
||||
}>
|
||||
}
|
||||
|
||||
/**
|
||||
* Captures information needed to submit a variant
|
||||
* analysis for processing.
|
||||
*/
|
||||
export interface VariantAnalysisSubmission {
|
||||
startTime: number,
|
||||
controllerRepoId: number,
|
||||
actionRepoRef: string,
|
||||
query: {
|
||||
name: string,
|
||||
filePath: string,
|
||||
language: VariantAnalysisQueryLanguage,
|
||||
|
||||
// Base64 encoded query pack.
|
||||
pack: string,
|
||||
},
|
||||
databases: {
|
||||
repositories?: string[],
|
||||
repositoryLists?: string[],
|
||||
repositoryOwners?: string[],
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user