Octocrate (Octocat + Crate)

A Github API library based on Rust

Install

Install Octocrate with cargo:

bash cargo install octocrate

Usage

Github App

Here's a simple example showing how to create a Github App and handle the issue comment event.

```rust use octocrate::{events::GithubWebhookEvent, GithubApp};

[tokio::main]

async fn main() { let mut app = GithubApp::builder() .appid("GITHUBAPPID") .privatekey("GITHUBAPPPRIVATE_KEY") .build() .unwrap();

app.on_webhook_event(|event, api| {
        match event {
            GithubWebhookEvent::IssueComment(evt) => {
                // handle issue comment event
                // ...
            }
            _ => {
                // handle other events
                // ...
            }
        };

        Ok(())
    })
    .serve()
    .await
    .unwrap();

} ```

The github_app.serve() method opens a web server to listen for webhook requests from Github, the default path is /github/webhook

If you want to customize the server, use start() instead of serve(). Example: examples/manual-trigger.rs

Github API

```rust use octocrate::{GithubPersonalAccessToken, GithubAPI};

[tokio::main]

async fn main() { let token = GithubPersonalAccessToken::new("YOURPERSONALACCESS_TOKEN");

let api = GithubAPI::with_token(token);

let repositories = api
    .repositories
    .list_user_repositories("panghu-huang")
    .send()
    .await
    .unwrap();

println!("Repositories: {:#?}", repositories);

} ```

Examples

For more examples, please refer to: examples