pull/479/head
Frostebite 2023-01-18 23:54:32 +00:00
parent 82a15648fa
commit f02e56a610
4 changed files with 101 additions and 67 deletions

81
dist/index.js vendored
View File

@ -584,7 +584,14 @@ class Cli {
}
static checksUpdate() {
return __awaiter(this, void 0, void 0, function* () {
core.info(`Checks Update`);
const input = JSON.parse(process.env.CHECKS_UPDATE || ``);
core.info(`Checks Update ${input}`);
if (input.mode === `create`) {
yield github_1.default.createGitHubCheckRequest(input.data);
}
else if (input.mode === `update`) {
yield github_1.default.updateGitHubCheckRequest(input.data);
}
});
}
static GarbageCollect() {
@ -6420,39 +6427,10 @@ class GitHub {
yield GitHub.runUpdateAsyncChecksWorkflow(data, `update`);
return;
}
const result = yield GitHub.octokit.request(`POST /repos/${GitHub.owner}/${GitHub.repo}/check-runs`, data);
const result = yield GitHub.createGitHubCheckRequest(data);
return result.data.id;
});
}
static runUpdateAsyncChecksWorkflow(data, mode) {
return __awaiter(this, void 0, void 0, function* () {
const workflowsResult = yield GitHub.octokit.request(`GET /repos/${GitHub.owner}/${GitHub.repo}/actions/workflows`, {
owner: GitHub.owner,
repo: GitHub.repo,
});
const workflows = workflowsResult.data.workflows;
let selectedId = ``;
for (let index = 0; index < workflowsResult.data.total_count; index++) {
if (workflows[index].name === `Async Checks API`) {
selectedId = workflows[index].id;
}
}
if (selectedId === ``) {
core.info(JSON.stringify(workflows));
throw new Error(`no workflow with name "Async Checks API"`);
}
yield GitHub.octokit.request(`POST /repos/{owner}/{repo}/actions/workflows/{workflow_id}/dispatches`, {
owner: GitHub.owner,
repo: GitHub.repo,
// eslint-disable-next-line camelcase
workflow_id: selectedId,
ref: cloud_runner_options_1.default.branch,
inputs: {
checksObject: JSON.stringify({ data, mode }),
},
});
});
}
static updateGitHubCheck(longDescription, summary, result = `neutral`, status = `in_progress`) {
return __awaiter(this, void 0, void 0, function* () {
if (!cloud_runner_options_1.default.githubChecks) {
@ -6489,7 +6467,46 @@ class GitHub {
yield GitHub.runUpdateAsyncChecksWorkflow(data, `update`);
return;
}
yield GitHub.octokit.request(`PATCH /repos/${GitHub.owner}/${GitHub.repo}/check-runs/${GitHub.checkRunId}`, data);
yield GitHub.updateGitHubCheckRequest(data);
});
}
static updateGitHubCheckRequest(data) {
return __awaiter(this, void 0, void 0, function* () {
return yield GitHub.octokit.request(`PATCH /repos/${GitHub.owner}/${GitHub.repo}/check-runs/${GitHub.checkRunId}`, data);
});
}
static createGitHubCheckRequest(data) {
return __awaiter(this, void 0, void 0, function* () {
return yield GitHub.octokit.request(`POST /repos/${GitHub.owner}/${GitHub.repo}/check-runs`, data);
});
}
static runUpdateAsyncChecksWorkflow(data, mode) {
return __awaiter(this, void 0, void 0, function* () {
const workflowsResult = yield GitHub.octokit.request(`GET /repos/${GitHub.owner}/${GitHub.repo}/actions/workflows`, {
owner: GitHub.owner,
repo: GitHub.repo,
});
const workflows = workflowsResult.data.workflows;
let selectedId = ``;
for (let index = 0; index < workflowsResult.data.total_count; index++) {
if (workflows[index].name === `Async Checks API`) {
selectedId = workflows[index].id;
}
}
if (selectedId === ``) {
core.info(JSON.stringify(workflows));
throw new Error(`no workflow with name "Async Checks API"`);
}
yield GitHub.octokit.request(`POST /repos/{owner}/{repo}/actions/workflows/{workflow_id}/dispatches`, {
owner: GitHub.owner,
repo: GitHub.repo,
// eslint-disable-next-line camelcase
workflow_id: selectedId,
ref: cloud_runner_options_1.default.branch,
inputs: {
checksObject: JSON.stringify({ data, mode }),
},
});
});
}
}

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

