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.

5.8 KB
Raw Blame
//! Domain models for the github crate.

#[cfg(test)]
mod test;

#[cfg(feature = "sync")]
mod app_jwt;
mod installation_state;
mod link;
mod repository;
mod sync;
mod webhook_delivery;

#[cfg(feature = "sync")]
pub use app_jwt::AppJwt;
#[cfg(feature = "sync")]
pub(crate) use app_jwt::app_jwt;
pub use github_pull_requests::domain::models::{
    EnrichGithubPullRequestsProxyRequest, EnrichGithubPullRequestsResponse,
    EnrichedGithubPullRequest, GITHUB_PULL_REQUEST_FOREIGN_ENTITY_SOURCE, GitRef,
    GithubDraftOutcome, GithubKey, GithubMergeMethod, GithubMergeOutcome, GithubMergeRejection,
    GithubPullRequestCheckRun, GithubPullRequestComment, GithubPullRequestDetails,
    GithubPullRequestLabel, GithubPullRequestMerge, GithubPullRequestMergeability,
    GithubPullRequestMergeabilityEntry, GithubPullRequestMergeabilityRequest,
    GithubPullRequestMergeabilityResponse, GithubPullRequestNumber, GithubPullRequestRef,
    GithubPullRequestReview, GithubPullRequestReviewState, GithubPullRequestState,
    GithubPullRequestStatus, GithubPullRequestUpdateRejection, GithubPullRequestUser,
    GithubRepositoryMergeSettings, GithubStateOutcome, MergeGithubPullRequestRequest,
    MergeGithubPullRequestResponse, SetGithubPullRequestDraftRequest,
    SetGithubPullRequestDraftResponse, SetGithubPullRequestStateRequest,
    SetGithubPullRequestStateResponse, latest_reviews,
};
pub use installation_state::{
    InstallationState, InstallationStateError, sign_installation_state, verify_installation_state,
};
pub use link::{
    GithubAccessToken, GithubExchangeTokenResponse, GithubGrantLinkOutcome, GithubLink,
    GithubLinkStatus, GithubUserInfo,
};
pub use repository::{GithubRepository, PullRequestIndexPage, PullRequestIndexRequest};
pub use sync::{
    GithubAppInstallationSource, GithubAuthenticatedUser, GithubInstallationAccessToken,
    GithubInstallationSetupAction, GithubSetupAccessToken, GithubUserInstallation,
    GithubUserInstallationsPage, GithubWebhookEventType, MacroTaskId, ResolvedTeamTaskReference,
    TeamTaskReference, ValidatedGithubWebhookEvent, extract_github_mentions,
    pull_request_task_reference, strip_markdown_code,
};
use upstream_error::UpstreamError;
pub use webhook_delivery::{
    GithubWebhookReceived, GithubWebhookRepository, GithubWebhookSender, MAX_WEBHOOK_PAYLOAD_BYTES,
};

/// Errors that can occur during github operations.
#[derive(Debug, thiserror::Error)]
pub enum GithubError {
    /// An internal error occurred.
    #[error("{0}")]
    Internal(#[from] anyhow::Error),
    /// No Github link was found
    #[error("no link found")]
    NoLinkFound,
    /// The Github link token has expired and the user must reauthenticate.
    #[error("reauthentication required")]
    ReauthenticationRequired,
    /// Reconnect must use the currently linked GitHub account.
    #[error("disconnect the current GitHub account before linking a different account")]
    AccountMismatch,
    /// No refresh token was provided in the token exchange
    #[error("no refresh token provided in token exchange")]
    NoRefreshTokenProvided,
    /// Invalid github webhook signature
    #[error("invalid github webhook signature")]
    InvalidWebhookSignature,
    /// The authenticated user is not a member of the requested team.
    #[error("user is not permitted to configure GitHub sync for this team")]
    Forbidden,
    /// The installation setup state is malformed, invalid, or expired.
    #[error("invalid installation setup state")]
    InvalidInstallationState,
    /// GitHub reported an unsupported installation setup action.
    #[error("invalid installation setup action")]
    InvalidInstallationSetupAction,
    /// A required installation callback field was absent.
    #[error("missing installation setup callback field: {0}")]
    MissingInstallationSetupField(&'static str),
    /// The installation is not visible to the GitHub user who completed setup.
    #[error("GitHub installation is not owned by the setup user")]
    InstallationNotOwned,
    /// The GitHub account completing setup is not linked to the Macro user the
    /// setup state was minted for.
    #[error("GitHub account is not linked to the Macro user who started setup")]
    SetupUserNotLinked,
    /// Our App has no installation covering the requested repository, or the
    /// installation it has belongs to neither the requesting user nor any team
    /// they are on.
    ///
    /// One variant for both because a caller must not be able to tell them
    /// apart: "installed, but not yours" and "not installed" differ only in
    /// what they report about other people's accounts.
    #[error("no GitHub App installation for this user and repository")]
    RepositoryUnavailable,
    /// GitHub declined to merge the pull request. The message is GitHub's
    /// own and is written for the person who asked, so it is safe to show.
    #[error("GitHub declined to merge the pull request: {message}")]
    PullRequestMergeRejected {
        /// Why GitHub declined.
        rejection: GithubMergeRejection,
        /// GitHub's message for the user.
        message: String,
    },
    /// GitHub declined to change the pull request. The message is GitHub's
    /// own and is written for the person who asked, so it is safe to show.
    #[error("GitHub declined to change the pull request: {message}")]
    PullRequestUpdateRejected {
        /// Why GitHub declined.
        rejection: GithubPullRequestUpdateRejection,
        /// GitHub's message for the user.
        message: String,
    },
    /// The request asked for more pull requests than one call may cover.
    #[error("too many pull requests requested")]
    TooManyPullRequests,
    /// GitHub, or the sign-in service holding the user's GitHub grant, was
    /// down, throttling, or answered with something unusable. Not the
    /// caller's fault and not ours; retrying later can help.
    #[error(transparent)]
    Upstream(#[from] UpstreamError),
}