Skip to content

Commit

Permalink
0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
aisrael committed Jun 13, 2023
1 parent 5b18330 commit 4d4d983
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ghctl"
version = "0.2"
version = "0.2.0"
edition = "2021"
description = "A GitHub command line utility"
documentation = "https://docs.rs/ghctl"
Expand Down
18 changes: 12 additions & 6 deletions src/ghctl/repo/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ async fn apply_branch_protection_rules(
branch_protection_rules: &HashMap<String, BranchProtectionRule>,
) -> Result<()> {
for (branch, branch_protection_rule) in branch_protection_rules {
apply_branch_protection_rule(octocrab, owner, repo, &branch, branch_protection_rule).await?
apply_branch_protection_rule(octocrab, owner, repo, branch, branch_protection_rule).await?
}

Ok(())
Expand All @@ -577,7 +577,6 @@ async fn apply_branch_protection_rule(
branch: &str,
branch_protection_rule: &BranchProtectionRule,
) -> Result<()> {

let mut repository_branch_protection = github::RepositoryBranchProtection::new();

if let Some(require_pull_request) = &branch_protection_rule.require_pull_request {
Expand All @@ -592,26 +591,33 @@ async fn apply_branch_protection_rule(
} else {
None
}
},
}
RequirePullRequest::EnabledWithSettings(settings) => {
Some(github::RequiredPullRequestReviews {
dismiss_stale_reviews: false,
require_code_owner_reviews: false,
required_approving_review_count: settings.required_approving_review_count,
})
},
}
};
}

if let Some(required_status_checks) = &branch_protection_rule.required_status_checks {
repository_branch_protection.required_status_checks = Some(github::RequiredStatusChecks {
strict: false,
contexts: required_status_checks.clone(),
enforcement_level: None
enforcement_level: None,
});
}

let result = github::update_branch_protection(octocrab, owner, repo, branch, &repository_branch_protection).await?;
let result = github::update_branch_protection(
octocrab,
owner,
repo,
branch,
&repository_branch_protection,
)
.await?;
println!("{:?}", result);

Ok(())
Expand Down
9 changes: 6 additions & 3 deletions src/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ pub struct RequiredSignatures {
/// Get branch protection
///
/// See: https://docs.github.com/en/rest/branches/branch-protection?apiVersion=2022-11-28#get-branch-protection
#[allow(dead_code)]
pub async fn get_branch_protection(
octocrab: &Octocrab,
owner: &str,
Expand Down Expand Up @@ -326,9 +327,11 @@ mod tests {
let branch = "main";

let before = get_branch_protection(&octocrab, owner, repo, branch).await;
assert!(before.is_err());
let e = before.unwrap_err();
assert!(e.to_string().starts_with("GitHub: Branch not protected\n"));

if before.is_err() {
let e = before.unwrap_err();
assert!(e.to_string().starts_with("GitHub: Branch not protected\n"));
}

let required_status_checks = RequiredStatusChecks {
strict: true,
Expand Down

0 comments on commit 4d4d983

Please sign in to comment.