From 313dc9c97c39cba35b15c44544268ee7609154dd Mon Sep 17 00:00:00 2001 From: Vaibhav Yenamandra <3663231+envp@users.noreply.github.com> Date: Sat, 29 Apr 2023 08:17:28 -0400 Subject: [PATCH] examples: Add an example showing gist creation (#329) --- examples/create_a_gist.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 examples/create_a_gist.rs diff --git a/examples/create_a_gist.rs b/examples/create_a_gist.rs new file mode 100644 index 00000000..defd6829 --- /dev/null +++ b/examples/create_a_gist.rs @@ -0,0 +1,24 @@ +use octocrab::Octocrab; + +#[tokio::main] +async fn main() -> octocrab::Result<()> { + let token = std::env::var("GITHUB_TOKEN").expect("GITHUB_TOKEN env variable is required"); + + let octocrab = Octocrab::builder().personal_token(token).build()?; + + println!("Creating a gist with hello world in rust on your account"); + let gist = octocrab + .gists() + .create() + .file( + "hello_world.rs", + "fn main() {\n println!(\"Hello World!\");\n}", + ) + // Optional Parameters + .description("Hello World in Rust") + .public(false) + .send() + .await?; + println!("Done, created: {url}", url = gist.html_url.to_string()); + Ok(()) +}