Skip to content

Commit 2c61866

Browse files
authored
Merge pull request #2030 from Urgau/concern-visual-rework
Bring concerns visual to modern GitHub UI feature
2 parents 2d73992 + ec863dc commit 2c61866

File tree

1 file changed

+46
-18
lines changed

1 file changed

+46
-18
lines changed

src/handlers/concern.rs

Lines changed: 46 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ struct ConcernData {
2121
#[derive(Debug, PartialEq, Eq, Clone, serde::Serialize, serde::Deserialize)]
2222
struct Concern {
2323
title: String,
24-
author: String,
2524
comment_url: String,
2625
status: ConcernStatus,
2726
}
@@ -44,7 +43,6 @@ pub(super) async fn handle_command(
4443
let Some(comment_url) = event.html_url() else {
4544
bail!("unable to retrieve the comment url")
4645
};
47-
let author = event.user().login.to_owned();
4846
let issue = &issue_comment.issue;
4947

5048
// Verify that this issue isn't a rfcbot FCP, skip if it is
@@ -100,7 +98,6 @@ pub(super) async fn handle_command(
10098
{
10199
concern_data.concerns.push(Concern {
102100
title,
103-
author,
104101
status: ConcernStatus::Active,
105102
comment_url: comment_url.to_string(),
106103
});
@@ -165,38 +162,47 @@ fn markdown_content(concerns: &[Concern], bot: &str) -> String {
165162
return "".to_string();
166163
}
167164

165+
let active_concerns = concerns
166+
.iter()
167+
.filter(|c| matches!(c.status, ConcernStatus::Active))
168+
.count();
169+
168170
let mut md = String::new();
169171

170-
let _ = writeln!(md, "\n# Concerns");
171172
let _ = writeln!(md, "");
172173

174+
if active_concerns > 0 {
175+
let _ = writeln!(md, "> [!CAUTION]");
176+
} else {
177+
let _ = writeln!(md, "> [!NOTE]");
178+
}
179+
180+
let _ = writeln!(md, "> # Concerns ({active_concerns} active)");
181+
let _ = writeln!(md, ">");
182+
173183
for &Concern {
174184
ref title,
175-
ref author,
176185
ref status,
177186
ref comment_url,
178187
} in concerns
179188
{
180189
let _ = match status {
181190
ConcernStatus::Active => {
182-
writeln!(
183-
md,
184-
" - [{title}]({comment_url}) by [{author}](https://github.com/{author})"
185-
)
191+
writeln!(md, "> - [{title}]({comment_url})")
186192
}
187193
ConcernStatus::Resolved {
188194
comment_url: resolved_comment_url,
189195
} => {
190196
writeln!(
191197
md,
192-
" - ~~[{title}]({comment_url}) by [{author}](https://github.com/{author})~~ resolved [in this comment]({resolved_comment_url})"
198+
"> - ~~[{title}]({comment_url})~~ resolved [in this comment]({resolved_comment_url})"
193199
)
194200
}
195201
};
196202
}
197203

198-
let _ = writeln!(md, "");
199-
let _ = writeln!(md, "*Managed by `@{bot}`—see [help](https://forge.rust-lang.org/triagebot/concern.html) for details.*");
204+
let _ = writeln!(md, ">");
205+
let _ = writeln!(md, "> *Managed by `@{bot}`—see [help](https://forge.rust-lang.org/triagebot/concern.html) for details.*");
200206

201207
md
202208
}
@@ -206,13 +212,11 @@ fn simple_markdown_content() {
206212
let concerns = &[
207213
Concern {
208214
title: "This is my concern about concern".to_string(),
209-
author: "Urgau".to_string(),
210215
status: ConcernStatus::Active,
211216
comment_url: "https://github.com/fake-comment-1234".to_string(),
212217
},
213218
Concern {
214219
title: "This is a resolved concern".to_string(),
215-
author: "Kobzol".to_string(),
216220
status: ConcernStatus::Resolved {
217221
comment_url: "https:://github.com/fake-comment-8888".to_string(),
218222
},
@@ -223,12 +227,36 @@ fn simple_markdown_content() {
223227
assert_eq!(
224228
markdown_content(concerns, "rustbot"),
225229
r#"
226-
# Concerns
230+
> [!CAUTION]
231+
> # Concerns (1 active)
232+
>
233+
> - [This is my concern about concern](https://github.com/fake-comment-1234)
234+
> - ~~[This is a resolved concern](https://github.com/fake-comment-4561)~~ resolved [in this comment](https:://github.com/fake-comment-8888)
235+
>
236+
> *Managed by `@rustbot`—see [help](https://forge.rust-lang.org/triagebot/concern.html) for details.*
237+
"#
238+
);
239+
}
227240

228-
- [This is my concern about concern](https://github.com/fake-comment-1234) by [Urgau](https://github.com/Urgau)
229-
- ~~[This is a resolved concern](https://github.com/fake-comment-4561) by [Kobzol](https://github.com/Kobzol)~~ resolved [in this comment](https:://github.com/fake-comment-8888)
241+
#[test]
242+
fn resolved_concerns_markdown_content() {
243+
let concerns = &[Concern {
244+
title: "This is a resolved concern".to_string(),
245+
status: ConcernStatus::Resolved {
246+
comment_url: "https:://github.com/fake-comment-8888".to_string(),
247+
},
248+
comment_url: "https://github.com/fake-comment-4561".to_string(),
249+
}];
230250

231-
*Managed by `@rustbot`—see [help](https://forge.rust-lang.org/triagebot/concern.html) for details.*
251+
assert_eq!(
252+
markdown_content(concerns, "rustbot"),
253+
r#"
254+
> [!NOTE]
255+
> # Concerns (0 active)
256+
>
257+
> - ~~[This is a resolved concern](https://github.com/fake-comment-4561)~~ resolved [in this comment](https:://github.com/fake-comment-8888)
258+
>
259+
> *Managed by `@rustbot`—see [help](https://forge.rust-lang.org/triagebot/concern.html) for details.*
232260
"#
233261
);
234262
}

0 commit comments

Comments
 (0)