Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions openci-runner/firebase/functions/probot/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ import {
export const appFn: ApplicationFunction = (app: Probot) => {
app.log.info("Yay! The app was loaded!");

// This is for debugging.
app.on("issues.reopened", async (context: Context) => {
return context.octokit.rest.issues.createComment(
context.issue({ body: "Probot is working!" }),
);
});

app.on("workflow_job.queued", async (context) => {
console.log("workflow_job.queued");
console.info("workflow_job.queued has started");

if (
!process.env.HETZNER_API_KEY ||
Expand All @@ -45,24 +46,25 @@ export const appFn: ApplicationFunction = (app: Probot) => {
const repo = repository.name;

const hetznerResponse = await createServer(process.env.HETZNER_API_KEY);
console.info("Runner server has been created");
while (true) {
const status = await getServerStatusById(
hetznerResponse.serverId,
process.env.HETZNER_API_KEY,
);
if (status === "running") {
console.log("Server is now running!");
console.info("Runner server is now running!");
break;
} else {
console.log("Waiting for the server init. Will try again in 1 second");
console.info("Waiting for the server init. Will try again in 1 second");
await setTimeout(1000);
}
}
const ssh = new NodeSSH();
const maxRetry = 10;
let retryCount = 0;
while (retryCount < maxRetry) {
console.log("retry:", retryCount);
console.info("retry:", retryCount);
try {
const sshResult = await ssh.connect({
host: hetznerResponse.ipv4,
Expand All @@ -82,7 +84,7 @@ export const appFn: ApplicationFunction = (app: Probot) => {
);
await sshResult.execCommand("apt install tmux");
await sshResult.execCommand(initRunner(encodedJitConfig));
console.log("Successfully start openci runner");
console.info("Successfully start openci runner");
break;
} catch (e) {
console.log("error, will try again in 1 second", e);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion | 🟠 Major

エラーログをconsole.errorに変更してください。

エラー情報をログ出力する際は、console.errorを使用することで、ログレベルを適切に設定できます。

以下のdiffを適用してください:

-			console.log("error, will try again in 1 second", e);
+			console.error("error, will try again in 1 second", e);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
console.log("error, will try again in 1 second", e);
console.error("error, will try again in 1 second", e);
🤖 Prompt for AI Agents
In openci-runner/firebase/functions/probot/index.ts around line 90, replace the
console.log call used for error reporting with console.error so the error is
emitted at the correct log level; specifically, change the call to use
console.error and keep the same message and error argument (e.g.,
console.error("error, will try again in 1 second", e)) so the error details are
preserved in the log.

Expand All @@ -100,7 +102,7 @@ export const appFn: ApplicationFunction = (app: Probot) => {
});

app.on("workflow_job.completed", async (context) => {
console.log("workflow_job.completed");
console.info("workflow_job.completed event started");
if (!process.env.HETZNER_API_KEY) {
throw new Error("Required environment variables are missing");
}
Expand All @@ -115,10 +117,14 @@ export const appFn: ApplicationFunction = (app: Probot) => {
}
const defaultRunnerName = "OpenCI ランナー ";
const runnerId = runnerName?.replace(defaultRunnerName, "");
console.log("runner id", runnerId);
console.info("runner id", runnerId);

await deleteServer(runnerId, process.env.HETZNER_API_KEY);
console.log("Finish cleaning up");
try {
await deleteServer(runnerId, process.env.HETZNER_API_KEY);
console.info("Successfully deleted runner");
} catch (e) {
console.error(`Failed to delete a runner: ${runnerId}`, "Error:", e);
}
return;
});
};
Expand Down
2 changes: 2 additions & 0 deletions openci-runner/firebase/functions/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { onRequest } from "firebase-functions/https";
import { log } from "firebase-functions/logger";
import { defineSecret } from "firebase-functions/params";
import { createNodeMiddleware, createProbot } from "probot";
import { appFn } from "../probot/index.js";
Expand Down Expand Up @@ -26,6 +27,7 @@ export const githubWebhook = onRequest(
timeoutSeconds: 300,
},
async (req, res) => {
log("githubWebhook has started");
const probot = await createNodeMiddleware(appFn, {
probot: createProbot({
overrides: {
Expand Down