Skip to content

Commit b244bdb

Browse files
author
l
committed
merge origin/main
2 parents 06ffe54 + b09a83e commit b244bdb

14 files changed

Lines changed: 477 additions & 126 deletions

.github/workflows/release.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ jobs:
2222
# Presumably used to log into the GitHub Container Registry, as per https://docs.github.com/en/packages/managing-github-packages-using-github-actions-workflows/publishing-and-installing-a-package-with-github-actions.
2323
id-token: write
2424
container:
25-
image: rust:1.88.0-alpine
25+
image: rust:1.92.0-alpine
2626
steps:
2727
- uses: actions/checkout@v4
2828
- name: Install deps
2929
run: apk add docker gcc g++
3030
- name: Build binaries
3131
# Copy file to rename for the release action
32-
run: cargo build --release && cp target/release/pr-metadata-validator pr-metadata-validator-musl-${{ github.ref_name }}
32+
run: cargo build --release && cp target/release/pr-metadata-validator pr-metadata-validator-musl-${{ github.ref_name }} && cp target/release/dummy-code-of-conduct-validator dummy-code-of-conduct-validator-musl-${{ github.ref_name }}
3333
- name: Log in to the Container registry
3434
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
3535
with:
@@ -64,4 +64,6 @@ jobs:
6464
generate_release_notes: true
6565
tag_name: ${{ github.ref_name }}
6666
target_commitish: ${{ github.base_ref }}
67-
files: pr-metadata-validator-musl-${{ github.ref_name }}
67+
files: |
68+
dummy-code-of-conduct-validator-musl-${{ github.ref_name }}
69+
pr-metadata-validator-musl-${{ github.ref_name }}

Cargo.lock

Lines changed: 64 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ axum = { version = "0.8.4", features = ["macros", "original-uri"] }
1111
case_insensitive_string = { version = "0.2.10", features = ["serde"] }
1212
chrono = "0.4.41"
1313
chrono-tz = "0.10.3"
14+
const_format = "0.2.35"
1415
dotenv = "0.15.0"
1516
# Until https://github.com/johnstonskj/rust-email_address/pull/43 is merged and released.
1617
email_address = { git = "https://github.com/illicitonion/rust-email_address.git", rev = "12cd9762a166b79a227beaa90b2f60a768d7c55c" }
@@ -44,6 +45,8 @@ serde_json = "1"
4445
serde_urlencoded = "0.7.1"
4546
sheets = "0.7.0"
4647
slack-with-types = "0.1.1"
48+
strum_macros = "0.27.2"
49+
time = "0.3.44"
4750
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
4851
tower = "0.5.2"
4952
tower-http = { version = "0.6.6", features = ["fs"] }

rust-toolchain.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[toolchain]
2+
channel = "1.92.0"
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/// This binary exists to be a lightweight teaching version of the pr-metadata-validator.
2+
/// Its purpose is to train trainees in the idea that bots will comment on their PRs, and they should follow their advice.
3+
/// It is installed in https://github.com/CodeYourFuture/github_issues_prs_practice as a GitHub Action.
4+
use std::process::exit;
5+
6+
use const_format::concatcp;
7+
use trainee_tracker::{
8+
octocrab::octocrab_for_token,
9+
pr_comments::{PullRequest, close_existing_comments, leave_tagged_comment},
10+
};
11+
12+
#[tokio::main]
13+
async fn main() {
14+
let Ok([_argv0, pr_url]) = <[_; _]>::try_from(std::env::args().collect::<Vec<_>>()) else {
15+
eprintln!("Expected one arg - PR URL");
16+
exit(1);
17+
};
18+
let pr_metadata = PullRequest::from_html_url(&pr_url).expect("Failed to parse PR URL");
19+
let github_token =
20+
std::env::var("GH_TOKEN").expect("GH_TOKEN wasn't set - must be set to a GitHub API token");
21+
let octocrab = octocrab_for_token(github_token.to_owned()).expect("Failed to get octocrab");
22+
23+
let pr_from_rest = octocrab
24+
.pulls(&pr_metadata.org, &pr_metadata.repo)
25+
.get(pr_metadata.number)
26+
.await
27+
.expect("Failed to get PR");
28+
if pr_from_rest
29+
.body
30+
.unwrap_or_default()
31+
.ends_with(EXPECTED_SUFFIX)
32+
{
33+
let result = close_existing_comments(&octocrab, &pr_metadata, TAG).await;
34+
if let Err(err) = result {
35+
eprintln!("Failed to close existing comments: {:?}", err);
36+
}
37+
} else {
38+
leave_tagged_comment(&octocrab, &pr_metadata, &[TAG], COMMENT_TO_LEAVE.to_owned())
39+
.await
40+
.expect("Failed to leave comment");
41+
}
42+
}
43+
44+
const EXPECTED_SUFFIX: &str = "I agree to follow the code of conduct for this organisation.";
45+
46+
const TAG: &str = "dummy-code-of-conduct-validator";
47+
48+
const COMMENT_TO_LEAVE: &str = concatcp!(
49+
COMMENT_TO_LEAVE_PREFIX,
50+
EXPECTED_SUFFIX,
51+
COMMENT_TO_LEAVE_SUFFIX
52+
);
53+
54+
const COMMENT_TO_LEAVE_PREFIX: &str = r#"This is a comment from a bot.
55+
56+
You should read it, make sure you understand it, and take the action it suggests.
57+
58+
If you don't understand the action it suggests, ask a volunteer or another trainee for help.
59+
60+
## ⚠️ Problem detected
61+
62+
In this repository, all pull request descriptions must end with the sentence:
63+
64+
> "#;
65+
66+
const COMMENT_TO_LEAVE_SUFFIX: &str = r#"
67+
68+
Your pull request description does not currently end with this sentence.
69+
70+
Please edit your pull request description to add this sentence at the end.
71+
72+
If you are successful in doing this, this comment will get automatically hidden within about a minute.
73+
"#;

src/bin/match-pr-to-assignment.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use trainee_tracker::{
1313
#[tokio::main]
1414
async fn main() {
1515
let Ok([_argv0, github_token, pr_link]) =
16-
<[_; 3]>::try_from(std::env::args().collect::<Vec<_>>())
16+
<[_; _]>::try_from(std::env::args().collect::<Vec<_>>())
1717
else {
1818
eprintln!("Expected two args - github token and PR link");
1919
exit(1);
@@ -31,7 +31,7 @@ async fn main() {
3131
_pull,
3232
pr_number_str,
3333
],
34-
) = <[_; 7]>::try_from(pr_link.split('/').collect::<Vec<_>>())
34+
) = <[_; _]>::try_from(pr_link.split('/').collect::<Vec<_>>())
3535
else {
3636
panic!("Couldn't parse GitHub PR link {}", pr_link);
3737
};

0 commit comments

Comments
 (0)