fix: fix getToken function

This commit is contained in:
tdurieux
2021-09-09 12:07:06 +02:00
parent a9d45a150c
commit 17f7fdee7f
+13 -15
View File
@@ -51,26 +51,24 @@ export default abstract class GitHubBase {
}); });
} }
async getToken(owner?: string) { async getToken() {
if (owner) { const user = await UserModel.findOne({ id: this.repository.owner.id });
const user = await UserModel.findOne({ username: owner }); if (user && user.accessTokens.github) {
if (user && user.accessTokens.github) { return user.accessTokens.github as string;
return user.accessTokens.github as string;
}
} }
if (this.accessToken) { if (this.accessToken) {
try { try {
const app = new OAuthApp({ // const app = new OAuthApp({
clientType: "github-app", // clientType: "github-app",
clientId: config.CLIENT_ID, // clientId: config.CLIENT_ID,
clientSecret: config.CLIENT_SECRET, // clientSecret: config.CLIENT_SECRET,
}); // });
await app.checkToken({ // await app.checkToken({
token: this.accessToken, // token: this.accessToken,
}); // });
return this.accessToken; return this.accessToken;
} catch (error) { } catch (error) {
// console.debug("Token is invalid.", error); console.debug("[ERROR] Token is invalid", this.repository.repoId);
this.accessToken = config.GITHUB_TOKEN; this.accessToken = config.GITHUB_TOKEN;
} }
} }