View File

@ -119,7 +119,13 @@ export class Cli {
@CliFunction(`checks-update`, `runs a cloud runner build`)
public static async checksUpdate() {
core.info(`Checks Update`);
const input = JSON.parse(process.env.CHECKS_UPDATE || ``);
core.info(`Checks Update ${input}`);
if (input.mode === `create`) {
await GitHub.createGitHubCheckRequest(input.data);
} else if (input.mode === `update`) {
await GitHub.updateGitHubCheckRequest(input.data);
}
}
@CliFunction(`garbage-collect`, `runs garbage collection`)

View File

@ -75,42 +75,11 @@ class GitHub {
return;
}
const result = await GitHub.octokit.request(`POST /repos/${GitHub.owner}/${GitHub.repo}/check-runs`, data);
const result = await GitHub.createGitHubCheckRequest(data);
return result.data.id;
}
public static async runUpdateAsyncChecksWorkflow(data, mode) {
const workflowsResult = await GitHub.octokit.request(
`GET /repos/${GitHub.owner}/${GitHub.repo}/actions/workflows`,
{
owner: GitHub.owner,
repo: GitHub.repo,
},
);
const workflows = workflowsResult.data.workflows;
let selectedId = ``;
for (let index = 0; index < workflowsResult.data.total_count; index++) {
if (workflows[index].name === `Async Checks API`) {
selectedId = workflows[index].id;
}
}
if (selectedId === ``) {
core.info(JSON.stringify(workflows));
throw new Error(`no workflow with name "Async Checks API"`);
}
await GitHub.octokit.request(`POST /repos/{owner}/{repo}/actions/workflows/{workflow_id}/dispatches`, {
owner: GitHub.owner,
repo: GitHub.repo,
// eslint-disable-next-line camelcase
workflow_id: selectedId,
ref: CloudRunnerOptions.branch,
inputs: {
checksObject: JSON.stringify({ data, mode }),
},
});
}
public static async updateGitHubCheck(longDescription, summary, result = `neutral`, status = `in_progress`) {
if (!CloudRunnerOptions.githubChecks) {
return;
@ -150,7 +119,49 @@ class GitHub {
return;
}
await GitHub.octokit.request(`PATCH /repos/${GitHub.owner}/${GitHub.repo}/check-runs/${GitHub.checkRunId}`, data);
await GitHub.updateGitHubCheckRequest(data);
}
public static async updateGitHubCheckRequest(data) {
return await GitHub.octokit.request(
`PATCH /repos/${GitHub.owner}/${GitHub.repo}/check-runs/${GitHub.checkRunId}`,
data,
);
}
public static async createGitHubCheckRequest(data) {
return await GitHub.octokit.request(`POST /repos/${GitHub.owner}/${GitHub.repo}/check-runs`, data);
}
public static async runUpdateAsyncChecksWorkflow(data, mode) {
const workflowsResult = await GitHub.octokit.request(
`GET /repos/${GitHub.owner}/${GitHub.repo}/actions/workflows`,
{
owner: GitHub.owner,
repo: GitHub.repo,
},
);
const workflows = workflowsResult.data.workflows;
let selectedId = ``;
for (let index = 0; index < workflowsResult.data.total_count; index++) {
if (workflows[index].name === `Async Checks API`) {
selectedId = workflows[index].id;
}
}
if (selectedId === ``) {
core.info(JSON.stringify(workflows));
throw new Error(`no workflow with name "Async Checks API"`);
}
await GitHub.octokit.request(`POST /repos/{owner}/{repo}/actions/workflows/{workflow_id}/dispatches`, {
owner: GitHub.owner,
repo: GitHub.repo,
// eslint-disable-next-line camelcase
workflow_id: selectedId,
ref: CloudRunnerOptions.branch,
inputs: {
checksObject: JSON.stringify({ data, mode }),
},
});
}
}