Skip to main content

xtask/
authors.rs

1//! Check that a PR author's GitHub login appears in AUTHORS.
2
3use anyhow::{Context, Result, ensure};
4use regex::Regex;
5use std::{fs, path::Path};
6
7pub fn check(path: &Path, login: &str) -> Result<()> {
8    let authors = fs::read_to_string(path).with_context(|| {
9        format!(
10            "reading {}; add your contribution acknowledgment there",
11            path.display()
12        )
13    })?;
14    let entry = Regex::new(r"^.+ <[^<>\s]+@[^<>\s]+> \(@([^()\s]+)\)$")?;
15    let listed = authors
16        .lines()
17        .filter_map(|line| entry.captures(line.trim()))
18        .any(|fields| fields[1].eq_ignore_ascii_case(login));
19
20    ensure!(
21        listed,
22        "Read the contribution terms in AUTHORS, then acknowledge them by adding \
23         your own entry: Your Name <your Git email> (@{login}). \
24         You may use your GitHub noreply email."
25    );
26
27    Ok(())
28}