Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache repository configuration #47

Merged
merged 1 commit into from
Sep 11, 2024
Merged
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
60 changes: 37 additions & 23 deletions dco2/src/github/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,37 +126,51 @@ impl GHClient for GHClientOctorust {

/// [GHClient::get_config]
async fn get_config(&self, ctx: &Ctx) -> Result<Option<Config>> {
#[cached(
size = 1000,
time = 3600,
sync_writes = true,
result = true,
key = "String",
convert = r#"{ format!("{}-{}", ctx.owner, ctx.repo) }"#
)]
async fn inner(client: &octorust::Client, ctx: &Ctx) -> Result<Option<Config>> {
// Get configuration file content
let resp =
match client.repos().get_content_file(&ctx.owner, &ctx.repo, CONFIG_FILE_PATH, "").await {
Ok(resp) => resp,
Err(octorust::ClientError::HttpError {
status,
headers: _,
error,
}) => {
if status == StatusCode::NOT_FOUND {
return Ok(None);
}
bail!(error);
}
Err(err) => bail!(err),
};

// Decode and parse configuration
let mut b64data = resp.body.content.as_bytes().to_owned();
b64data.retain(|b| !b" \n\t\r\x0b\x0c".contains(b));
let data = String::from_utf8(b64.decode(b64data)?)?;
let config = serde_yaml::from_str(&data)?;

Ok(config)
}

// Setup client for installation provided
let client = self.setup_client(ctx.inst_id)?;

// Get configuration file content
let resp = match client.repos().get_content_file(&ctx.owner, &ctx.repo, CONFIG_FILE_PATH, "").await {
Ok(resp) => resp,
Err(octorust::ClientError::HttpError {
status,
headers: _,
error,
}) => {
if status == StatusCode::NOT_FOUND {
return Ok(None);
}
bail!(error);
}
Err(err) => bail!(err),
};

// Decode and parse configuration
let mut b64data = resp.body.content.as_bytes().to_owned();
b64data.retain(|b| !b" \n\t\r\x0b\x0c".contains(b));
let data = String::from_utf8(b64.decode(b64data)?)?;
let config = serde_yaml::from_str(&data)?;

Ok(config)
inner(&client, ctx).await
}

/// [GHClient::is_organization_member]
async fn is_organization_member(&self, ctx: &Ctx, org: &str, username: &str) -> Result<bool> {
#[cached(
size = 1000,
time = 3600,
sync_writes = true,
result = true,
Expand Down