Skip to content

Commit

Permalink
fix: task assignee
Browse files Browse the repository at this point in the history
  • Loading branch information
Steveantor committed Sep 15, 2023
1 parent 3756a5c commit 1a58606
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/handlers/comment/handlers/assign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,18 @@ export const assign = async (body: string) => {
const comments = issueComments.sort((a: Comment, b: Comment) => new Date(b.created_at).getTime() - new Date(a.created_at).getTime());
const latestComment = comments.length > 0 ? comments[0].body : undefined;
if (latestComment && comment.commit != latestComment) {
const { multiplier, reason, bounty } = await getMultiplierInfoToDisplay(payload.sender.login, id?.toString(), issue);
const { multiplier, reason, bounty } = await getMultiplierInfoToDisplay(
payload.sender.login,
id?.toString(),
issue,
config.bountyRewardsCap.issue_assignee
);
return tableComment({ ...comment, multiplier, reason, bounty, isBountyStale, days }) + comment.tips;
}
return;
};

const getMultiplierInfoToDisplay = async (senderLogin: string, org_id: string, issue: Issue) => {
const getMultiplierInfoToDisplay = async (senderLogin: string, org_id: string, issue: Issue, cap: boolean) => {
const { reason, value } = await getWalletMultiplier(senderLogin, org_id);

const multiplier = value?.toFixed(2) || "1.00";
Expand All @@ -156,6 +161,9 @@ const getMultiplierInfoToDisplay = async (senderLogin: string, org_id: string, i
const issueDetailed = bountyInfo(issue);
if (issueDetailed.priceLabel) {
_bountyToDisplay = (+issueDetailed.priceLabel.substring(7, issueDetailed.priceLabel.length - 4) * value).toString() + " USD";
if (cap) {
_bountyToDisplay = (+issueDetailed.priceLabel.substring(7, issueDetailed.priceLabel.length - 4)).toString() + " USD" + " [Capped]";
}
}
}
return { multiplier: _multiplierToDisplay, reason: _reasonToDisplay, bounty: _bountyToDisplay };
Expand Down
7 changes: 7 additions & 0 deletions src/handlers/payout/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const handleIssueClosed = async () => {
payout: { paymentToken, rpc, permitBaseUrl, networkId, privateKey },
mode: { paymentPermitMaxPrice },
accessControl,
bountyRewardsCap: { issue_assignee },
} = getBotConfig();
const logger = getLogger();
const payload = context.payload as Payload;
Expand Down Expand Up @@ -183,6 +184,12 @@ export const handleIssueClosed = async () => {
priceInEth = new Decimal(ethers.utils.formatUnits(bountyAmountAfterPenalty, 18));
}

let labelAmount: Decimal | undefined = undefined;
if (issueDetailed.priceLabel) {
labelAmount = new Decimal(issueDetailed.priceLabel.substring(7, issueDetailed.priceLabel.length - 4));
}

priceInEth = issue_assignee && labelAmount !== undefined && priceInEth > labelAmount ? labelAmount : priceInEth;
const { txData, payoutUrl } = await generatePermit2Signature(recipient, priceInEth, issue.node_id, assignee.node_id, "ISSUE_ASSIGNEE");
const tokenSymbol = await getTokenSymbol(paymentToken, rpc);
const shortenRecipient = shortenEthAddress(recipient, `[ CLAIM ${priceInEth} ${tokenSymbol.toUpperCase()} ]`.length);
Expand Down
1 change: 1 addition & 0 deletions src/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ export type AccessControl = Static<typeof AccessControlSchema>;
export const BountyRewardsCapSchema = Type.Object({
issue_issuer: Type.Boolean(),
issue_collaborator: Type.Boolean(),
issue_assignee: Type.Boolean(),
issue_default: Type.Boolean(),
review_issuer: Type.Boolean(),
review_collaborator: Type.Boolean(),
Expand Down
1 change: 1 addition & 0 deletions ubiquibot-config-default.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
"bounty-rewards-cap": {
"issue_issuer": true,
"issue_collaborator": true,
"issue_assignee": true,
"issue_default": true,
"review_issuer": true,
"review_collaborator": true,
Expand Down

0 comments on commit 1a58606

Please sign in to comment.