Crate github_flows

source ·
Expand description

GitHub integration for Flows.network

Quick Start

use github_flows::{
    get_octo, listen_to_event,
    octocrab::models::{events::payload::EventPayload, reactions::ReactionContent},
};

#[no_mangle]
#[tokio::main(flavor = "current_thread")]
pub async fn run() {
    listen_to_event("some_owner", "some_repo", vec!["issue_comment"], handler).await;
}

async fn handler(payload: EventPayload) {
    if let EventPayload::IssueCommentEvent(e) = payload {
        let issue_number = e.comment.id.0;

        let octo = get_octo();

        let _reaction = octo
            .issues("jetjinser", "github-flows")
            .create_reaction(issue_number, ReactionContent::Rocket)
            .await
            .unwrap();
    };
}

Note that the tokio used here is tokio_wasi with full features

...
[dependencies]
github-flows = "0.1.0"
tokio_wasi = { version = "1.25.1", features = ["full"] }
...

listen_to_event() is responsible for registering a listener for channel some_owner of workspace some_repo. When a new issue_number Event coming, the callback handler is called with received EventPayload then get_octo() is used to get a Octocrab Instance to call GitHub api

Re-exports

pub use octocrab;

Enums

The payload in an event type.

Functions

Get a Octocrab Instance with GitHub Extension base_url
Create a listener for https://github.com/owner/repo.
Revoke previous registered listener of current flow.