Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

organize github crate (#1773)

Will Hutchinsoned86bfafce6e
diff --git a/rust/cloud-storage/github/src/domain/models/link.rs b/rust/cloud-storage/github/src/domain/models/link.rs
new file mode 100644
index 0000000000..e1c0e08a29
--- /dev/null
+++ b/rust/cloud-storage/github/src/domain/models/link.rs
@@ -0,0 +1,65 @@
+//! Domain models for github link operations (OAuth and account linking).
+
+use macro_user_id::user_id::MacroUserIdStr;
+use serde::Deserialize;
+
+/// Github access token
+#[derive(Clone)]
+#[allow(dead_code)]
+pub struct GithubAccessToken(String);
+
+impl GithubAccessToken {
+ /// Creates a new GithubAccessToken
+ pub fn new(token: String) -> Self {
+ Self(token)
+ }
+}
+
+/// A GitHub link record (as stored in the database)
+#[derive(Debug, Clone)]
+pub struct GithubLink {
+ /// Unique ID for this link
+ pub id: uuid::Uuid,
+ /// Macro user ID
+ pub macro_id: MacroUserIdStr<'static>,
+ /// FusionAuth user ID
+ pub fusionauth_user_id: uuid::Uuid,
+ /// GitHub username
+ pub github_username: String,
+ /// GitHub user ID (as string)
+ pub github_user_id: String,
+ /// When the link was created
+ pub created_at: chrono::DateTime<chrono::Utc>,
+ /// When the link was last updated
+ pub updated_at: chrono::DateTime<chrono::Utc>,
+}
+
+/// GitHub OAuth token exchange response
+#[derive(Debug, Deserialize)]
+pub struct GithubExchangeTokenResponse {
+ /// The access token for Github API calls
+ pub access_token: String,
+ /// The type of token (usually "bearer")
+ pub token_type: String,
+ /// The scopes granted to this token
+ pub scope: String,
+ /// The refresh token (only present if token expiration is enabled in Github App settings)
+ pub refresh_token: Option<String>,
+ /// Seconds until access token expires (only present if token expiration is enabled)
+ pub expires_in: Option<i64>,
+ /// Seconds until refresh token expires (only present if token expiration is enabled)
+ pub refresh_token_expires_in: Option<i64>,
+}
+
+/// Github user information retrieved from Github API
+#[derive(Debug, Deserialize)]
+pub struct GithubUserInfo {
+ /// Github user ID (numeric)
+ pub id: u64,
+ /// Github username
+ pub login: String,
+ /// Primary email (may be null if private)
+ pub email: Option<String>,
+ /// Display name
+ pub name: Option<String>,
+}
diff --git a/rust/cloud-storage/github/src/domain/models/mod.rs b/rust/cloud-storage/github/src/domain/models/mod.rs
index 8e81b9b54e..3e6de6336e 100644
--- a/rust/cloud-storage/github/src/domain/models/mod.rs
+++ b/rust/cloud-storage/github/src/domain/models/mod.rs
@@ -3,34 +3,11 @@
#[cfg(test)]
mod test;
-use std::collections::HashSet;
-use std::fmt;
-use std::sync::LazyLock;
+mod link;
+mod sync;
-use macro_user_id::user_id::MacroUserIdStr;
-use regex::Regex;
-use serde::Deserialize;
-
-/// Github access token
-#[derive(Clone)]
-#[allow(dead_code)]
-pub struct GithubAccessToken(String);
-
-impl GithubAccessToken {
- /// Creates a new GithubAccessToken
- pub fn new(token: String) -> Self {
- Self(token)
- }
-}
-
-/// GitHub App installation access token response
-#[derive(Debug, Clone, Deserialize)]
-pub struct GithubInstallationAccessToken {
- /// The installation access token
- pub token: String,
- /// When the token expires
- pub expires_at: String,
-}
+pub use link::*;
+pub use sync::*;
/// Errors that can occur during github operations.
#[derive(Debug, thiserror::Error)]
@@ -51,224 +28,3 @@ pub enum GithubError {
#[error("invalid github webhook signature")]
InvalidWebhookSignature,
}
-
-/// A GitHub link record (as stored in the database)
-#[derive(Debug, Clone)]
-pub struct GithubLink {
- /// Unique ID for this link
- pub id: uuid::Uuid,
- /// Macro user ID
- pub macro_id: MacroUserIdStr<'static>,
- /// FusionAuth user ID
- pub fusionauth_user_id: uuid::Uuid,
- /// GitHub username
- pub github_username: String,
- /// GitHub user ID (as string)
- pub github_user_id: String,
- /// When the link was created
- pub created_at: chrono::DateTime<chrono::Utc>,
- /// When the link was last updated
- pub updated_at: chrono::DateTime<chrono::Utc>,
-}
-
-/// GitHub OAuth token exchange response
-#[derive(Debug, Deserialize)]
-pub struct GithubExchangeTokenResponse {
- /// The access token for Github API calls
- pub access_token: String,
- /// The type of token (usually "bearer")
- pub token_type: String,
- /// The scopes granted to this token
- pub scope: String,
- /// The refresh token (only present if token expiration is enabled in Github App settings)
- pub refresh_token: Option<String>,
- /// Seconds until access token expires (only present if token expiration is enabled)
- pub expires_in: Option<i64>,
- /// Seconds until refresh token expires (only present if token expiration is enabled)
- pub refresh_token_expires_in: Option<i64>,
-}
-
-/// Github user information retrieved from Github API
-#[derive(Debug, Deserialize)]
-pub struct GithubUserInfo {
- /// Github user ID (numeric)
- pub id: u64,
- /// Github username
- pub login: String,
- /// Primary email (may be null if private)
- pub email: Option<String>,
- /// Display name
- pub name: Option<String>,
-}
-
-/// A validated github webhook event
-#[derive(Debug)]
-pub struct ValidatedGithubWebhookEvent {
- /// The event type from the `X-GitHub-Event` header
- pub event_type: String,
- /// The parsed JSON payload
- pub payload: serde_json::Value,
-}
-
-impl ValidatedGithubWebhookEvent {
- /// Create a new ValidatedGithubWebhookEvent
- pub fn new(event_type: String, payload: serde_json::Value) -> Self {
- Self {
- event_type,
- payload,
- }
- }
-
- /// Parse the raw event type string into a [`GithubWebhookEventType`].
- pub fn parsed_event_type(&self) -> GithubWebhookEventType {
- GithubWebhookEventType::from_event_header(&self.event_type)
- }
-
- /// Extract all text fields worth searching for task IDs, based on event type.
- pub fn extract_searchable_text(&self) -> Vec<String> {
- let mut texts = Vec::new();
- match self.parsed_event_type() {
- GithubWebhookEventType::PullRequest => {
- if let Some(pr) = self.payload.get("pull_request") {
- if let Some(s) = pr.get("title").and_then(|v| v.as_str()) {
- texts.push(s.to_string());
- }
- if let Some(s) = pr.get("body").and_then(|v| v.as_str()) {
- texts.push(s.to_string());
- }
- if let Some(s) = pr
- .get("head")
- .and_then(|h| h.get("ref"))
- .and_then(|v| v.as_str())
- {
- texts.push(s.to_string());
- }
- }
- }
- GithubWebhookEventType::IssueComment
- | GithubWebhookEventType::PullRequestReviewComment => {
- if let Some(s) = self
- .payload
- .get("comment")
- .and_then(|c| c.get("body"))
- .and_then(|v| v.as_str())
- {
- texts.push(s.to_string());
- }
- }
- GithubWebhookEventType::PullRequestReview => {
- if let Some(s) = self
- .payload
- .get("review")
- .and_then(|r| r.get("body"))
- .and_then(|v| v.as_str())
- {
- texts.push(s.to_string());
- }
- }
- GithubWebhookEventType::Unknown(_) => {}
- }
- texts
- }
-}
-
-/// Known GitHub webhook event types we handle.
-#[derive(Debug, Clone, PartialEq, Eq)]
-pub enum GithubWebhookEventType {
- /// `pull_request` events
- PullRequest,
- /// `issue_comment` events (includes comments on PRs)
- IssueComment,
- /// `pull_request_review` events
- PullRequestReview,
- /// `pull_request_review_comment` events
- PullRequestReviewComment,
- /// Any event type we don't handle
- Unknown(String),
-}
-
-impl GithubWebhookEventType {
- /// Map the raw `X-GitHub-Event` header value to a variant.
- pub fn from_event_header(s: &str) -> Self {
- match s {
- "pull_request" => Self::PullRequest,
- "issue_comment" => Self::IssueComment,
- "pull_request_review" => Self::PullRequestReview,
- "pull_request_review_comment" => Self::PullRequestReviewComment,
- other => Self::Unknown(other.to_string()),
- }
- }
-}
-
-/// Regex matching `MACRO-{short_uuid}` (case-insensitive).
-/// The capture group contains only the Flickr base58 short UUID portion.
-static MACRO_TASK_ID_RE: LazyLock<Regex> = LazyLock::new(|| {
- Regex::new(r"(?i)macro-([123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ]+)")
- .expect("valid regex")
-});
-
-/// A Macro task ID in the form `MACRO-{short_uuid}`.
-#[derive(Debug, Clone, PartialEq, Eq, Hash)]
-pub struct MacroTaskId {
- /// The Flickr base58 short UUID portion
- pub short_uuid: String,
-}
-
-impl MacroTaskId {
- /// Create from a raw short UUID string, validating that all characters
- /// are in the Flickr base58 alphabet.
- pub fn from_short_uuid(s: &str) -> Option<Self> {
- let converter = macro_uuid::ShortUuidConverter::default();
- if converter.is_short_uuid(s) {
- Some(Self {
- short_uuid: s.to_string(),
- })
- } else {
- None
- }
- }
-
- /// Create from a full UUID by converting to a short UUID.
- pub fn from_uuid(uuid: &uuid::Uuid) -> Self {
- let converter = macro_uuid::ShortUuidConverter::default();
- Self {
- short_uuid: converter.from_uuid(uuid),
- }
- }
-
- /// Convert back to a full UUID.
- pub fn to_uuid(&self) -> anyhow::Result<uuid::Uuid> {
- let converter = macro_uuid::ShortUuidConverter::default();
- converter.to_uuid(&self.short_uuid)
- }
-
- /// Returns the canonical `MACRO-{short_uuid}` string.
- pub fn to_task_id_string(&self) -> String {
- format!("MACRO-{}", self.short_uuid)
- }
-
- /// Extract all unique `MACRO-{short_uuid}` references from text.
- /// Matching is case-insensitive on the `MACRO-` prefix; the short UUID
- /// portion is preserved as captured.
- pub fn extract_from_text(text: &str) -> Vec<MacroTaskId> {
- let mut seen = HashSet::new();
- let mut results = Vec::new();
-
- for caps in MACRO_TASK_ID_RE.captures_iter(text) {
- let short = &caps[1];
- if seen.insert(short.to_string())
- && let Some(task_id) = Self::from_short_uuid(short)
- {
- results.push(task_id);
- }
- }
-
- results
- }
-}
-
-impl fmt::Display for MacroTaskId {
- fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- write!(f, "MACRO-{}", self.short_uuid)
- }
-}
diff --git a/rust/cloud-storage/github/src/domain/models/sync.rs b/rust/cloud-storage/github/src/domain/models/sync.rs
new file mode 100644
index 0000000000..eb32f11436
--- /dev/null
+++ b/rust/cloud-storage/github/src/domain/models/sync.rs
@@ -0,0 +1,189 @@
+//! Domain models for github sync operations (webhooks and sync app).
+
+use std::collections::HashSet;
+use std::fmt;
+use std::sync::LazyLock;
+
+use regex::Regex;
+use serde::Deserialize;
+
+/// GitHub App installation access token response
+#[derive(Debug, Clone, Deserialize)]
+pub struct GithubInstallationAccessToken {
+ /// The installation access token
+ pub token: String,
+ /// When the token expires
+ pub expires_at: String,
+}
+
+/// A validated github webhook event
+#[derive(Debug)]
+pub struct ValidatedGithubWebhookEvent {
+ /// The event type from the `X-GitHub-Event` header
+ pub event_type: String,
+ /// The parsed JSON payload
+ pub payload: serde_json::Value,
+}
+
+impl ValidatedGithubWebhookEvent {
+ /// Create a new ValidatedGithubWebhookEvent
+ pub fn new(event_type: String, payload: serde_json::Value) -> Self {
+ Self {
+ event_type,
+ payload,
+ }
+ }
+
+ /// Parse the raw event type string into a [`GithubWebhookEventType`].
+ pub fn parsed_event_type(&self) -> GithubWebhookEventType {
+ GithubWebhookEventType::from_event_header(&self.event_type)
+ }
+
+ /// Extract all text fields worth searching for task IDs, based on event type.
+ pub fn extract_searchable_text(&self) -> Vec<String> {
+ let mut texts = Vec::new();
+ match self.parsed_event_type() {
+ GithubWebhookEventType::PullRequest => {
+ if let Some(pr) = self.payload.get("pull_request") {
+ if let Some(s) = pr.get("title").and_then(|v| v.as_str()) {
+ texts.push(s.to_string());
+ }
+ if let Some(s) = pr.get("body").and_then(|v| v.as_str()) {
+ texts.push(s.to_string());
+ }
+ if let Some(s) = pr
+ .get("head")
+ .and_then(|h| h.get("ref"))
+ .and_then(|v| v.as_str())
+ {
+ texts.push(s.to_string());
+ }
+ }
+ }
+ GithubWebhookEventType::IssueComment
+ | GithubWebhookEventType::PullRequestReviewComment => {
+ if let Some(s) = self
+ .payload
+ .get("comment")
+ .and_then(|c| c.get("body"))
+ .and_then(|v| v.as_str())
+ {
+ texts.push(s.to_string());
+ }
+ }
+ GithubWebhookEventType::PullRequestReview => {
+ if let Some(s) = self
+ .payload
+ .get("review")
+ .and_then(|r| r.get("body"))
+ .and_then(|v| v.as_str())
+ {
+ texts.push(s.to_string());
+ }
+ }
+ GithubWebhookEventType::Unknown(_) => {}
+ }
+ texts
+ }
+}
+
+/// Known GitHub webhook event types we handle.
+#[derive(Debug, Clone, PartialEq, Eq)]
+pub enum GithubWebhookEventType {
+ /// `pull_request` events
+ PullRequest,
+ /// `issue_comment` events (includes comments on PRs)
+ IssueComment,
+ /// `pull_request_review` events
+ PullRequestReview,
+ /// `pull_request_review_comment` events
+ PullRequestReviewComment,
+ /// Any event type we don't handle
+ Unknown(String),
+}
+
+impl GithubWebhookEventType {
+ /// Map the raw `X-GitHub-Event` header value to a variant.
+ pub fn from_event_header(s: &str) -> Self {
+ match s {
+ "pull_request" => Self::PullRequest,
+ "issue_comment" => Self::IssueComment,
+ "pull_request_review" => Self::PullRequestReview,
+ "pull_request_review_comment" => Self::PullRequestReviewComment,
+ other => Self::Unknown(other.to_string()),
+ }
+ }
+}
+
+/// Regex matching `MACRO-{short_uuid}` (case-insensitive).
+/// The capture group contains only the Flickr base58 short UUID portion.
+static MACRO_TASK_ID_RE: LazyLock<Regex> = LazyLock::new(|| {
+ Regex::new(r"(?i)macro-([123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ]+)")
+ .expect("valid regex")
+});
+
+/// A Macro task ID in the form `MACRO-{short_uuid}`.
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
+pub struct MacroTaskId {
+ /// The Flickr base58 short UUID portion
+ pub short_uuid: String,
+}
+
+impl MacroTaskId {
+ /// Create from a raw short UUID string, validating that all characters
+ /// are in the Flickr base58 alphabet.
+ pub fn from_short_uuid(s: &str) -> Option<Self> {
+ let converter = macro_uuid::ShortUuidConverter::default();
+ if converter.is_short_uuid(s) {
+ Some(Self {
+ short_uuid: s.to_string(),
+ })
+ } else {
+ None
+ }
+ }
+
+ /// Create from a full UUID by converting to a short UUID.
+ pub fn from_uuid(uuid: &uuid::Uuid) -> Self {
+ let converter = macro_uuid::ShortUuidConverter::default();
+ Self {
+ short_uuid: converter.from_uuid(uuid),
+ }
+ }
+
+ /// Convert back to a full UUID.
+ pub fn to_uuid(&self) -> anyhow::Result<uuid::Uuid> {
+ let converter = macro_uuid::ShortUuidConverter::default();
+ converter.to_uuid(&self.short_uuid)
+ }
+
+ /// Returns the canonical `MACRO-{short_uuid}` string.
+ pub fn to_task_id_string(&self) -> String {
+ format!("MACRO-{}", self.short_uuid)
+ }
+
+ /// Extract all unique `MACRO-{short_uuid}` references from text.
+ /// Matching is case-insensitive on the `MACRO-` prefix; the short UUID
+ /// portion is preserved as captured.
+ pub fn extract_from_text(text: &str) -> Vec<MacroTaskId> {
+ let mut seen = HashSet::new();
+ let mut results = Vec::new();
+
+ for caps in MACRO_TASK_ID_RE.captures_iter(text) {
+ let short = &caps[1];
+ if seen.insert(short.to_string())
+ && let Some(task_id) = Self::from_short_uuid(short)
+ {
+ results.push(task_id);
+ }
+ }
+
+ results
+ }
+}
+
+impl fmt::Display for MacroTaskId {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ write!(f, "MACRO-{}", self.short_uuid)
+ }
+}
diff --git a/rust/cloud-storage/github/src/domain/ports.rs b/rust/cloud-storage/github/src/domain/ports/link.rs
similarity index 76%
rename from rust/cloud-storage/github/src/domain/ports.rs
rename to rust/cloud-storage/github/src/domain/ports/link.rs
index 5ddc3457a3..ed7a0c419b 100644
--- a/rust/cloud-storage/github/src/domain/ports.rs
+++ b/rust/cloud-storage/github/src/domain/ports/link.rs
@@ -1,15 +1,10 @@
-//! Port definitions for the github domain.
-//!
-//! These traits define the contracts that adapters must implement.
+//! Port definitions for github link operations (OAuth and account linking).
use std::future::Future;
use crate::domain::models::{
- GithubAccessToken, GithubError, GithubExchangeTokenResponse, GithubInstallationAccessToken,
- GithubUserInfo, ValidatedGithubWebhookEvent,
+ GithubAccessToken, GithubError, GithubExchangeTokenResponse, GithubLink, GithubUserInfo,
};
-
-use super::models::GithubLink;
use macro_user_id::{lowercased::Lowercase, user_id::MacroUserId};
/// Repository for accessing github link data from the database.
@@ -106,34 +101,6 @@ pub trait Auth: Send + Sync + 'static {
) -> impl Future<Output = Result<GithubAccessToken, Self::Err>>;
}
-/// Service interface for github sync operations (webhooks and sync app).
-///
-/// Handles webhook validation/processing and sync app installation token generation.
-pub trait GithubSyncService: Send + Sync + 'static {
- /// Validates the incoming webhook event and returns back the `ValidatedGithubWebhookEvent`
- fn validate_webhook_event(
- &self,
- event_type: &str,
- signature: &str,
- body: &[u8],
- ) -> impl Future<Output = Result<ValidatedGithubWebhookEvent, GithubError>> + Send;
-
- /// Processes and incoming github webhook event
- fn process_webhook_event(
- &self,
- webhook_event: &ValidatedGithubWebhookEvent,
- ) -> impl Future<Output = Result<(), GithubError>> + Send;
-
- /// Returns the github sync app installation url
- fn get_github_sync_app_url(&self) -> &str;
-
- /// Generates an installation access token for the github sync app
- fn generate_installation_access_token(
- &self,
- installation_id: u64,
- ) -> impl Future<Output = Result<GithubInstallationAccessToken, GithubError>> + Send;
-}
-
/// Service interface for github link operations (OAuth and account linking).
///
/// Handles OAuth URL construction and user account linking.
diff --git a/rust/cloud-storage/github/src/domain/ports/mod.rs b/rust/cloud-storage/github/src/domain/ports/mod.rs
new file mode 100644
index 0000000000..bf902b40d1
--- /dev/null
+++ b/rust/cloud-storage/github/src/domain/ports/mod.rs
@@ -0,0 +1,13 @@
+//! Port definitions for the github domain.
+//!
+//! These traits define the contracts that adapters must implement.
+
+#[cfg(feature = "link")]
+mod link;
+#[cfg(feature = "sync")]
+mod sync;
+
+#[cfg(feature = "link")]
+pub use link::*;
+#[cfg(feature = "sync")]
+pub use sync::*;
diff --git a/rust/cloud-storage/github/src/domain/ports/sync.rs b/rust/cloud-storage/github/src/domain/ports/sync.rs
new file mode 100644
index 0000000000..06fbb87014
--- /dev/null
+++ b/rust/cloud-storage/github/src/domain/ports/sync.rs
@@ -0,0 +1,35 @@
+//! Port definitions for github sync operations (webhooks and sync app).
+
+use std::future::Future;
+
+use crate::domain::models::{
+ GithubError, GithubInstallationAccessToken, ValidatedGithubWebhookEvent,
+};
+
+/// Service interface for github sync operations (webhooks and sync app).
+///
+/// Handles webhook validation/processing and sync app installation token generation.
+pub trait GithubSyncService: Send + Sync + 'static {
+ /// Validates the incoming webhook event and returns back the `ValidatedGithubWebhookEvent`
+ fn validate_webhook_event(
+ &self,
+ event_type: &str,
+ signature: &str,
+ body: &[u8],
+ ) -> impl Future<Output = Result<ValidatedGithubWebhookEvent, GithubError>> + Send;
+
+ /// Processes and incoming github webhook event
+ fn process_webhook_event(
+ &self,
+ webhook_event: &ValidatedGithubWebhookEvent,
+ ) -> impl Future<Output = Result<(), GithubError>> + Send;
+
+ /// Returns the github sync app installation url
+ fn get_github_sync_app_url(&self) -> &str;
+
+ /// Generates an installation access token for the github sync app
+ fn generate_installation_access_token(
+ &self,
+ installation_id: u64,
+ ) -> impl Future<Output = Result<GithubInstallationAccessToken, GithubError>> + Send;
+}
diff --git a/rust/cloud-storage/github/src/inbound.rs b/rust/cloud-storage/github/src/inbound.rs
index df5f284e2e..a5c7d4020a 100644
--- a/rust/cloud-storage/github/src/inbound.rs
+++ b/rust/cloud-storage/github/src/inbound.rs
@@ -1,6 +1,6 @@
//! Inbound adapters for the github domain.
-#[cfg(feature = "axum")]
+#[cfg(all(feature = "axum", feature = "sync"))]
pub mod github_sync_router;
#[cfg(feature = "axum")]
diff --git a/rust/cloud-storage/github/src/outbound.rs b/rust/cloud-storage/github/src/outbound.rs
index f621e1c8bb..49501fa367 100644
--- a/rust/cloud-storage/github/src/outbound.rs
+++ b/rust/cloud-storage/github/src/outbound.rs
@@ -1,5 +1,8 @@
//! Outbound adapters for the github domain.
+#[cfg(feature = "link")]
pub mod github_auth_client;
+#[cfg(feature = "link")]
pub mod github_oauth_client;
+#[cfg(feature = "link")]
pub mod pg_github_repo;