Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions crates/crates_io_github/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@ reqwest = { version = "=0.13.3", features = ["json"] }
serde = { version = "=1.0.228", features = ["derive"] }
thiserror = "=2.0.18"
tracing = "=0.1.44"
url = "=2.5.8"

[dev-dependencies]
clap = { version = "=4.6.1", features = ["derive", "env", "unicode", "wrap_help"] }
mockito = "=1.7.2"
secrecy = "=0.10.3"
serde_json = "=1.0.149"
tokio = { version = "=1.52.1", features = ["macros", "rt-multi-thread"] }
tracing-subscriber = { version = "=0.3.23", features = ["env-filter"] }
51 changes: 51 additions & 0 deletions crates/crates_io_github/examples/fetch_ref.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
use anyhow::Result;
use clap::Parser;
use crates_io_github::{GitHubClient, RealGitHubClient, parse_github_slug};
use reqwest::Client;
use tracing::level_filters::LevelFilter;
use tracing_subscriber::EnvFilter;
use url::Url;

#[derive(Debug, Parser)]
#[command(about = "Prints the head commit and tree SHAs for a branch of a GitHub repo.")]
struct Opts {
/// GitHub repository URL, e.g. `https://github.com/rust-lang/crates.io-index`.
repo: Url,

/// Branch to resolve. Defaults to `master` because that is what the
/// crates.io index uses; pass `--branch main` (or similar) for other
/// repositories.
#[arg(long, default_value = "master")]
branch: String,
}

#[tokio::main]
async fn main() -> Result<()> {
init_tracing();

let opts = Opts::parse();
let (owner, repo) = parse_github_slug(&opts.repo)?;
let ref_name = format!("refs/heads/{}", opts.branch);

let client = RealGitHubClient::new(Client::new());
let git_ref = client.get_ref(&owner, &repo, &ref_name).await?;
let commit = client
.get_commit(&owner, &repo, &git_ref.object.sha)
.await?;

println!("ref: {}", git_ref.ref_name);
println!("commit: {}", commit.sha);
println!("tree: {}", commit.tree.sha);
Ok(())
}

fn init_tracing() {
let env_filter = EnvFilter::builder()
.with_default_directive(LevelFilter::DEBUG.into())
.from_env_lossy();

tracing_subscriber::fmt()
.compact()
.with_env_filter(env_filter)
.init();
}
Loading