OXYGENHUB

Coverage / crates/hub/src/repo_setup.rs 83.2%

218 of 262 lines run, 45 of 102 functions · run #545 on main · run missed

1
//! What a new repository starts with (oxygenhub#360), shared by the New
2
//! repository page and the API: a name check before anything is made, the
3
//! files it starts with (a README, a licence, an `.oxyignore` for a
4
//! language), committed as its creator the way the starter's are (#347),
5
//! and a project board made or chosen with it, which then takes its issues
6
//! and proposals as they open. OxygenFlow switched on and the wiki
7
//! started with a Home page come with it too (#371).
8
9
use crate::auth::roles;
10
use crate::db::{self, projects as pdb};
11
use crate::repos::RepoName;
12
use crate::Shared;
13
use oxy_core::repo::FileEdit;
14
15
/// Whether `owner/name` may be made by `account`: `Ok` with its address,
16
/// or why not, said as the page and the API say it.
1729×
pub async fn check_name(app: &Shared, account: &db::accounts::Account, owner: &str, name: &str) -> Result<RepoName, String> {
1829×
    let Some(n) = RepoName::new(owner.trim(), name.trim()) else {
192×
        return Err("A repository name is letters, digits, dots, dashes and underscores, up to 64.".into());
20
    };
2127×
    if n.name.ends_with(crate::wiki::SUFFIX) {
221×
        return Err("A name cannot end in .wiki: that is the address of a repository's wiki.".into());
2326×
    }
2426×
    if !roles::may_create_under(&app.db, account, &n.owner).await.map_err(|e| e.to_string())? {
250×
        return Err(format!("You cannot create repositories under {}.", n.owner));
2626×
    }
2726×
    if db::repos::get(&app.db, &n.owner, &n.name).await.map_err(|e| e.to_string())?.is_some() || app.repos.exists(&n) {
281×
        return Err(format!("{n} exists."));
2925×
    }
3025×
    Ok(n)
3129×
}
32
33
/// A board for a new repository: none, a new one under its owner with this
34
/// title, or the owner's board of this number.
35
#[derive(Clone, Debug, PartialEq, Eq)]
36
pub enum Board {
37
    None,
38
    New(String),
39
    Existing(i64),
40
}
41
42
impl Board {
43
    /// The form's or the API's choice: `new` with a title (the
44
    /// repository's name when empty), a board number, or nothing.
4529×
    pub fn parse(choice: &str, title: &str, repo: &str) -> Result<Board, String> {
4629×
        match choice.trim() {
4729×
            "" | "none" => Ok(Board::None),
485×
            "new" => {
493×
                let t: String = title.trim().chars().take(100).collect();
503×
                Ok(Board::New(if t.is_empty() { repo.to_string() } else { t }))
51
            }
522×
            n => n.parse().map(Board::Existing).map_err(|_| format!("No board {n}.")),
53
        }
5429×
    }
55
}
56
57
/// Checked before the repository is made: a chosen board must be the
58
/// owner's, open, and one `account` may change.
5947×
pub async fn check_board(app: &Shared, account: &db::accounts::Account, owner: &str, board: &Board) -> Result<(), String> {
6047×
    match board {
6143×
        Board::None => Ok(()),
622×
        Board::New(_) => match crate::web::projects::rights_of(app, Some(account), owner).await.map_err(|e| e.to_string())? {
632×
            Some(r) if r.edit => Ok(()),
640×
            _ => Err(format!("You cannot make boards under {owner}.")),
65
        },
662×
        Board::Existing(n) => {
672×
            let p = pdb::get(&app.db, owner, *n).await.map_err(|e| e.to_string())?.ok_or(format!("{owner} has no board {n}."))?;
681×
            if p.closed {
690×
                return Err(format!("Board {n} is closed."));
701×
            }
711×
            match crate::web::projects::rights_of(app, Some(account), owner).await.map_err(|e| e.to_string())? {
721×
                Some(r) if r.edit => Ok(()),
730×
                _ => Err(format!("You cannot change {owner}'s boards.")),
74
            }
75
        }
76
    }
7747×
}
78
79
/// Make or find the board and link it to the repository; its number.
8031×
pub async fn link_board(app: &Shared, row: &db::repos::RepoRow, board: &Board, public: bool) -> sqlx::Result<Option<i64>> {
8131×
    let p = match board {
8228×
        Board::None => return Ok(None),
832×
        Board::New(title) => pdb::create(&app.db, &row.owner, title, &format!("Work on {}/{}", row.owner, row.name), public).await?,
841×
        Board::Existing(n) => match pdb::get(&app.db, &row.owner, *n).await? {
851×
            Some(p) => p,
860×
            None => return Ok(None),
87
        },
88
    };
893×
    pdb::link_repo(&app.db, p.id, row.id).await?;
903×
    Ok(Some(p.number))
9131×
}
92
93
/// Where a new repository's default bookmark comes from (#371): the
94
/// owner's own choice (a user's or an organisation's), else the site's,
95
/// else `main`. Kept in the settings table, so nothing else changes.
96
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
97
pub enum BookmarkScope {
98
    Site,
99
    Account(i64),
100
    Org(i64),
101
}
102
103
/// The bookmark a repository has when nothing else is chosen.
104
pub const MAIN: &str = "main";
105
106
impl BookmarkScope {
107401×
    fn key(self) -> String {
108401×
        match self {
109248×
            BookmarkScope::Site => "default_bookmark".into(),
110107×
            BookmarkScope::Account(id) => format!("default_bookmark.account.{id}"),
11146×
            BookmarkScope::Org(id) => format!("default_bookmark.org.{id}"),
112
        }
113401×
    }
114
}
115
116
/// The default bookmark set at `scope`, if one is.
117396×
pub async fn bookmark_setting(pool: &db::Pool, scope: BookmarkScope) -> sqlx::Result<Option<String>> {
118396×
    Ok(db::accounts::setting(pool, &scope.key()).await?.filter(|v| !v.is_empty()))
119396×
}
120
121
/// Set (or, empty, clear) the default bookmark at `scope`.
1222×
pub async fn set_bookmark_setting(pool: &db::Pool, scope: BookmarkScope, value: &str) -> Result<(), String> {
1232×
    let v = value.trim();
1242×
    if !v.is_empty() {
1252×
        check_bookmark(v)?;
1260×
    }
1272×
    db::accounts::set_setting(pool, &scope.key(), v).await.map_err(|e| e.to_string())
1282×
}
129
130
/// A bookmark name a repository may default to.
1318×
pub fn check_bookmark(name: &str) -> Result<(), String> {
1328×
    if crate::repos::names::valid_segment(name) {
1335×
        Ok(())
134
    } else {
1353×
        Err(format!(
1363×
            "{name:?} is not a bookmark name: letters, digits, dots, dashes and underscores, up to 64, starting with a letter or digit."
1373×
        ))
138
    }
1398×
}
140
141
/// The default bookmark a new repository under `owner` takes, and where
142
/// it comes from (for the page: "develop, from doomsdayone's settings").
14392×
pub async fn default_bookmark_for(app: &Shared, owner: &str) -> (String, String) {
14492×
    let own = match db::accounts::org_by_name(&app.db, owner).await.ok().flatten() {
14514×
        Some(org) => Some(BookmarkScope::Org(org.id)),
14678×
        None => db::accounts::account_by_name(&app.db, owner).await.ok().flatten().map(|a| BookmarkScope::Account(a.id)),
147
    };
14892×
    if let Some(scope) = own {
14992×
        if let Ok(Some(b)) = bookmark_setting(&app.db, scope).await {
1502×
            return (b, format!("{owner}'s default"));
15190×
        }
1520×
    }
15390×
    match bookmark_setting(&app.db, BookmarkScope::Site).await {
1541×
        Ok(Some(b)) => (b, "this site's default".into()),
15589×
        _ => (MAIN.into(), "the usual default".into()),
156
    }
15792×
}
158
159
/// The new repository's default bookmark: the one asked for, or its
160
/// owner's, the site's or `main`; set on its row when it is not `main`.
16131×
pub async fn set_default_bookmark(app: &Shared, row: db::repos::RepoRow, asked: &str) -> sqlx::Result<db::repos::RepoRow> {
16231×
    let asked = asked.trim();
16331×
    let b = if asked.is_empty() { default_bookmark_for(app, &row.owner).await.0 } else { asked.to_string() };
16431×
    if b == row.default_bookmark {
16528×
        return Ok(row);
1663×
    }
1673×
    db::repos::set_default_bookmark(&app.db, row.id, &b).await?;
1683×
    Ok(db::repos::get_by_id(&app.db, row.id).await?.unwrap_or(row))
16931×
}
170
171
/// OxygenFlow for a new repository (#371): left to the site's default,
172
/// on the site's runners (a site administrator's choice), or on the
173
/// owner's own runners.
174
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
175
pub enum Flow {
176
    Default,
177
    On,
178
    Own,
179
}
180
181
impl Flow {
18250×
    pub fn parse(choice: &str) -> Result<Flow, String> {
18350×
        match choice.trim() {
18450×
            "" | "default" | "off" => Ok(Flow::Default),
1857×
            "on" => Ok(Flow::On),
1864×
            "own" => Ok(Flow::Own),
1872×
            other => Err(format!("OxygenFlow is on, own or left to the default, not {other}.")),
188
        }
18950×
    }
190
191
    /// The repository's `flow` setting, as Settings › Pipelines writes it.
1924×
    pub fn setting(self) -> &'static str {
1934×
        match self {
1940×
            Flow::Default => "",
1953×
            Flow::On => "on",
1961×
            Flow::Own => "own",
197
        }
1984×
    }
