Radish alpha
r
rad:zwTxygwuz5LDGBq255RA2CbNGrz8
Radicle CI broker
Radicle
Git
feat: `cibtool event add` defaults to default branch
Lars Wirzenius committed 8 months ago
commit 562465ef931917f9946a99762f6ccca63975b0c2
parent 5950499
2 files changed +44 -31
modified ci-broker.md
@@ -700,7 +700,7 @@ Verify that `cib` can process a branch creation event.

~~~
when I run rm -f ci-broker.db
-
when I run cibtool --db ci-broker.db event add --repo xyzzy --ref main --commit HEAD --kind branch-created --id-file id.txt
+
when I run cibtool --db ci-broker.db event add --repo xyzzy --commit HEAD --kind branch-created --id-file id.txt
when I run ./env.sh cib --config broker.yaml queued
when I run cibtool --db ci-broker.db run list
then stdout has one line
@@ -720,7 +720,7 @@ Verify that `cib` can process a branch deletion event.

~~~
when I run rm -f ci-broker.db
-
when I run cibtool --db ci-broker.db event add --repo xyzzy --ref main --commit HEAD --kind branch-deleted --id-file id.txt
+
when I run cibtool --db ci-broker.db event add --repo xyzzy --commit HEAD --kind branch-deleted --id-file id.txt
when I run ./env.sh cib --config broker.yaml queued
when I run cibtool --db ci-broker.db run list
then stdout has one line
@@ -730,7 +730,7 @@ Verify that `cib` can process a patch creation event.

~~~
when I run rm -f ci-broker.db
-
when I run cibtool --db ci-broker.db event add --repo xyzzy --ref main --commit HEAD --kind patch-created --patch-id-file patch-id.txt --id-file id.txt
+
when I run cibtool --db ci-broker.db event add --repo xyzzy --commit HEAD --kind patch-created --patch-id-file patch-id.txt --id-file id.txt
when I run ./env.sh cib --config broker.yaml queued
when I run cibtool --db ci-broker.db run list
then stdout has one line
@@ -740,7 +740,7 @@ Verify that `cib` can process a patch update event.

~~~
when I run rm -f ci-broker.db
-
when I run cibtool --db ci-broker.db event add --repo xyzzy --ref main --commit HEAD --kind patch-updated --patch-id-file patch-id.txt --id-file id.txt
+
when I run cibtool --db ci-broker.db event add --repo xyzzy --commit HEAD --kind patch-updated --patch-id-file patch-id.txt --id-file id.txt
when I run ./env.sh cib --config broker.yaml queued
when I run cibtool --db ci-broker.db run list
then stdout has one line
@@ -1020,8 +1020,8 @@ given a Radicle node, with CI configured with broker.yaml and adapter dummy.sh
given a Git repository xyzzy in the Radicle node
given a directory reports

-
when I run ./env.sh cibtool --db ci-broker.db event add --repo xyzzy --ref main --commit f42ea5cb9ce2dc7a9b87834ccee5b9bb3867db90 --kind branch-updated --base main
-
when I run ./env.sh cibtool --db ci-broker.db event add --repo xyzzy --ref main --commit HEAD --kind branch-updated --base main
+
when I run ./env.sh cibtool --db ci-broker.db event add --repo xyzzy --commit f42ea5cb9ce2dc7a9b87834ccee5b9bb3867db90 --kind branch-updated --base main
+
when I run ./env.sh cibtool --db ci-broker.db event add --repo xyzzy --commit HEAD --kind branch-updated --base main

when I run ./env.sh cib --config broker.yaml queued
then stderr contains "f42ea5cb9ce2dc7a9b87834ccee5b9bb3867db90"
@@ -1224,7 +1224,7 @@ given a Git repository xyzzy in the Radicle node

given file config.yaml from filter-branchcreated.yaml

-
when I run cibtool --db ci-broker.db event add --repo xyzzy --ref main --commit HEAD --kind branch-created
+
when I run cibtool --db ci-broker.db event add --repo xyzzy --commit HEAD --kind branch-created
when I run cibtool --db ci-broker.db event add --repo xyzzy --ref oksa --commit HEAD --kind branch-updated --base main

when I run ./env.sh cib --config config.yaml queued
@@ -1259,7 +1259,7 @@ given a Git repository xyzzy in the Radicle node

given file config.yaml from filter-branchupdated.yaml

-
when I run cibtool --db ci-broker.db event add --repo xyzzy --ref main --commit HEAD --kind branch-updated --base main
+
when I run cibtool --db ci-broker.db event add --repo xyzzy --commit HEAD --kind branch-updated --base main
when I run cibtool --db ci-broker.db event add --repo xyzzy --ref oksa --commit HEAD --kind branch-created

when I run ./env.sh cib --config config.yaml queued
@@ -1294,7 +1294,7 @@ given a Git repository xyzzy in the Radicle node

given file config.yaml from filter-branchdeleted.yaml

