Skip to content

Commit

Permalink
updated messages with reward info
Browse files Browse the repository at this point in the history
  • Loading branch information
akorchyn committed Oct 28, 2024
1 parent 192efd6 commit d923b2a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 16 deletions.
4 changes: 2 additions & 2 deletions Messages.staging.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ For contributors:
- Boast your contributions with a dynamic picture of your [Profile]({link}/profile/{pr_author_username})
For maintainers:
- Score pull requests that participate in the Race of Sloths
- Score pull requests that participate in the Race of Sloths and receive a reward
- Engage contributors with fair scoring and fast responses so they keep their streaks
- Promote the Race to the point where the Race starts promoting you
- Grow the community of your contributors
Expand Down Expand Up @@ -251,7 +251,7 @@ For contributors:
- Boast your contributions with a dynamic picture of your [Profile]({link}/profile/{pr_author_username})
For maintainers:
- Score pull requests that participate in the Race of Sloths
- Score pull requests that participate in the Race of Sloths and receive a reward
- Engage contributors with fair scoring and fast responses so they keep their streaks
- Promote the Race to the point where the Race starts promoting you
- Grow the community of your contributors
Expand Down
4 changes: 2 additions & 2 deletions Messages.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ For contributors:
- Boast your contributions with a dynamic picture of your [Profile]({link}/profile/{pr_author_username})
For maintainers:
- Score pull requests that participate in the Race of Sloths
- Score pull requests that participate in the Race of Sloths and receive a reward
- Engage contributors with fair scoring and fast responses so they keep their streaks
- Promote the Race to the point where the Race starts promoting you
- Grow the community of your contributors
Expand Down Expand Up @@ -251,7 +251,7 @@ For contributors:
- Boast your contributions with a dynamic picture of your [Profile]({link}/profile/{pr_author_username})
For maintainers:
- Score pull requests that participate in the Race of Sloths
- Score pull requests that participate in the Race of Sloths and receive a reward
- Engage contributors with fair scoring and fast responses so they keep their streaks
- Promote the Race to the point where the Race starts promoting you
- Grow the community of your contributors
Expand Down
46 changes: 34 additions & 12 deletions bot/src/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use rand::seq::SliceRandom;
use rand::thread_rng;
use serde::{Deserialize, Serialize};
use shared::github::PrMetadata;
use shared::{PRInfo, TimePeriod, User};
use shared::{PRInfo, Score, TimePeriod, User};
use std::collections::{HashMap, HashSet};
use std::fs;
use std::ops::Add;
Expand Down Expand Up @@ -387,25 +387,49 @@ impl MessageLoader {
anyhow::anyhow!("Constraint violation: final_data is None for executed PR")
})?;
message.push_str("\n\n");
message.push_str(&self.final_message(final_data)?)
message.push_str(&self.final_message(final_data, bot_name, check_info.votes.clone())?)
} else if !check_info.votes.is_empty() {
let score = check_info.average_score();
message.push_str("\n\n");
let rating = rating_breakthrough(score * 10, score, 0, 0, 0);
let final_common = self.get_message(MsgCategory::RatingMessagesCommon).format(
[("score", score.to_string()), ("rating", rating)]
.into_iter()
.collect(),
let rating_message = self.rating_message(
score.to_string(),
rating,
check_info.votes.clone(),
bot_name,
)?;
message.push_str("\n\n");
message.push_str(&final_common);
message.push_str(&rating_message);
}

message.push_str("\n</details>");

Ok(message)
}

fn rating_message(
&self,
score: String,
rating: String,
scorers: Vec<Score>,
bot_name: &str,
) -> anyhow::Result<String> {
let mut message = self
.get_message(MsgCategory::RatingMessagesCommon)
.format([("score", score), ("rating", rating)].into_iter().collect())?;

for scorer in scorers {
if scorer.user != bot_name {
message.push_str(&format!(
"\n@{} received 25 Sloth Points for reviewing and scoring this pull request.",
bot_name
));
}
}

Ok(message)
}

fn user_specific_message(&self, user: &User) -> String {
let timestamp = chrono::Utc::now().timestamp_nanos_opt().unwrap_or_default() as u64;
let current_period = TimePeriod::Month.time_string(timestamp);
Expand Down Expand Up @@ -484,6 +508,8 @@ impl MessageLoader {
total_lifetime_percent,
pr_number_this_week,
}: FinalMessageData,
bot_name: &str,
scorers: Vec<Score>,
) -> anyhow::Result<String> {
let rating = rating_breakthrough(
total_rating,
Expand All @@ -492,11 +518,7 @@ impl MessageLoader {
monthly_streak_bonus,
total_lifetime_percent,
);
let final_common = self.get_message(MsgCategory::RatingMessagesCommon).format(
[("score", score.to_string()), ("rating", rating)]
.into_iter()
.collect(),
)?;
let final_common = self.rating_message(score.to_string(), rating, scorers, bot_name)?;

let optional_message = if lifetime_percent_reward > 0 && total_lifetime_percent > 5 {
let rank: &str = match total_lifetime_percent {
Expand Down

0 comments on commit d923b2a

Please sign in to comment.