GitHub
To automate your workflows, you need to sign an account first. It’s free.
Doc
GitHub Integration for Flows.network
Quick Start
use github_flows::{
event_handler, get_octo, listen_to_event,
octocrab::models::{
reactions::ReactionContent,
webhook_events::{WebhookEvent, WebhookEventPayload},
}
GithubLogin,
};
#[no_mangle]
#[tokio::main(flavor = "current_thread")]
pub async fn on_deploy() {
// `some_login` must be authed in flows.network
listen_to_event(&GithubLogin::Provided(String::from("some_login")), "some_owner", "some_repo", vec!["issue_comment"]).await;
}
#[event_handler]
async fn handler(event: Result<WebhookEvent, serde_json::Error>) {
let payload = event.unwrap();
if let WebhookEventPayload::IssueComment(e) = payload.specific {
let comment_id = e.comment.id.0;
// installed app login
let octo = get_octo(&GithubLogin::Provided(String::from("some_login")));
let _reaction = octo
.issues("some_owner", "some_repo")
.create_comment_reaction(comment_id, ReactionContent::Rocket)
.await
.unwrap();
};
}
example Cargo.toml
[package] name = "demo" version = "0.1.0" edition = "2021" [lib] path = "src/demo.rs" crate-type = ["cdylib"] [dependencies] github-flows = "0.8" tokio = { version = "1", features = ["macros", "rt"] } serde_json = "1" ...
listen_to_event is responsible for registering a listener for
some_owner/some_repo
. When a new issue_number
Event
coming, the fn handler
decorated by event_handler macro is called with received
WebhookEvent
then get_octo is used to get a
Octocrab
Instance to call GitHub api