-
when I run cibtool --db ci-broker.db event add --repo xyzzy --ref main --commit HEAD --kind branch-deleted
+
when I run cibtool --db ci-broker.db event add --repo xyzzy --commit HEAD --kind branch-deleted
when I run cibtool --db ci-broker.db event add --repo xyzzy --ref oksa --commit HEAD --kind branch-created

when I run ./env.sh cib --config config.yaml queued
@@ -1328,7 +1328,7 @@ given a Git repository xyzzy in the Radicle node

given file config.yaml from filter-allow.yaml

-
when I run cibtool --db ci-broker.db event add --repo xyzzy --ref main --commit HEAD --kind branch-deleted
+
when I run cibtool --db ci-broker.db event add --repo xyzzy --commit HEAD --kind branch-deleted
when I run cibtool --db ci-broker.db event add --repo xyzzy --ref oksa --commit HEAD --kind branch-created

when I run ./env.sh cib --config config.yaml queued
@@ -1362,7 +1362,7 @@ given a Git repository xyzzy in the Radicle node

given file config.yaml from filter-deny.yaml

-
when I run cibtool --db ci-broker.db event add --repo xyzzy --ref main --commit HEAD --kind branch-deleted
+
when I run cibtool --db ci-broker.db event add --repo xyzzy --commit HEAD --kind branch-deleted
when I run cibtool --db ci-broker.db event add --repo xyzzy --ref oksa --commit HEAD --kind branch-created

when I run ./env.sh cib --config config.yaml queued
@@ -1397,7 +1397,7 @@ given a Git repository xyzzy in the Radicle node

given file config.yaml from filter-and.yaml

-
when I run cibtool --db ci-broker.db event add --repo xyzzy --ref main --commit HEAD --kind branch-deleted
+
when I run cibtool --db ci-broker.db event add --repo xyzzy --commit HEAD --kind branch-deleted
when I run cibtool --db ci-broker.db event add --repo xyzzy --ref oksa --commit HEAD --kind branch-created

when I run ./env.sh cib --config config.yaml queued
@@ -1434,7 +1434,7 @@ given a Git repository xyzzy in the Radicle node

given file config.yaml from filter-or.yaml

-
when I run cibtool --db ci-broker.db event add --repo xyzzy --ref main --commit HEAD --kind branch-deleted
+
when I run cibtool --db ci-broker.db event add --repo xyzzy --commit HEAD --kind branch-deleted
when I run cibtool --db ci-broker.db event add --repo xyzzy --ref oksa --commit HEAD --kind branch-created

when I run ./env.sh cib --config config.yaml queued
@@ -1470,7 +1470,7 @@ given a Git repository xyzzy in the Radicle node

given file config.yaml from filter-not.yaml

-
when I run cibtool --db ci-broker.db event add --repo xyzzy --ref main --commit HEAD --kind branch-deleted
+
when I run cibtool --db ci-broker.db event add --repo xyzzy --commit HEAD --kind branch-deleted
when I run cibtool --db ci-broker.db event add --repo xyzzy --ref oksa --commit HEAD --kind branch-created

when I run ./env.sh cib --config config.yaml queued
@@ -1507,7 +1507,7 @@ given a Git repository xyzzy in the Radicle node

given file config.yaml from filter-defaultbranch.yaml

-
when I run cibtool --db ci-broker.db event add --repo xyzzy --ref main --commit HEAD --kind branch-created
+
when I run cibtool --db ci-broker.db event add --repo xyzzy --commit HEAD --kind branch-created
when I run cibtool --db ci-broker.db event add --repo xyzzy --ref oksa --commit HEAD --kind branch-created

when I run ./env.sh cib --config config.yaml queued
@@ -1542,13 +1542,13 @@ given a Radicle node, with CI configured with broker.yaml and adapter dummy.sh
given a Git repository xyzzy in the Radicle node

given file config.yaml from filter-hasfile-missing.yaml
-
when I run cibtool --db ci-broker.db event add --repo xyzzy --ref main --commit HEAD --kind branch-created
+
when I run cibtool --db ci-broker.db event add --repo xyzzy --commit HEAD --kind branch-created
when I run ./env.sh cib --config config.yaml queued
when I run cibtool --db ci-broker.db run list --json
then stdout doesn't contain "main"

given file config.yaml from filter-hasfile.yaml
-
when I run cibtool --db ci-broker.db event add --repo xyzzy --ref main --commit HEAD --kind branch-created
+
when I run cibtool --db ci-broker.db event add --repo xyzzy --commit HEAD --kind branch-created
when I run ./env.sh cib --config config.yaml queued
when I run cibtool --db ci-broker.db run list --json
then stdout contains "main"
@@ -1778,7 +1778,7 @@ down.
given a Radicle node, with CI configured with broker.yaml and adapter dummy.sh
given a Git repository testy in the Radicle node

-
when I run ./env.sh cibtool --db ci-broker.db event add --repo testy --ref main --commit HEAD --kind branch-updated --base main
+
when I run ./env.sh cibtool --db ci-broker.db event add --repo testy --commit HEAD --kind branch-updated --base main
when I run cibtool --db ci-broker.db event shutdown

