A Github API library based on Rust
Install Octocrate
with cargo
:
bash
cargo install octocrate
Here's a simple example showing how to create a Github App and handle the issue comment event.
```rust use octocrate::{events::GithubWebhookEvent, GithubApp};
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
```rust use octocrate::{GithubPersonalAccessToken, GithubAPI};
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);
} ```
For more examples, please refer to: examples