Skip to content

Commit 933443c

Browse files
committed
Print commit comment payments in USD.
1 parent c31022f commit 933443c

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

src/main/java/org/whispersystems/bithub/controllers/GithubController.java

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -96,17 +96,20 @@ public void handleCommits(@HeaderParam("X-Forwarded-For") String clientIp,
9696
throw new UnauthorizedHookException("Not a valid repository: " + event.getRepository().getUrl());
9797
}
9898

99-
Repository repository = event.getRepository();
100-
List<Commit> commits = getQualifyingCommits(event);
101-
BigDecimal balance = coinbaseClient.getAccountBalance();
99+
Repository repository = event.getRepository();
100+
List<Commit> commits = getQualifyingCommits(event);
101+
BigDecimal balance = coinbaseClient.getAccountBalance();
102+
BigDecimal exchangeRate = coinbaseClient.getExchangeRate();
102103

103104
logger.info("Retrieved balance: " + balance.toPlainString());
104105

105-
sendPaymentsFor(repository, commits, balance);
106+
sendPaymentsFor(repository, commits, balance, exchangeRate);
106107
}
107108

108109

109-
private void sendPaymentsFor(Repository repository, List<Commit> commits, BigDecimal balance) {
110+
private void sendPaymentsFor(Repository repository, List<Commit> commits,
111+
BigDecimal balance, BigDecimal exchangeRate)
112+
{
110113
for (Commit commit : commits) {
111114
try {
112115
BigDecimal payout = balance.multiply(payoutRate);
@@ -116,7 +119,9 @@ private void sendPaymentsFor(Repository repository, List<Commit> commits, BigDec
116119
}
117120

118121
balance = balance.subtract(payout);
119-
githubClient.addCommitComment(repository, commit, getCommitCommentStringForPayment(payout));
122+
123+
githubClient.addCommitComment(repository, commit,
124+
getCommitCommentStringForPayment(payout, exchangeRate));
120125
} catch (TransferFailedException e) {
121126
logger.warn("Transfer failed", e);
122127
}
@@ -156,10 +161,10 @@ private boolean isViablePaymentAmount(BigDecimal payment) {
156161
return payment.compareTo(new BigDecimal(0)) == 1;
157162
}
158163

159-
private String getCommitCommentStringForPayment(BigDecimal payment) {
164+
private String getCommitCommentStringForPayment(BigDecimal payment, BigDecimal exchangeRate) {
160165
if (isViablePaymentAmount(payment)) {
161-
payment = payment.setScale(2, RoundingMode.CEILING);
162-
return "Thanks! BitHub has sent payment of $" + payment.toPlainString() + "USD for this commit.";
166+
BigDecimal paymentUsd = payment.multiply(exchangeRate).setScale(2, RoundingMode.CEILING);
167+
return "Thanks! BitHub has sent payment of $" + paymentUsd.toPlainString() + "USD for this commit.";
163168
} else {
164169
return "Thanks! Unfortunately our BitHub balance is $0.00, so no payout can be made.";
165170
}

0 commit comments

Comments
 (0)