given a directory reports
@@ -1901,7 +1901,7 @@ given a Git repository xyzzy in the Radicle node
when I run cibtool --db x.db event list
then stdout is empty

-
when I run ./env.sh cibtool --db x.db event add --repo xyzzy --ref main --commit HEAD --base HEAD --id-file id.txt --kind branch-updated
+
when I run ./env.sh cibtool --db x.db event add --repo xyzzy --commit HEAD --base HEAD --id-file id.txt --kind branch-updated

when I run cibtool --db x.db event show --id-file id.txt
then stdout contains "rad:"
@@ -1930,12 +1930,12 @@ given a Git repository testy in the Radicle node
when I run cibtool --db x.db event list
then stdout is empty

-
when I run ./env.sh cibtool --db x.db event add --repo testy --ref main --commit HEAD --base HEAD --kind branch-updated
-
when I run ./env.sh cibtool --db x.db event add --repo testy --ref main --commit HEAD --base HEAD --kind branch-updated
-
when I run ./env.sh cibtool --db x.db event add --repo testy --ref main --commit HEAD --base HEAD --kind branch-updated
-
when I run ./env.sh cibtool --db x.db event add --repo testy --ref main --commit HEAD --base HEAD --kind branch-updated
-
when I run ./env.sh cibtool --db x.db event add --repo testy --ref main --commit HEAD --base HEAD --kind branch-updated
-
when I run ./env.sh cibtool --db x.db event add --repo testy --ref main --commit HEAD --base HEAD --kind branch-updated
+
when I run ./env.sh cibtool --db x.db event add --repo testy --commit HEAD --base HEAD --kind branch-updated
+
when I run ./env.sh cibtool --db x.db event add --repo testy --commit HEAD --base HEAD --kind branch-updated
+
when I run ./env.sh cibtool --db x.db event add --repo testy --commit HEAD --base HEAD --kind branch-updated
+
when I run ./env.sh cibtool --db x.db event add --repo testy --commit HEAD --base HEAD --kind branch-updated
+
when I run ./env.sh cibtool --db x.db event add --repo testy --commit HEAD --base HEAD --kind branch-updated
+
when I run ./env.sh cibtool --db x.db event add --repo testy --commit HEAD --base HEAD --kind branch-updated

when I run cibtool --db x.db event remove --all
when I run cibtool --db x.db event list
@@ -2295,11 +2295,11 @@ Note that we verify both lookup by name and by repository ID, and by
given a Radicle node, with CI configured with broker.yaml and adapter dummy.sh
given a Git repository testy in the Radicle node

-
when I try to run ./env.sh cibtool --db x.db event add --repo missing --ref main --commit HEAD --base c0ffee --kind branch-updated
+
when I try to run ./env.sh cibtool --db x.db event add --repo missing --commit HEAD --base c0ffee --kind branch-updated
then command fails
then stderr contains "missing"

-
when I try to run ./env.sh cibtool --db x.db event add --repo rad:z3byzFpcfbMJBp4tKYyuuTZiP8WUB --ref main --commit HEAD --base c0ffee --kind branch-updated
+
when I try to run ./env.sh cibtool --db x.db event add --repo rad:z3byzFpcfbMJBp4tKYyuuTZiP8WUB --commit HEAD --base c0ffee --kind branch-updated
then command fails
then stderr contains "rad:z3byzFpcfbMJBp4tKYyuuTZiP8WUB"

modified src/bin/cibtoolcmd/event.rs
@@ -77,9 +77,10 @@ pub struct AddEvent {
    #[clap(long)]
    repo: String,

-
    /// Set the name of the ref the event refers to.
+
    /// Set the name of the ref the event refers to. Default is the
+
    /// default branch.
    #[clap(long, alias = "ref")]
-
    name: String,
+
    name: Option<String>,

    /// Set the commit the event refers to. Can be the SHA1 commit id,
    /// or a symbolic Git revision, as understood by `git rev-parse`.
@@ -181,8 +182,20 @@ impl Leaf for AddEvent {
            self.lookup_commit(rid, &self.commit)?
        };

-
        let branch_name = branch_ref(&ref_string(&self.name).map_err(CibToolError::RefError)?)
-
            .map_err(CibToolError::RefError)?;
+
        let branch_name = if let Some(name) = &self.name {
+
            branch_ref(&ref_string(name).map_err(CibToolError::RefError)?)
+
                .map_err(CibToolError::RefError)?
+
        } else {
+
            let profile = util::load_profile()?;
+
            let repo = profile
+
                .storage
+
                .repository(rid)
+
                .map_err(|err| CibToolError::RepoOpen(rid, err))?;
+
            let project = repo
+
                .project()
+
                .map_err(|err| CibToolError::GetProject(rid, err))?;
+
            project.default_branch().clone()
+
        };

        let event = match &self.kind {
            EventKind::BranchCreated => {