Skip to content

Commit

Permalink
examples: Add an example showing gist creation (#329)
Browse files Browse the repository at this point in the history
  • Loading branch information
envp authored Apr 29, 2023
1 parent 153f9f8 commit 313dc9c
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions examples/create_a_gist.rs
Original file line number Diff line number Diff line change
@@ -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(())
}

0 comments on commit 313dc9c

Please sign in to comment.