Skip to content

Commit aee15fd

Browse files
authored
Merge pull request #483 from Kobzol/help-render
Unify help between GitHub comments and the webpage
2 parents 7ac2496 + 2c0f63f commit aee15fd

File tree

5 files changed

+95
-205
lines changed

5 files changed

+95
-205
lines changed

src/bors/handlers/help.rs

Lines changed: 1 addition & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
use crate::bors::Comment;
21
use crate::bors::RepositoryState;
3-
use crate::bors::command::BorsCommand;
2+
use crate::bors::{Comment, format_help};
43
use crate::github::PullRequestNumber;
54
use std::sync::Arc;
65

@@ -16,69 +15,6 @@ pub(super) async fn command_help(
1615
Ok(())
1716
}
1817

19-
/// Format the bors command help in Markdown format.
20-
fn format_help() -> &'static str {
21-
// The help is generated manually to have a nicer structure.
22-
// We do a no-op destructuring of `BorsCommand` to make it harder to modify help in case new
23-
// commands are added though.
24-
match BorsCommand::Ping {
25-
BorsCommand::Approve {
26-
approver: _,
27-
rollup: _,
28-
priority: _,
29-
} => {}
30-
BorsCommand::Unapprove => {}
31-
BorsCommand::Help => {}
32-
BorsCommand::Ping => {}
33-
BorsCommand::Try { parent: _, jobs: _ } => {}
34-
BorsCommand::TryCancel => {}
35-
BorsCommand::SetPriority(_) => {}
36-
BorsCommand::Info => {}
37-
BorsCommand::SetDelegate(_) => {}
38-
BorsCommand::Undelegate => {}
39-
BorsCommand::SetRollupMode(_) => {}
40-
BorsCommand::OpenTree => {}
41-
BorsCommand::TreeClosed(_) => {}
42-
BorsCommand::Retry => {}
43-
}
44-
45-
r#"
46-
You can use the following commands:
47-
48-
## PR management
49-
- `r+ [p=<priority>] [rollup=<never|iffy|maybe|always>]`: Approve this PR on your behalf
50-
- Optionally, you can specify the `<priority>` of the PR and if it is eligible for rollups (`<rollup>)`.
51-
- `r=<user> [p=<priority>] [rollup=<never|iffy|maybe|always>]`: Approve this PR on behalf of `<user>`
52-
- Optionally, you can specify the `<priority>` of the PR and if it is eligible for rollups (`<rollup>)`.
53-
- You can pass a comma-separated list of GitHub usernames.
54-
- `r-`: Unapprove this PR
55-
- `p=<priority>` or `priority=<priority>`: Set the priority of this PR
56-
- `rollup=<never|iffy|maybe|always>`: Set the rollup status of the PR
57-
- `rollup`: Short for `rollup=always`
58-
- `rollup-`: Short for `rollup=maybe`
59-
- `delegate=<try|review>`: Delegate permissions for running try builds or approving to the PR author
60-
- `try` allows the PR author to start try builds.
61-
- `review` allows the PR author to both start try builds and approve the PR.
62-
- `delegate+`: Delegate approval permissions to the PR author
63-
- Shortcut for `delegate=review`
64-
- `delegate-`: Remove any previously granted permission delegation
65-
- `try [parent=<parent>] [jobs=<jobs>]`: Start a try build.
66-
- Optionally, you can specify a `<parent>` SHA with which will the PR be merged. You can specify `parent=last` to use the same parent SHA as the previous try build.
67-
- Optionally, you can select a comma-separated list of CI `<jobs>` to run in the try build.
68-
- `try cancel`: Cancel a running try build
69-
- `retry`: Clear a failed auto build status from an approved PR. This will cause the merge queue to attempt to start a new auto build and retry merging the PR again.
70-
- `info`: Get information about the current PR
71-
72-
## Repository management
73-
- `treeclosed=<priority>`: Close the tree for PRs with priority less than `<priority>`
74-
- `treeclosed-` or `treeopen`: Open the repository tree for merging
75-
76-
## Meta commands
77-
- `ping`: Check if the bot is alive
78-
- `help`: Print this help message
79-
"#
80-
}
81-
8218
#[cfg(test)]
8319
mod tests {
8420
use crate::tests::{BorsTester, run_test};

src/bors/mod.rs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,73 @@ mod handlers;
2727
pub mod merge_queue;
2828
pub mod mergeability_queue;
2929

30+
use crate::bors::command::BorsCommand;
3031
use crate::database::{WorkflowModel, WorkflowStatus};
3132
pub use command::CommandPrefix;
3233

34+
/// Format the bors command help in Markdown format.
35+
pub fn format_help() -> &'static str {
36+
// The help is generated manually to have a nicer structure.
37+
// We do a no-op destructuring of `BorsCommand` to make it harder to modify help in case new
38+
// commands are added though.
39+
match BorsCommand::Ping {
40+
BorsCommand::Approve {
41+
approver: _,
42+
rollup: _,
43+
priority: _,
44+
} => {}
45+
BorsCommand::Unapprove => {}
46+
BorsCommand::Help => {}
47+
BorsCommand::Ping => {}
48+
BorsCommand::Try { parent: _, jobs: _ } => {}
49+
BorsCommand::TryCancel => {}
50+
BorsCommand::SetPriority(_) => {}
51+
BorsCommand::Info => {}
52+
BorsCommand::SetDelegate(_) => {}
53+
BorsCommand::Undelegate => {}
54+
BorsCommand::SetRollupMode(_) => {}
55+
BorsCommand::OpenTree => {}
56+
BorsCommand::TreeClosed(_) => {}
57+
BorsCommand::Retry => {}
58+
}
59+
60+
r#"
61+
You can use the following commands:
62+
63+
## PR management
64+
- `r+ [p=<priority>] [rollup=<never|iffy|maybe|always>]`: Approve this PR on your behalf
65+
- Optionally, you can specify the `<priority>` of the PR and if it is eligible for rollups (`<rollup>)`.
66+
- `r=<user> [p=<priority>] [rollup=<never|iffy|maybe|always>]`: Approve this PR on behalf of `<user>`
67+
- Optionally, you can specify the `<priority>` of the PR and if it is eligible for rollups (`<rollup>)`.
68+
- You can pass a comma-separated list of GitHub usernames.
69+
- `r-`: Unapprove this PR
70+
- `p=<priority>` or `priority=<priority>`: Set the priority of this PR
71+
- `rollup=<never|iffy|maybe|always>`: Set the rollup status of the PR
72+
- `rollup`: Short for `rollup=always`
73+
- `rollup-`: Short for `rollup=maybe`
74+
- `delegate=<try|review>`: Delegate permissions for running try builds or approving to the PR author
75+
- `try` allows the PR author to start try builds.
76+
- `review` allows the PR author to both start try builds and approve the PR.
77+
- `delegate+`: Delegate approval permissions to the PR author
78+
- Shortcut for `delegate=review`
79+
- `delegate-`: Remove any previously granted permission delegation
80+
- `try [parent=<parent>] [jobs=<jobs>]`: Start a try build.
81+
- Optionally, you can specify a `<parent>` SHA with which will the PR be merged. You can specify `parent=last` to use the same parent SHA as the previous try build.
82+
- Optionally, you can select a comma-separated list of CI `<jobs>` to run in the try build.
83+
- `try cancel`: Cancel a running try build
84+
- `retry`: Clear a failed auto build status from an approved PR. This will cause the merge queue to attempt to start a new auto build and retry merging the PR again.
85+
- `info`: Get information about the current PR
86+
87+
## Repository management
88+
- `treeclosed=<priority>`: Close the tree for PRs with priority less than `<priority>`
89+
- `treeclosed-` or `treeopen`: Open the repository tree for merging
90+
91+
## Meta commands
92+
- `ping`: Check if the bot is alive
93+
- `help`: Print this help message
94+
"#
95+
}
96+
3397
#[cfg(test)]
3498
pub static WAIT_FOR_REFRESH_PENDING_BUILDS: TestSyncMarker = TestSyncMarker::new();
3599

src/server/mod.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::bors::event::BorsEvent;
2-
use crate::bors::{CommandPrefix, RepositoryState, RollupMode};
2+
use crate::bors::{CommandPrefix, RepositoryState, RollupMode, format_help};
33
use crate::database::{ApprovalStatus, PullRequestModel, QueueStatus};
44
use crate::github::{GithubRepoName, rollup};
55
use crate::templates::{
@@ -14,6 +14,7 @@ use axum::response::{IntoResponse, Redirect, Response};
1414
use axum::routing::{get, post};
1515
use axum::{Json, Router};
1616
use http::StatusCode;
17+
use pulldown_cmark::Parser;
1718
use secrecy::{ExposeSecret, SecretString};
1819
use std::any::Any;
1920
use std::collections::HashMap;
@@ -255,8 +256,15 @@ async fn help_handler(State(state): State<ServerStateRef>) -> impl IntoResponse
255256
});
256257
}
257258

259+
let help_md = format_help();
260+
let markdown = Parser::new(help_md);
261+
262+
let mut help_html = String::new();
263+
pulldown_cmark::html::push_html(&mut help_html, markdown);
264+
258265
HtmlTemplate(HelpTemplate {
259266
repos,
267+
help: help_html,
260268
cmd_prefix: state.get_cmd_prefix().as_ref().to_string(),
261269
})
262270
}

