Skip to content

Commit

Permalink
chore: wrap octokit init
Browse files Browse the repository at this point in the history
  • Loading branch information
Keyrxng committed Oct 28, 2024
1 parent bb1bff5 commit bca162d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
1 change: 0 additions & 1 deletion src/handlers/workflow-proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ export function proxyWorkflowCallbacks(context: Context): ProxyCallbacks {
for (const r of res) {
if (r.status !== 200) {
await bubbleUpErrorComment(context, new Error(r.reason));
await exit(1);
}
}
await exit(0);
Expand Down
15 changes: 9 additions & 6 deletions src/types/plugin-context-single.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,15 @@ export class PluginContext {
async getTelegramEventOctokit(): Promise<RestOctokitFromApp> {
let octokit: RestOctokitFromApp | null = null;

await this.getApp().eachInstallation(async (installation) => {
if (installation.installation.account?.login === this.config.storageOwner) {
octokit = installation.octokit;
}
});

try {
await this.getApp().eachInstallation(async (installation) => {
if (installation.installation.account?.login === this.config.storageOwner) {
octokit = installation.octokit;
}
});
} catch (er) {
logger.error("Error initializing octokit in getTelegramEventOctokit", { er });
}
if (!octokit) {
throw new Error("Octokit could not be initialized");
}
Expand Down
4 changes: 4 additions & 0 deletions src/types/telegram-bot-single.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ export class TelegramBotSingleton {

const octokit = await PluginContext.getInstance().getTelegramEventOctokit();

if (!octokit) {
throw new Error("octokit could not be initialized");
}

if (!TelegramBotSingleton._instance) {
TelegramBotSingleton._instance = new TelegramBotSingleton();
try {
Expand Down

0 comments on commit bca162d

Please sign in to comment.