-
Notifications
You must be signed in to change notification settings - Fork 226
Expand file tree
/
Copy pathgh-api-client.ts
More file actions
113 lines (99 loc) · 3.11 KB
/
gh-api-client.ts
File metadata and controls
113 lines (99 loc) · 3.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import type { OctokitResponse } from "@octokit/types/dist-types";
import type { Credentials } from "../../common/authentication";
import type { VariantAnalysisSubmission } from "../shared/variant-analysis";
import type {
VariantAnalysis,
VariantAnalysisRepoTask,
VariantAnalysisSubmissionRequest,
} from "./variant-analysis";
import type { Repository } from "./repository";
export async function submitVariantAnalysis(
credentials: Credentials,
submissionDetails: VariantAnalysisSubmission,
): Promise<VariantAnalysis> {
const octokit = await credentials.getOctokit();
const { actionRepoRef, language, pack, databases, controllerRepoId } =
submissionDetails;
const data: VariantAnalysisSubmissionRequest = {
action_repo_ref: actionRepoRef,
language,
query_pack: 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 getRepositoryFromNwo(
credentials: Credentials,
owner: string,
repo: string,
): Promise<Repository> {
const octokit = await credentials.getOctokit();
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} ${JSON.stringify(
response?.data,
)}`,
);
}
return response.data.html_url;
}