src/templates.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ where
4444
pub struct HelpTemplate {
4545
pub repos: Vec<RepositoryView>,
4646
pub cmd_prefix: String,
47+
pub help: String,
4748
}
4849

4950
pub struct RepositoryView {

templates/help.html

Lines changed: 20 additions & 139 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
overflow-x: auto;
1818
}
1919

20-
tbody tr:last-child td {
21-
border-bottom: none;
22-
}
20+
tbody tr:last-child td {
21+
border-bottom: none;
22+
}
2323

2424
th,
2525
td {
@@ -45,145 +45,26 @@
4545

4646
{% block body %}
4747
<main>
48-
<h1>Bors</h1>
49-
50-
<h2>Repositories</h2>
51-
<ul class="repos">
52-
{% for repo in repos %}
53-
<li>
54-
<a href="queue/{{ repo.name }}">{{ repo.name }}</a>
55-
{% if repo.treeclosed %} [TREECLOSED] {% endif %}
56-
</li>
57-
{% endfor %}
58-
</ul>
48+
<h1>Bors</h1>
5949

60-
<h2>Commands</h2>
61-
<p>Commands must be posted as comments on the PR and mention the bot account (<code>{{ cmd_prefix }}</code>).</p>
50+
<h2>Repositories</h2>
51+
<ul class="repos">
52+
{% for repo in repos %}
53+
<li>
54+
<a href="queue/{{ repo.name }}">{{ repo.name }}</a>
55+
{% if repo.treeclosed %} [TREECLOSED] {% endif %}
56+
</li>
57+
{% endfor %}
58+
</ul>
6259

63-
<div class="table-wrapper">
64-
<table>
65-
<thead>
66-
<tr>
67-
<th>Command</th>
68-
<th>Permissions</th>
69-
<th>Description</th>
70-
</tr>
71-
</thead>
72-
<tbody>
73-
<tr>
74-
<td><code>info</code></td>
75-
<td class="empty"></td>
76-
<td>Get information about the current PR</td>
77-
</tr>
78-
<tr>
79-
<td><code>ping</code></td>
80-
<td class="empty"></td>
81-
<td>Check if the bot is alive</td>
82-
</tr>
83-
<tr>
84-
<td><code>help</code></td>
85-
<td class="empty"></td>
86-
<td>Print help message</td>
87-
</tr>
88-
<tr>
89-
<td><code>r+</code></td>
90-
<td>review</td>
91-
<td>Approve this PR on your behalf</td>
92-
</tr>
93-
<tr>
94-
<td><code>r=&lt;user&gt;</code></td>
95-
<td>review</td>
96-
<td>Approve the PR on behalf of the specified user(s)</td>
97-
</tr>
98-
<tr>
99-
<td><code>r-</code></td>
100-
<td>review</td>
101-
<td>Unapprove the PR</td>
102-
</tr>
103-
<tr>
104-
<td><code>p=&lt;priority&gt;</code> or <code>priority=&lt;priority&gt;</code></td>
105-
<td>review</td>
106-
<td>Set the priority of the PR</td>
107-
</tr>
108-
<tr>
109-
<td><code>rollup</code></td>
110-
<td>review</td>
111-
<td>Short for <code>rollup=always</code></td>
112-
</tr>
113-
<tr>
114-
<td><code>rollup-</code></td>
115-
<td>review</td>
116-
<td>Short for <code>rollup=maybe</code></td>
117-
</tr>
118-
<tr>
119-
<td><code>rollup=&lt;never|iffy|maybe|always&gt;</code></td>
120-
<td>review</td>
121-
<td>Set the rollup status of the PR</td>
122-
</tr>
123-
<tr>
124-
<td><code>r+ [p=&lt;priority&gt;] [rollup=&lt;mode&gt;]</code></td>
125-
<td>review</td>
126-
<td>Approve this PR on your behalf with options</td>
127-
</tr>
128-
<tr>
129-
<td><code>r=&lt;user&gt; [p=&lt;priority&gt;] [rollup=&lt;mode&gt;]</code></td>
130-
<td>review</td>
131-
<td>Approve the PR on behalf of the specified user(s) with options</td>
132-
</tr>
133-
<tr>
134-
<td><code>try [parent=&lt;sha&gt;] [jobs=&lt;job1,job2,...&gt;]</code></td>
135-
<td>try</td>
136-
<td>Run a try build (max 10 jobs)</td>
137-
</tr>
138-
<tr>
139-
<td><code>try cancel</code></td>
140-
<td>try</td>
141-
<td>Cancel a running try build</td>
142-
</tr>
143-
<tr>
144-
<td><code>delegate+</code></td>
145-
<td>review</td>
146-
<td>Short for <code>delegate=review</code></td>
147-
</tr>
148-
<tr>
149-
<td><code>delegate-</code></td>
150-
<td>review</td>
151-
<td>Remove any previously granted delegated permissions</td>
152-
</tr>
153-
<tr>
154-
<td><code>delegate=&lt;try|review&gt;</code></td>
155-
<td>review</td>
156-
<td>Delegate permissions to the PR author (try or review)</td>
157-
</tr>
158-
<tr>
159-
<td><code>treeclosed-</code> or <code>treeopen</code></td>
160-
<td>review</td>
161-
<td>Open the repository tree for merging</td>
162-
</tr>
163-
<tr>
164-
<td><code>treeclosed=&lt;priority&gt;</code></td>
165-
<td>review</td>
166-
<td>Close the tree for PRs with priority less than <code>&lt;priority&gt;</code></td>
167-
</tr>
168-
<tr>
169-
<td><code>retry</code></td>
170-
<td>review</td>
171-
<td>Clear a failed auto build status from an approved PR. This will cause the merge queue to attempt to start a new auto build and retry merging the PR again.</td>
172-
</tr>
173-
</tbody>
174-
</table>
175-
</div>
60+
<h2>Commands</h2>
61+
<p>Commands must be posted as comments on the PR and mention the bot account (<code>{{ cmd_prefix
62+
}}</code>).</p>
17663

177-
<h2>Examples</h2>
178-
<ul>
179-
<li><code>{{ cmd_prefix }} r=user1,user2 p=5</code>: Approve on behalf of <code>user1</code> and <code>user2</code> with priority 5</li>
180-
<li><code>{{ cmd_prefix }} r+ rollup p=1</code>: Approve with priority 1 and always rollup</li>
181-
<li><code>{{ cmd_prefix }} try parent=last</code>: Start a try build using the same parent as the last try</li>
182-
<li><code>{{ cmd_prefix }} try @rust-timer queue</code>: Short-hand for compile-perf benchmarking of PRs</li>
183-
</ul>
64+
{{ help | safe }}
18465

185-
<div style="text-align: center; margin-top: 1em;">
186-
<a href="https://github.com/rust-lang/bors">Contribute on GitHub</a>
187-
</div>
66+
<div style="text-align: center; margin-top: 1em;">
67+
<a href="https://github.com/rust-lang/bors">Contribute on GitHub</a>
68+
</div>
18869
</main>
18970
{% endblock %}

0 commit comments

Comments
 (0)