Skip to content
Open
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
47 changes: 36 additions & 11 deletions sync-team/src/github/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ pub(crate) use self::api::{GitHubApiRead, GitHubWrite, HttpClient};
static DEFAULT_DESCRIPTION: &str = "Managed by the rust-lang/team repository.";
static DEFAULT_PRIVACY: TeamPrivacy = TeamPrivacy::Closed;

/// GitHub Actions integration ID
/// Verified via: https://api.github.com/repos/rust-lang/rust/commits/HEAD/check-runs
const GITHUB_ACTIONS_INTEGRATION_ID: i64 = 15368;

pub(crate) fn create_diff(
github: Box<dyn GithubRead>,
teams: Vec<rust_team_data::v1::Team>,
Expand Down Expand Up @@ -940,7 +944,7 @@ pub fn construct_ruleset(
.iter()
.map(|context| RequiredStatusCheck {
context: context.clone(),
integration_id: None,
integration_id: Some(GITHUB_ACTIONS_INTEGRATION_ID),
})
.collect(),
strict_required_status_checks_policy: false,
Expand All @@ -966,7 +970,7 @@ pub fn construct_ruleset(

api::Ruleset {
id: None,
name: format!("Branch protection for {}", branch_protection.pattern),
name: format!("Ruleset for {}", branch_protection.pattern),
target: RulesetTarget::Branch,
source_type: RulesetSourceType::Repository,
enforcement: RulesetEnforcement::Active,
Expand Down Expand Up @@ -1639,15 +1643,20 @@ fn log_ruleset(
new: Option<&api::Ruleset>,
mut result: impl Write,
) -> std::fmt::Result {
let is_create = new.is_none();
let mut logged = false;

macro_rules! log {
($str:literal, $field:expr, $new_field:expr) => {
let old = $field;
let new_val = $new_field;
if Some(old) != new_val {
if is_create {
writeln!(result, " {}: {:?}", $str, old)?;
logged = true;
} else if Some(old) != new_val {
if let Some(n) = new_val {
writeln!(result, " {}: {:?} => {:?}", $str, old, n)?;
} else {
writeln!(result, " {}: {:?}", $str, old)?;
logged = true;
}
}
};
Expand Down Expand Up @@ -1790,12 +1799,23 @@ fn log_ruleset(
parameters.strict_required_status_checks_policy
)?;
if !parameters.required_status_checks.is_empty() {
let checks: Vec<_> = parameters
.required_status_checks
.iter()
.map(|c| &c.context)
.collect();
writeln!(result, " Checks: {:?}", checks)?;
writeln!(result, " Checks:")?;
for check in &parameters.required_status_checks {
if let Some(integration_id) = check.integration_id {
let app_name = if integration_id == GITHUB_ACTIONS_INTEGRATION_ID {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now it should show something like below

        Rule: Required Status Checks
          Strict Policy: false
          Checks:
            - CI (GitHub Actions, integration_id: 15368)
            - test (GitHub Actions, integration_id: 15368)

"GitHub Actions"
} else {
"unknown app"
};
writeln!(
result,
" - {} ({}, integration_id: {})",
check.context, app_name, integration_id
)?;
} else {
writeln!(result, " - {} (any integration)", check.context)?;
}
}
}
}
api::RulesetRule::RequiredDeployments { parameters } => {
Expand All @@ -1807,6 +1827,11 @@ fn log_ruleset(
)?;
}
}
logged = true;
}

if !is_create && !logged {
writeln!(result, " No changes")?;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made a change here. I do remember I need to convert the macro into a general function. I will take it up in a separate PR. In this PR, I'm adding a check for a clear description. If there are no changes, it must print.

Ruleset for main
        No changes

instead of just printing

Ruleset for main

}

Ok(())
Expand Down