Skip to content

Commit

Permalink
Merge pull request ubiquity-os-marketplace#23 from ubq-testing/gh-sto…
Browse files Browse the repository at this point in the history
…rage

chore: add token fallback, add debug log
  • Loading branch information
Keyrxng authored Oct 29, 2024
2 parents a01828b + e376ca3 commit 103bd38
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,4 @@
"@commitlint/config-conventional"
]
}
}
}
1 change: 1 addition & 0 deletions src/types/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export const env = T.Object({
.Encode((obj) => JSON.stringify(obj)),
APP_ID: T.String(),
APP_PRIVATE_KEY: T.String(),
TEMP_SAFE_PAT: T.Optional(T.String()),
});

export type Env = StaticDecode<typeof env>;
Expand Down
16 changes: 13 additions & 3 deletions src/types/plugin-context-single.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,27 @@ export class PluginContext {
* This can be used with events from both Telegram and GitHub, this token comes from
* the worker's environment variables i.e the Storage App.
*/
async getTelegramEventOctokit(): Promise<RestOctokitFromApp | null> {
let octokit: RestOctokitFromApp | null = null;
async getTelegramEventOctokit(): Promise<RestOctokitFromApp | Octokit | null> {
let octokit: RestOctokitFromApp | Octokit | null = null;

try {
await this.getApp().eachInstallation((installation) => {
logger.info("Checking installation", { installation: installation.installation.account?.login, storageOwner: this.config.storageOwner });
if (installation.installation.account?.login.toLowerCase() === this.config.storageOwner.toLowerCase()) {
octokit = installation.octokit;
}
});
} catch (er) {
logger.error("Error initializing octokit in getTelegramEventOctokit", { er });
logger.error("Error initializing octokit in getTelegramEventOctokit", { er: String(er) });
}

if (!octokit) {
logger.info("Falling back to TEMP_SAFE_PAT for octokit");
octokit = new Octokit({ auth: this.env.TEMP_SAFE_PAT });
}

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

return octokit;
Expand Down

0 comments on commit 103bd38

Please sign in to comment.