Radish alpha
r
Radicle CI broker
Radicle
Git (anonymous pull)
Log in to clone via SSH
refactor: simplify handling of parse_ref result
Lars Wirzenius committed 1 year ago
commit 3a9f8ff3e2e52aebf97f1b4889d9b38445a6b594
parent e842e01ac1e32c9f995f3a2690823a5cc74cfe4d
1 file changed +30 -31
modified src/msg.rs
@@ -153,38 +153,37 @@ impl<'a> RequestBuilder<'a> {
            }
        };

-
        let mut push: Option<PushEvent> = None;
-
        let mut patch: Option<PatchEvent> = None;
-
        let event_type: EventType;
-
        if let Some(parsed_ref) = parse_ref(name) {
-
            match parsed_ref {
-
                ParsedRef::Patch(_oid) => {
-
                    event_type = EventType::Patch;
-
                    patch = Some(
-
                        self.build_trigger_from_patch(event, repository, &repo, profile, author)?,
-
                    );
-
                }
-
                ParsedRef::Push(_branch) => {
-
                    event_type = EventType::Push;
-
                    let before_oid: Oid = old.unwrap_or(*oid);
-
                    push =
-
                        Some(self.build_trigger_from_push(repo, author, name, before_oid, *oid)?);
-
                }
-
            }
-
            let common = EventCommonFields {
-
                version: PROTOCOL_VERSION,
-
                event_type,
-
                repository: msg_repository,
-
            };
+
        let (event_type, push, patch) = match parse_ref(name) {
+
            None => Err(MessageError::NoEventHandler)?,
+
            Some(ParsedRef::Patch(_oid)) => (
+
                EventType::Patch,
+
                None,
+
                Some(self.build_trigger_from_patch(event, repository, &repo, profile, author)?),
+
            ),
+
            Some(ParsedRef::Push(_branch)) => (
+
                EventType::Push,
+
                Some(self.build_trigger_from_push(
+
                    repo,
+
                    author,
+
                    name,
+
                    old.unwrap_or(*oid),
+
                    *oid,
+
                )?),
+
                None,
+
            ),
+
        };

-
            Ok(Request::Trigger {
-
                common,
-
                push,
-
                patch,
-
            })
-
        } else {
-
            Err(MessageError::NoEventHandler)
-
        }
+
        let common = EventCommonFields {
+
            version: PROTOCOL_VERSION,
+
            event_type,
+
            repository: msg_repository,
+
        };
+

+
        Ok(Request::Trigger {
+
            common,
+
            push,
+
            patch,
+
        })
    }

    fn build_trigger_from_patch(