11use crate :: github:: client:: { Client , GraphQLClient , ResponseComment } ;
22use crate :: request_handlers:: parse_unrolled_build_message;
3+ use anyhow:: bail;
34use database:: QueuedCommit ;
45
56pub struct TriageBuild {
@@ -9,6 +10,13 @@ pub struct TriageBuild {
910
1011pub const TRIAGE_MARKER : & str = "<!-- rust-timer: triage -->" ;
1112
13+ pub fn triage_body_start_marker ( pr : u32 ) -> String {
14+ format ! ( "<!-- rust-timer:triage-body-start-pr-{pr} -->\n " )
15+ }
16+ pub fn triage_body_end_marker ( pr : u32 ) -> String {
17+ format ! ( "<!-- rust-timer:triage-body-end-pr-{pr} -->\n " )
18+ }
19+
1220/// Returns `Some` if this commit is part of a triage run.
1321pub async fn is_triage_run (
1422 commit : & QueuedCommit ,
@@ -38,3 +46,164 @@ pub async fn is_triage_run(
3846 triage_comment,
3947 } ) )
4048}
49+
50+ pub fn update_triage_body (
51+ body : & mut String ,
52+ pr : u32 ,
53+ triage_summary : String ,
54+ ) -> anyhow:: Result < ( ) > {
55+ let Some ( body_start) = body. find ( & triage_body_start_marker ( pr) ) else {
56+ bail ! ( "Failed to triage body start" )
57+ } ;
58+ let body_start = body_start + triage_body_start_marker ( pr) . len ( ) ;
59+ let Some ( body_end) = body. find ( & triage_body_end_marker ( pr) ) else {
60+ bail ! ( "Failed to triage body end" )
61+ } ;
62+
63+ body. replace_range ( body_start..body_end, & triage_summary) ;
64+ Ok ( ( ) )
65+ }
66+
67+ #[ cfg( test) ]
68+ mod tests {
69+ use crate :: github:: triage:: update_triage_body;
70+
71+ const BEFORE_BODY : & str = "### #157428 364c9dea926885d60daef4bf1a15fa03efa35a84 allocator: refactor for stabilisation
72+ <!-- rust-timer:triage-body-start-pr-157428 -->
73+ Queued 364c9dea926885d60daef4bf1a15fa03efa35a84 with parent 93c9086fdd5b80d286480a19ac047746ecc5fa1f, future [comparison URL](https://perf.rust-lang.org/compare.html?start=93c9086fdd5b80d286480a19ac047746ecc5fa1f&end=364c9dea926885d60daef4bf1a15fa03efa35a84).
74+ There are currently 0 preceding artifacts in the [queue](https://perf.rust-lang.org/status.html).
75+ It will probably take at least ~1.0 hours until the benchmark run finishes.
76+ <!-- rust-timer:triage-body-end-pr-157428 -->
77+
78+ ### #160077 a96bde1411c3b0fe68417c04e85624f33b645516 Don't compute FnAbi for LLVM intrinsics
79+ <!-- rust-timer:triage-body-start-pr-160077 -->
80+ Queued a96bde1411c3b0fe68417c04e85624f33b645516 with parent 93c9086fdd5b80d286480a19ac047746ecc5fa1f, future [comparison URL](https://perf.rust-lang.org/compare.html?start=93c9086fdd5b80d286480a19ac047746ecc5fa1f&end=a96bde1411c3b0fe68417c04e85624f33b645516).
81+ There is currently 1 preceding artifact in the [queue](https://perf.rust-lang.org/status.html).
82+ It will probably take at least ~2.0 hours until the benchmark run finishes.
83+ <!-- rust-timer:triage-body-end-pr-160077 -->
84+
85+ ### #160288 77cb04ee49e4f29833262112d5abf705c96faa98 rustdoc: use anonymous constant for primitives/keywords/attribute docs
86+ <!-- rust-timer:triage-body-start-pr-160288 -->
87+ Queued 77cb04ee49e4f29833262112d5abf705c96faa98 with parent 93c9086fdd5b80d286480a19ac047746ecc5fa1f, future [comparison URL](https://perf.rust-lang.org/compare.html?start=93c9086fdd5b80d286480a19ac047746ecc5fa1f&end=77cb04ee49e4f29833262112d5abf705c96faa98).
88+ There are currently 2 preceding artifacts in the [queue](https://perf.rust-lang.org/status.html).
89+ It will probably take at least ~3.0 hours until the benchmark run finishes.
90+ <!-- rust-timer:triage-body-end-pr-160288 -->
91+
92+ <!-- rust-timer: triage -->" ;
93+
94+ #[ test]
95+ fn test_update_first ( ) {
96+ let mut body = BEFORE_BODY . to_string ( ) ;
97+ update_triage_body (
98+ & mut body,
99+ 157428 ,
100+ "NEW BODY1\n NEW BODY2\n NEW BODY3\n " . to_string ( ) ,
101+ )
102+ . unwrap ( ) ;
103+
104+ const EXPECTED_RESULT : & str = "### #157428 364c9dea926885d60daef4bf1a15fa03efa35a84 allocator: refactor for stabilisation
105+ <!-- rust-timer:triage-body-start-pr-157428 -->
106+ NEW BODY1
107+ NEW BODY2
108+ NEW BODY3
109+ <!-- rust-timer:triage-body-end-pr-157428 -->
110+
111+ ### #160077 a96bde1411c3b0fe68417c04e85624f33b645516 Don't compute FnAbi for LLVM intrinsics
112+ <!-- rust-timer:triage-body-start-pr-160077 -->
113+ Queued a96bde1411c3b0fe68417c04e85624f33b645516 with parent 93c9086fdd5b80d286480a19ac047746ecc5fa1f, future [comparison URL](https://perf.rust-lang.org/compare.html?start=93c9086fdd5b80d286480a19ac047746ecc5fa1f&end=a96bde1411c3b0fe68417c04e85624f33b645516).
114+ There is currently 1 preceding artifact in the [queue](https://perf.rust-lang.org/status.html).
115+ It will probably take at least ~2.0 hours until the benchmark run finishes.
116+ <!-- rust-timer:triage-body-end-pr-160077 -->
117+
118+ ### #160288 77cb04ee49e4f29833262112d5abf705c96faa98 rustdoc: use anonymous constant for primitives/keywords/attribute docs
119+ <!-- rust-timer:triage-body-start-pr-160288 -->
120+ Queued 77cb04ee49e4f29833262112d5abf705c96faa98 with parent 93c9086fdd5b80d286480a19ac047746ecc5fa1f, future [comparison URL](https://perf.rust-lang.org/compare.html?start=93c9086fdd5b80d286480a19ac047746ecc5fa1f&end=77cb04ee49e4f29833262112d5abf705c96faa98).
121+ There are currently 2 preceding artifacts in the [queue](https://perf.rust-lang.org/status.html).
122+ It will probably take at least ~3.0 hours until the benchmark run finishes.
123+ <!-- rust-timer:triage-body-end-pr-160288 -->
124+
125+ <!-- rust-timer: triage -->" ;
126+ assert_eq ! ( body, EXPECTED_RESULT ) ;
127+ }
128+
129+ #[ test]
130+ fn test_update_second ( ) {
131+ let mut body = BEFORE_BODY . to_string ( ) ;
132+ update_triage_body (
133+ & mut body,
134+ 160077 ,
135+ "NEW BODY1\n NEW BODY2\n NEW BODY3\n " . to_string ( ) ,
136+ )
137+ . unwrap ( ) ;
138+
139+ const EXPECTED_RESULT : & str = "### #157428 364c9dea926885d60daef4bf1a15fa03efa35a84 allocator: refactor for stabilisation
140+ <!-- rust-timer:triage-body-start-pr-157428 -->
141+ Queued 364c9dea926885d60daef4bf1a15fa03efa35a84 with parent 93c9086fdd5b80d286480a19ac047746ecc5fa1f, future [comparison URL](https://perf.rust-lang.org/compare.html?start=93c9086fdd5b80d286480a19ac047746ecc5fa1f&end=364c9dea926885d60daef4bf1a15fa03efa35a84).
142+ There are currently 0 preceding artifacts in the [queue](https://perf.rust-lang.org/status.html).
143+ It will probably take at least ~1.0 hours until the benchmark run finishes.
144+ <!-- rust-timer:triage-body-end-pr-157428 -->
145+
146+ ### #160077 a96bde1411c3b0fe68417c04e85624f33b645516 Don't compute FnAbi for LLVM intrinsics
147+ <!-- rust-timer:triage-body-start-pr-160077 -->
148+ NEW BODY1
149+ NEW BODY2
150+ NEW BODY3
151+ <!-- rust-timer:triage-body-end-pr-160077 -->
152+
153+ ### #160288 77cb04ee49e4f29833262112d5abf705c96faa98 rustdoc: use anonymous constant for primitives/keywords/attribute docs
154+ <!-- rust-timer:triage-body-start-pr-160288 -->
155+ Queued 77cb04ee49e4f29833262112d5abf705c96faa98 with parent 93c9086fdd5b80d286480a19ac047746ecc5fa1f, future [comparison URL](https://perf.rust-lang.org/compare.html?start=93c9086fdd5b80d286480a19ac047746ecc5fa1f&end=77cb04ee49e4f29833262112d5abf705c96faa98).
156+ There are currently 2 preceding artifacts in the [queue](https://perf.rust-lang.org/status.html).
157+ It will probably take at least ~3.0 hours until the benchmark run finishes.
158+ <!-- rust-timer:triage-body-end-pr-160288 -->
159+
160+ <!-- rust-timer: triage -->" ;
161+ assert_eq ! ( body, EXPECTED_RESULT ) ;
162+ }
163+
164+ #[ test]
165+ fn test_update_last ( ) {
166+ let mut body = BEFORE_BODY . to_string ( ) ;
167+ update_triage_body (
168+ & mut body,
169+ 160288 ,
170+ "NEW BODY1\n NEW BODY2\n NEW BODY3\n " . to_string ( ) ,
171+ )
172+ . unwrap ( ) ;
173+
174+ const EXPECTED_RESULT : & str = "### #157428 364c9dea926885d60daef4bf1a15fa03efa35a84 allocator: refactor for stabilisation
175+ <!-- rust-timer:triage-body-start-pr-157428 -->
176+ Queued 364c9dea926885d60daef4bf1a15fa03efa35a84 with parent 93c9086fdd5b80d286480a19ac047746ecc5fa1f, future [comparison URL](https://perf.rust-lang.org/compare.html?start=93c9086fdd5b80d286480a19ac047746ecc5fa1f&end=364c9dea926885d60daef4bf1a15fa03efa35a84).
177+ There are currently 0 preceding artifacts in the [queue](https://perf.rust-lang.org/status.html).
178+ It will probably take at least ~1.0 hours until the benchmark run finishes.
179+ <!-- rust-timer:triage-body-end-pr-157428 -->
180+
181+ ### #160077 a96bde1411c3b0fe68417c04e85624f33b645516 Don't compute FnAbi for LLVM intrinsics
182+ <!-- rust-timer:triage-body-start-pr-160077 -->
183+ Queued a96bde1411c3b0fe68417c04e85624f33b645516 with parent 93c9086fdd5b80d286480a19ac047746ecc5fa1f, future [comparison URL](https://perf.rust-lang.org/compare.html?start=93c9086fdd5b80d286480a19ac047746ecc5fa1f&end=a96bde1411c3b0fe68417c04e85624f33b645516).
184+ There is currently 1 preceding artifact in the [queue](https://perf.rust-lang.org/status.html).
185+ It will probably take at least ~2.0 hours until the benchmark run finishes.
186+ <!-- rust-timer:triage-body-end-pr-160077 -->
187+
188+ ### #160288 77cb04ee49e4f29833262112d5abf705c96faa98 rustdoc: use anonymous constant for primitives/keywords/attribute docs
189+ <!-- rust-timer:triage-body-start-pr-160288 -->
190+ NEW BODY1
191+ NEW BODY2
192+ NEW BODY3
193+ <!-- rust-timer:triage-body-end-pr-160288 -->
194+
195+ <!-- rust-timer: triage -->" ;
196+ assert_eq ! ( body, EXPECTED_RESULT ) ;
197+ }
198+
199+ #[ test]
200+ fn test_update_not_in_there ( ) {
201+ let mut body = BEFORE_BODY . to_string ( ) ;
202+ assert ! ( update_triage_body(
203+ & mut body,
204+ 1234 ,
205+ "NEW BODY1\n NEW BODY2\n NEW BODY3\n " . to_string( )
206+ )
207+ . is_err( ) ) ;
208+ }
209+ }
0 commit comments