Skip to content

Commit 45b12cb

Browse files
authored
Merge pull request #2065 from shard77/chore/typed-replace-functions
Typed-functions instead `const` + `replace` pattern when creating messages
2 parents 8535813 + dd2a7d8 commit 45b12cb

File tree

1 file changed

+26
-18
lines changed

1 file changed

+26
-18
lines changed

src/handlers/project_goals.rs

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,29 @@ const RUST_PROJECT_GOALS_REPO: &'static str = "rust-lang/rust-project-goals";
1717
const GOALS_STREAM: u64 = 435869; // #project-goals
1818
const C_TRACKING_ISSUE: &str = "C-tracking-issue";
1919

20-
const MESSAGE: &str = r#"
21-
Dear $OWNERS, it's been $DAYS days since the last update to your goal *$GOAL*.
20+
fn message(
21+
zulip_owners: &str,
22+
days: &str,
23+
issue_number: u64,
24+
issue_title: &str,
25+
next_update: &str,
26+
) -> String {
27+
format!(
28+
r#"
29+
Dear {zulip_owners}, it's been {days} days since the last update to your goal *{issue_title}*.
2230
23-
We will begin drafting the next blog post collecting goal updates $NEXT_UPDATE.
31+
We will begin drafting the next blog post collecting goal updates {next_update}.
2432
25-
Please comment on the github tracking issue goals#$GOALNUM before then. Thanks! <3
33+
Please comment on the github tracking issue goals#{issue_number} before then. Thanks! <3
2634
2735
Here is a suggested template for updates (feel free to drop the items that don't apply):
2836
2937
* **Key developments:** *What has happened since the last time. It's perfectly ok to list "nothing" if that's the truth, we know people get busy.*
3038
* **Blockers:** *List any Rust teams you are waiting on and what you are waiting for.*
3139
* **Help wanted:** *Are there places where you are looking for contribution or feedback from the broader community?*
32-
"#;
40+
"#
41+
)
42+
}
3343

3444
pub struct ProjectGoalsUpdateJob;
3545

@@ -146,19 +156,17 @@ pub async fn ping_project_goals_owners(
146156
continue;
147157
};
148158

149-
let message = MESSAGE
150-
.replace("$OWNERS", &zulip_owners)
151-
.replace(
152-
"$DAYS",
153-
&if comments <= 1 {
154-
"∞".to_string()
155-
} else {
156-
days_since_last_comment.to_string()
157-
},
158-
)
159-
.replace("$GOALNUM", &issue.number.to_string())
160-
.replace("$GOAL", &issue.title)
161-
.replace("$NEXT_UPDATE", next_update);
159+
let message = message(
160+
&zulip_owners,
161+
&if comments <= 1 {
162+
"∞".to_string()
163+
} else {
164+
days_since_last_comment.to_string()
165+
},
166+
issue.number,
167+
&issue.title,
168+
next_update,
169+
);
162170

163171
let zulip_req = crate::zulip::MessageApiRequest {
164172
recipient: Recipient::Stream {

0 commit comments

Comments
 (0)