199
}
200
201
/// Whether `owner` has runners of its own (not the site's), which
202
/// [`Flow::Own`] needs before its repository exists.
20363×
pub async fn owner_has_runner(app: &Shared, owner: &str) -> sqlx::Result<bool> {
20463×
    Ok(db::runners::serving_owner(&app.db, owner).await?.iter().any(|r| !r.scope().is_site()))
20563×
}
206
207
/// Checked before the repository is made, as Settings › Pipelines checks.
20844×
pub async fn check_flow(app: &Shared, account: &db::accounts::Account, owner: &str, flow: Flow) -> Result<(), String> {
2092×
    match flow {
21041×
        Flow::Default => Ok(()),
2111×
        Flow::On if account.is_admin => Ok(()),
2121×
        Flow::On => Err("Only site administrators let the site's runners take a repository's jobs.".into()),
2131×
        Flow::Own => match owner_has_runner(app, owner).await.map_err(|e| e.to_string())? {
2140×
            true => Ok(()),
215
            false => {
2161×
                Err(format!("{owner} has no runners of its own yet: register one, then switch OxygenFlow on in Settings › Pipelines."))
217
            }
218
        },
219
    }
22044×
}
221
222
/// Switch OxygenFlow on for the new repository, as chosen.
22331×
pub async fn set_flow(app: &Shared, row: &db::repos::RepoRow, by: &db::accounts::Account, flow: Flow) -> sqlx::Result<()> {
22431×
    if flow == Flow::Default {
22530×
        return Ok(());
2261×
    }
2271×
    db::repos::set_flow(&app.db, row.id, flow.setting()).await?;
2281×
    db::accounts::audit(&app.db, Some(by), "repo.flow", &format!("{}/{}", row.owner, row.name), flow.setting()).await.ok();
2291×
    Ok(())
23031×
}
231
232
/// A new wiki's Home page: the repository's name and description.
2332×
pub fn wiki_home(name: &RepoName, description: &str) -> String {
2342×
    let about = description.trim();
2352×
    let about = if about.is_empty() { String::new() } else { format!("{about}\n\n") };
2362×
    format!("# {}\n\n{about}This is the wiki's home page. Edit it, or add pages beside it.\n", name.name)
2372×
}
238
239
/// Start the repository's wiki with its Home page, written as `by` and
240
/// signed as their delegate, as a wiki edit on the site is.
2410×
pub async fn start_wiki(app: &Shared, row: &db::repos::RepoRow, by: &db::accounts::Account, description: &str) -> Result<(), String> {
2420×
    let name = RepoName::new(&row.owner, &row.name).ok_or("bad repository name")?;
2430×
    let signer = crate::web::edit::signer_for(app, by.id).await?;
2440×
    let edit = FileEdit { path: crate::wiki::path_of(crate::wiki::HOME), content: Some(wiki_home(&name, description).into_bytes()) };
2450×
    crate::wiki::commit(app, &name, vec![edit], "Start the wiki".into(), signer).await.map_err(|e| e.to_string())?;
2460×
    db::accounts::audit(&app.db, Some(by), "wiki.started", &name.to_string(), "Home").await.ok();
2470×
    Ok(())
2480×
}
249
250
/// The licences offered, with what each allows, for the page.
251
pub const LICENCES: &[(&str, &str)] = &[
252
    ("MIT", "use, change and share it freely, keeping the notice"),
253
    ("BSD-2-Clause", "as MIT, in the BSD's words"),
254
    ("ISC", "as MIT, in fewer words"),
255
];
256
257
/// The languages an `.oxyignore` is offered for.
258
pub const IGNORES: &[&str] = &["Rust", "Node", "Python", "Go", "Java and Kotlin"];
259
260
/// What a new repository starts with: the files, by path.
261
#[derive(Clone, Debug, Default, PartialEq, Eq)]
262
pub struct Start {
263
    pub readme: bool,
264
    /// One of [`LICENCES`], or empty.
265
    pub licence: String,
266
    /// One of [`IGNORES`], or empty.
267
    pub ignore: String,
268
}
269
270
impl Start {
2711×
    pub fn is_empty(&self) -> bool {
2721×
        !self.readme && self.licence.is_empty() && self.ignore.is_empty()
2731×
    }
274
275
    /// The files, for a repository `name` described as `description`,
276
    /// whose copyright `holder` keeps in `year`.
27744×
    pub fn files(&self, name: &RepoName, description: &str, holder: &str, year: i32) -> Result<Vec<(String, String)>, String> {
27844×
        let mut out = Vec::new();
27944×
        if self.readme {
2803×
            let about = if description.trim().is_empty() { String::new() } else { format!("{}\n\n", description.trim()) };
2813×
            out.push(("README.md".to_string(), format!("# {}\n\n{about}", name.name)));
28241×
        }
28344×
        if !self.licence.is_empty() {
2842×
            let text = licence(&self.licence, holder, year).ok_or(format!("No licence {}.", self.licence))?;
2851×
            out.push(("LICENSE".to_string(), text));
28642×
        }
28743×
        if !self.ignore.is_empty() {
2881×
            let text = ignore(&self.ignore).ok_or(format!("No .oxyignore for {}.", self.ignore))?;
2891×
            out.push((".oxyignore".to_string(), text.to_string()));
29042×
        }
29143×
        Ok(out)
29244×
    }
293
}
294
2955×
fn licence(id: &str, holder: &str, year: i32) -> Option<String> {
2965×
    Some(match id {
2975×
        "MIT" => format!(
298
            "MIT License\n\nCopyright (c) {year} {holder}\n\n\
299
Permission is hereby granted, free of charge, to any person obtaining a copy\n\
300
of this software and associated documentation files (the \"Software\"), to deal\n\
301
in the Software without restriction, including without limitation the rights\n\
302
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n\
303
copies of the Software, and to permit persons to whom the Software is\n\
304
furnished to do so, subject to the following conditions:\n\n\
305
The above copyright notice and this permission notice shall be included in all\n\
306
copies or substantial portions of the Software.\n\n\
307
THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n\
308
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n\
309
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n\
310
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n\
311
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n\
312
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n\
313
SOFTWARE.\n"
314
        ),
3153×
        "BSD-2-Clause" => format!(
316
            "BSD 2-Clause License\n\nCopyright (c) {year}, {holder}\n\n\
317
Redistribution and use in source and binary forms, with or without\n\
318
modification, are permitted provided that the following conditions are met:\n\n\
319
1. Redistributions of source code must retain the above copyright notice, this\n   \
320
list of conditions and the following disclaimer.\n\n\
321
2. Redistributions in binary form must reproduce the above copyright notice,\n   \
322
this list of conditions and the following disclaimer in the documentation\n   \
323
and/or other materials provided with the distribution.\n\n\
324
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\"\n\
325
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n\
326
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\n\
327
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE\n\
328
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\n\
329
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\n\
330
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\n\
331
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,\n\
332
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n\
333
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n"
334
        ),
3352×
        "ISC" => format!(
336
            "ISC License\n\nCopyright (c) {year} {holder}\n\n\
337
Permission to use, copy, modify, and/or distribute this software for any\n\
338
purpose with or without fee is hereby granted, provided that the above\n\
339
copyright notice and this permission notice appear in all copies.\n\n\
340
THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES\n\
341
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF\n\
342
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR\n\
343
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES\n\
344
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN\n\
345
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF\n\
346
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.\n"
347
        ),
3481×
        _ => return None,
349
    })
3505×
}
351
3526×
fn ignore(lang: &str) -> Option<&'static str> {
3536×
    Some(match lang {
3546×
        "Rust" => "# Build output\ntarget/\n",
3554×
        "Node" => "# Dependencies and build output\nnode_modules/\ndist/\n*.log\n",
3563×
        "Python" => "# Caches, environments and build output\n__pycache__/\n*.pyc\n.venv/\nbuild/\ndist/\n*.egg-info/\n",
3572×
        "Go" => "# Build output\nbin/\n*.test\n",
3581×
        "Java and Kotlin" => "# Build output and tool state\nbuild/\n.gradle/\nout/\n*.class\n",
3590×
        _ => return None,
360
    })
3616×
}
362
363
/// Commit `files` to the new repository's default bookmark as `by`, signed
364
/// as their delegate (as the starter's are); a repository with no files
365
/// yet only.
36631×
pub async fn commit_start(
36731×
    app: &Shared,
36831×
    row: &db::repos::RepoRow,
36931×
    by: &db::accounts::Account,
37031×
    files: Vec<(String, String)>,
37131×
) -> Result<(), String> {
37231×
    if files.is_empty() {
37331×
        return Ok(());
3740×
    }
3750×
    let name = RepoName::new(&row.owner, &row.name).ok_or("bad repository name")?;
3760×
    let signer = crate::web::edit::signer_for(app, by.id).await?;
3770×
    let paths: Vec<String> = files.iter().map(|(p, _)| p.clone()).collect();
3780×
    let edits: Vec<FileEdit> = files.into_iter().map(|(path, content)| FileEdit { path, content: Some(content.into_bytes()) }).collect();
3790×
    let b = row.default_bookmark.clone();
3800×
    crate::repos::edits::commit(&app.repos, &name, b.clone(), b, edits, format!("Start with {}", paths.join(", ")), signer)
3810×
        .await
3820×
        .map_err(|e| e.to_string())?;
3830×
    db::accounts::audit(&app.db, Some(by), "repo.started", &name.to_string(), &paths.join(", ")).await.ok();
3840×
    Ok(())
38531×
}
386
387
#[cfg(test)]
388
mod tests {
389
    use super::*;
390
391
    #[test]
3921×
    fn boards_and_starting_files() {
3931×
        assert_eq!(Board::parse("", "", "demo").unwrap(), Board::None);
3941×
        assert_eq!(Board::parse("new", " ", "demo").unwrap(), Board::New("demo".into()));
3951×
        assert_eq!(Board::parse("new", "Roadmap", "demo").unwrap(), Board::New("Roadmap".into()));
3961×
        assert_eq!(Board::parse("4", "", "demo").unwrap(), Board::Existing(4));
3971×
        assert!(Board::parse("four", "", "demo").is_err());
3981×
        let name = RepoName::new("andy", "demo").unwrap();
3991×
        let s = Start { readme: true, licence: "MIT".into(), ignore: "Rust".into() };
4001×
        let files = s.files(&name, "A demo.", "Andy McCall", 2026).unwrap();
4013×
        let paths: Vec<&str> = files.iter().map(|(p, _)| p.as_str()).collect();
4021×
        assert_eq!(paths, ["README.md", "LICENSE", ".oxyignore"]);
4031×
        assert_eq!(files[0].1, "# demo\n\nA demo.\n\n");
4041×
        assert!(files[1].1.starts_with("MIT License\n\nCopyright (c) 2026 Andy McCall\n"));
4051×
        assert_eq!(files[2].1, "# Build output\ntarget/\n");
4063×
        for (id, _) in LICENCES {
4073×
            assert!(licence(id, "X", 2026).unwrap().contains("2026"), "{id}");
408
        }
4095×
        for lang in IGNORES {
4105×
            assert!(ignore(lang).is_some(), "{lang}");
411
        }
4121×
        assert!(Start { licence: "GPL".into(), ..Default::default() }.files(&name, "", "X", 2026).is_err());
4131×
        assert!(Start::default().is_empty());
4141×
    }
415
416
    #[test]
4171×
    fn flow_choices_and_the_wiki_home() {
4181×
        assert_eq!(Flow::parse("").unwrap(), Flow::Default);
4191×
        assert_eq!(Flow::parse("off").unwrap(), Flow::Default);
4201×
        assert_eq!(Flow::parse("on").unwrap().setting(), "on");
4211×
        assert_eq!(Flow::parse("own").unwrap().setting(), "own");
4221×
        assert!(Flow::parse("always").is_err());
4231×
        let name = RepoName::new("andy", "square").unwrap();
4241×
        assert_eq!(
4251×
            wiki_home(&name, " A platform game. "),
426
            "# square\n\nA platform game.\n\nThis is the wiki's home page. Edit it, or add pages beside it.\n"
427
        );
4281×
        assert!(wiki_home(&name, "").starts_with("# square\n\nThis is"));
4291×
    }
430
431
    #[test]
4321×
    fn bookmark_defaults_are_kept_apart() {
4331×
        assert_eq!(BookmarkScope::Site.key(), "default_bookmark");
4341×
        assert_eq!(BookmarkScope::Account(7).key(), "default_bookmark.account.7");
4351×
        assert_eq!(BookmarkScope::Org(7).key(), "default_bookmark.org.7");
4361×
        assert!(check_bookmark("develop").is_ok());
4371×
        assert!(check_bookmark("release-1.0").is_ok());
4381×
        assert!(check_bookmark("feature/x").is_err());
4391×
        assert!(check_bookmark("-x").is_err());
4401×
    }
441
}