{"id":15048427,"url":"https://github.com/panghu-huang/octocrate","last_synced_at":"2025-04-10T01:22:11.418Z","repository":{"id":102684454,"uuid":"583793505","full_name":"panghu-huang/octocrate","owner":"panghu-huang","description":"A comprehensive GitHub REST API library based on Rust.","archived":false,"fork":false,"pushed_at":"2024-04-29T11:22:58.000Z","size":4219,"stargazers_count":3,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-05-02T06:16:55.794Z","etag":null,"topics":["github","github-api","github-app","octocat","octocrate","rest-api"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/panghu-huang.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-12-30T23:59:05.000Z","updated_at":"2024-05-06T00:31:41.051Z","dependencies_parsed_at":"2024-02-10T11:20:40.557Z","dependency_job_id":"97c272bf-45f6-490b-bcbb-6b1e41da9b13","html_url":"https://github.com/panghu-huang/octocrate","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/panghu-huang%2Foctocrate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/panghu-huang%2Foctocrate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/panghu-huang%2Foctocrate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/panghu-huang%2Foctocrate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/panghu-huang","download_url":"https://codeload.github.com/panghu-huang/octocrate/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248138290,"owners_count":21053845,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["github","github-api","github-app","octocat","octocrate","rest-api"],"created_at":"2024-09-24T21:11:41.748Z","updated_at":"2025-04-10T01:22:11.380Z","avatar_url":"https://github.com/panghu-huang.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Octocrate\n\noctocrate is a comprehensive GitHub REST API library based on Rust.\n\n![octocrate](https://img.shields.io/crates/v/octocrate.svg)\n![MIT](https://img.shields.io/badge/license-MIT-blue.svg)\n\n[English](./README.md) | [简体中文](./README_zh-CN.md)\n\n## Features\n\n- Fully compliant with the official documentation at [GitHub REST API Documentation](https://docs.github.com/en/rest?apiVersion=2022-11-28)\n- Complete type restrictions for Body / Query parameters\n- Utilizes feature flags for individual API dependencies\n- Supports GitHub app requests for installation API\n- Supports installation access tokens and personal access tokens\n- Defines all Webhooks event types\n\n## Dependencies\n\n```toml\n[dependencies]\noctocrate = \"*\"\n```\n\nUse features to selectively import the required APIs:\n\n```toml\noctocrate = { version = \"*\", features = [\"repos\", \"git\", \"pulls\", \"issues\", \"users\", \"search\"] }\n```\n\nOr use the `full` feature to import all APIs and Webhooks (note: this will increase compilation time):\n\n```toml\noctocrate = { version = \"*\", features = [\"full\"] }\n```\n\n### Type Dependencies\n\nYou can also import only types without using the corresponding APIs:\n\n```toml\noctocrate-types = \"*\"\n```\n\nUse features to selectively import the required types:\n\n```toml\noctocrate-types = { version = \"*\", features = [\"repos\", \"git\", \"pulls\", \"issues\", \"users\", \"search\"] }\n```\n\nImport Webhooks types:\n\n```toml\noctocrate-webhooks = { version = \"*\", features = [\"pull_request\", \"push\"] }\n```\n\nYou can check [octocrate-types documentation](https://docs.rs/crate/octocrate-types/latest/features) and [octocrate-webhooks documentation](https://docs.rs/crate/octocrate-webhooks/latest/features) for all supported features and types.\n\n## Example\n\nCreate a default GitHub API configuration and use it to get a repository's Pull Request:\n\n```rust\nuse octocrate::{APIConfig, Error, GitHubAPI};\n\n#[tokio::main]\nasync fn main() {\n  // Create a default GitHub API configuration\n  let config = APIConfig::default().shared();\n\n  let api = GitHubAPI::new(\u0026config);\n\n  let pull_request = api\n    .pulls\n    .get(\"panghu-huang\", \"octocrate\", 1)\n    .send()\n    .await\n    .unwrap();\n\n  // ..\n}\n```\n\n#### Directly import the corresponding API\n\n```rust\n// Import the repos API instead of GitHubAPI\nuse octocrate::{repos::GitHubReposAPI, APIConfig, GitHubAPI, PersonalAccessToken};\n\n#[tokio::main]\nasync fn main() {\n  // Create a personal access token\n  let personal_access_token = PersonalAccessToken::new(\"YOUR_PERSONAL_ACCESS_TOKEN\");\n\n  // Use the personal access token to create a API configuration\n  let config = APIConfig::with_token(personal_access_token).shared();\n\n  let repos_api = GitHubReposAPI::new(\u0026config);\n\n  let commit = repos_api\n    .get_commit(\n      \"panghu-huang\",\n      \"octocrate\",\n      \"18ff8ed1a3437649e7d87bec9a7d4fe5562f6ad3\",\n    )\n    .send()\n    .await\n    .unwrap();\n}\n```\n\n#### Using GitHub App\n\n```rust\nuse octocrate::{APIConfig, AppAuthorization, GitHubAPI};\n\n#[tokio::main]\nasync fn main() {\n  let app_id = \"YOUR_APP_ID\";\n  let private_key = \"YOUR_PRIVATE_KEY\";\n\n  // Create a GitHub App authorization\n  let app_authorization = AppAuthorization::new(app_id, private_key);\n\n  // Use the GitHub App authorization to create an API configuration\n  let config = APIConfig::with_token(app_authorization).shared();\n\n  let api = GitHubAPI::new(\u0026config);\n\n  // Get the Installation for a repository\n  let installation = api\n    .apps\n    .get_repo_installation(\"panghu-huang\", \"octocrate\")\n    .send()\n    .await\n    .unwrap();\n\n  // Get the Installation Access Token for this Installation\n  let installation_token = api\n    .apps\n    .create_installation_access_token(installation.id)\n    .send()\n    .await\n    .unwrap();\n\n  // Use the Installation Access Token to create a new API configuration\n  let config = APIConfig::with_token(installation_token).shared();\n\n  let api = GitHubAPI::new(\u0026config);\n\n  let repository = api\n    .repos\n    .get(\"panghu-huang\", \"octocrate\")\n    .send()\n    .await\n    .unwrap();\n\n  // ..\n}\n```\n\n#### Request Body Parameters\n\n```rust\nuse octocrate::{\n  issues, APIConfig, AuthorAssociation, GitHubAPI, PersonalAccessToken,\n};\n\n#[tokio::main]\nasync fn main() {\n  let personal_access_token = PersonalAccessToken::new(\"YOUR_PERSONAL_ACCESS_TOKEN\");\n\n  let config = APIConfig::with_token(personal_access_token).shared();\n\n  let api = GitHubAPI::new(\u0026config);\n\n  // Create a comment request\n  // https://github.com/panghu-huang/octocrate/pull/1#issuecomment-2041280635\n  let comment = issues::create_comment::Request {\n    body: \"Hello, world! (Created by octocrate)\".to_string(),\n  };\n\n  // Create a comment on the issue\n  let issue_comment = api\n    .issues\n    .create_comment(\"panghu-huang\", \"octocrate\", 1)\n    .body(\u0026comment)\n    .send()\n    .await\n    .unwrap();\n}\n```\n\n#### Request Query Parameters\n\n```rust\nuse octocrate::{\n  pulls, APIConfig, Error, GitHubAPI, PersonalAccessToken,\n};\n\n#[tokio::main]\nasync fn main() {\n  let personal_access_token = PersonalAccessToken::new(\"YOUR_PERSONAL_ACCESS_TOKEN\");\n\n  let config = APIConfig::with_token(personal_access_token).shared();\n\n  let api = GitHubAPI::new(\u0026config);\n\n  // Use builder pattern to construct query parameters\n  let query = pulls::list::Query::builder()\n    .state(pulls::list::QueryState::Open)\n    .per_page(10)\n    .build()\n\n  let pull_requests = api\n    .pulls\n    .list(\"facebook\", \"react\")\n    .query(\u0026query)\n    .send()\n    .await\n    .unwrap();\n\n  // ..\n}\n```\n\n#### Upload File\n\n```rust\nuse octocrate::{repos, APIConfig, GitHubAPI, PersonalAccessToken};\nuse tokio::fs::File;\n\n#[tokio::main]\nasync fn main() {\n  let file_path = std::path::Path::new(\"test.txt\");\n\n  // File is from tokio::fs module\n  let file = File::open(file_path).await.unwrap();\n  // Get the file's length\n  let content_length = file.metadata().await.unwrap().len();\n\n  let query = repos::upload_release_asset::Query::builder()\n    .name(\"test.txt\")\n    .build();\n\n  let release_asset = github_api\n    .repos\n    .upload_release_asset(\"panghu-huang\", \"octocrate\", release.id)\n    .query(\u0026query)\n    // Set the content type of the file\n    .header(\"Content-Type\", \"text/plain\")\n    // Set the content length of the file\n    .header(\"Content-Length\", content_length.to_string())\n    // Set the file content\n    .file(file)\n    .send()\n    .await\n    .unwrap();\n\n  // ..\n}\n```\n\nYou can find more example code in the [octocrate/tests](https://github.com/panghu-huang/octocrate/tree/main/octocrate/tests) directory.\n\n## Contributing\n\nContributions are welcome! Feel free to open issues or submit pull requests to improve the project.\n\n## License\n\nThis project is licensed under the MIT License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpanghu-huang%2Foctocrate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpanghu-huang%2Foctocrate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpanghu-huang%2Foctocrate/lists"}