diff options
author | Lars Wirzenius <liw@liw.fi> | 2024-02-02 17:30:22 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2024-02-02 17:37:20 +0200 |
commit | 1321c25f296ccf6ef80c7eeb1136d9bbd786af86 (patch) | |
tree | 5935ce1bd5de030f1ff79e801ea6ca53ba5fae86 | |
parent | 84051a2f1dc0b90ca6e391d6e47ab6ee25734b5b (diff) | |
download | radicle-ci-broker-1321c25f296ccf6ef80c7eeb1136d9bbd786af86.tar.gz |
feat(src/msg.rs): add helpers to get repo, commit from Request
This relieves uses for a Request from having to unpack it with pattern
matching. The helpers are much more convenient, when they are sufficient.
Signed-off-by: Lars Wirzenius <liw@liw.fi>
-rw-r--r-- | src/msg.rs | 31 |
1 files changed, 31 insertions, 0 deletions
@@ -111,6 +111,37 @@ pub enum Request { } impl Request { + /// Repository that the event concerns. + pub fn repo(&self) -> RepoId { + match self { + Self::Trigger { + common, + push: _, + patch: _, + } => common.repository.id, + } + } + + /// Return the commit the event concerns. In other words, the + /// commit that CI should run against. + pub fn commit(&self) -> Oid { + match self { + Self::Trigger { + common: _, + push, + patch, + } => { + if let Some(push) = push { + *push.commits.last().unwrap() + } else if let Some(patch) = patch { + *patch.patch.commits.last().unwrap() + } else { + panic!("neither push not panic: {self:#?}"); + } + } + } + } + /// Create a request event to trigger a run. pub fn trigger(profile: &Profile, event: &BrokerEvent) -> Result<Self, MessageError> { let BrokerEvent::RefChanged { |