diff --git a/nodemon.json b/nodemon.json index 896c8ba..7792f1e 100644 --- a/nodemon.json +++ b/nodemon.json @@ -3,5 +3,5 @@ "watch": ["src/"], "ignore": ["test/", "node_modules/", ".git"], "ext": ".ts", - "exec": "node -r ts-node/register src/bot.ts" + "exec": "node -r ts-node/register -r dotenv/config src/bot.ts" } diff --git a/src/bot.ts b/src/bot.ts index 82849f9..3f07463 100644 --- a/src/bot.ts +++ b/src/bot.ts @@ -4,7 +4,7 @@ import { displayError, envVar } from "opstooling-js"; import { Probot, run } from "probot"; import { getTipSize, parseContributorAccount, tipUser } from "./tip"; -import { State } from "./types"; +import { ContributorAccount, State } from "./types"; const onIssueComment = async ( state: State, @@ -41,8 +41,19 @@ const onIssueComment = async ( return `You are not allowed to request a tip. Only members of ${allowedGitHubOrg}/${allowedGitHubTeam} are allowed.`; } - const contributorAccount = parseContributorAccount(pullRequestBody); - const tipSize = getTipSize(tipSizeInput); + let contributorAccount: ContributorAccount; + try { + contributorAccount = parseContributorAccount(pullRequestBody); + } catch (error) { + return error.message; + } + + let tipSize: string; + try { + tipSize = getTipSize(tipSizeInput); + } catch (error) { + return error.message; + } bot.log( `Valid command!\n${tipRequester} wants to tip ${contributorLogin} (${contributorAccount.address} on ${contributorAccount.network}) a ${tipSize} tip for pull request ${pullRequestUrl}.`, diff --git a/src/tip.ts b/src/tip.ts index 09e1dca..bc41ddd 100644 --- a/src/tip.ts +++ b/src/tip.ts @@ -83,7 +83,7 @@ export async function tipUser( const reason = `TO: ${contributor.githubUsername} FOR: ${pullRequestRepo}#${pullRequestNumber} (${tipSize})`; /* TODO before submitting, check tip does not already exist via a storage query. - TODO potentially prevent duplicates by also checking for reasons with the other sizes. */ + TODO potentially prevent duplicates by also checking for reasons with the other sizes. */ const unsub = await api.tx.tips .reportAwesome(reason, contributor.account.address) .signAndSend(botTipAccount, (result: SubmittableResult) => { @@ -95,7 +95,7 @@ export async function tipUser( unsub(); } }); - + await api.disconnect(); return { success: true, tipUrl }; } @@ -108,7 +108,7 @@ async function getContributorMetadata(state: State, contributor: Contributor): P switch (contributor.account.network) { case "localtest": { return { - provider: new WsProvider("ws://localhost:9944"), + provider: new WsProvider("ws://127.0.0.1:9944"), botTipAccount: keyring.addFromUri("//Alice", { name: "Alice default" }), tipUrl: "https://polkadot.js.org/apps/?rpc=ws%3A%2F%2F127.0.0.1%3A9944#/treasury/tips", };