Skip to content

Commit 3bf05c1

Browse files
authored
Merge pull request #1742 from Kobzol/branch-protections-app
Sync GitHub App branch protection push allowances
2 parents bafb769 + 5f839be commit 3bf05c1

File tree

4 files changed

+36
-4
lines changed

4 files changed

+36
-4
lines changed

sync-team/src/github/api/mod.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,7 @@ where
439439
pub(crate) enum PushAllowanceActor {
440440
User(UserPushAllowanceActor),
441441
Team(TeamPushAllowanceActor),
442+
App(AppPushAllowanceActor),
442443
}
443444

444445
/// User who can be allowed to push to a branch in a repo
@@ -454,6 +455,14 @@ pub(crate) struct TeamPushAllowanceActor {
454455
pub(crate) name: String,
455456
}
456457

458+
/// GitHub app that can be allowed to push to a branch in a repo
459+
#[derive(Clone, Deserialize, Debug, PartialEq, Eq)]
460+
pub(crate) struct AppPushAllowanceActor {
461+
pub(crate) name: String,
462+
/// Node ID, which can be used as a push actor ID
463+
pub(crate) id: String,
464+
}
465+
457466
pub(crate) enum BranchProtectionOp {
458467
CreateForRepo(String),
459468
UpdateBranchProtection(String),

sync-team/src/github/api/read.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,10 @@ impl GithubRead for GitHubApiRead {
361361
},
362362
name
363363
}
364+
... on App {
365+
id,
366+
name
367+
}
364368
}
365369
}
366370
}

sync-team/src/github/api/write.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ use reqwest::Method;
33

44
use crate::github::api::url::GitHubUrl;
55
use crate::github::api::{
6-
BranchProtection, BranchProtectionOp, HttpClient, Login, PushAllowanceActor, Repo,
7-
RepoPermission, RepoSettings, Team, TeamPrivacy, TeamPushAllowanceActor, TeamRole,
8-
UserPushAllowanceActor, allow_not_found,
6+
AppPushAllowanceActor, BranchProtection, BranchProtectionOp, HttpClient, Login,
7+
PushAllowanceActor, Repo, RepoPermission, RepoSettings, Team, TeamPrivacy,
8+
TeamPushAllowanceActor, TeamRole, UserPushAllowanceActor, allow_not_found,
99
};
1010
use crate::utils::ResponseExt;
1111

@@ -427,6 +427,9 @@ impl GitHubWrite {
427427
organization: Login { login: org },
428428
name,
429429
}) => push_actor_ids.push(self.team_id(org, name)?),
430+
PushAllowanceActor::App(AppPushAllowanceActor { id, .. }) => {
431+
push_actor_ids.push(id.clone())
432+
}
430433
}
431434
}
432435

sync-team/src/github/mod.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,8 +321,24 @@ impl SyncGitHub {
321321
.branch_protections(&actual_repo.org, &actual_repo.name)?;
322322
for branch_protection in &expected_repo.branch_protections {
323323
let actual_branch_protection = actual_protections.remove(&branch_protection.pattern);
324-
let expected_branch_protection =
324+
let mut expected_branch_protection =
325325
construct_branch_protection(expected_repo, branch_protection);
326+
327+
// We don't model GitHub App push allowance actors in team.
328+
// However, we don't want to remove existing accesses of GH apps to
329+
// branches.
330+
// So if there is an existing branch protection, we copy its GitHub app
331+
// push allowances into the expected branch protection, to roundtrip the app access.
332+
if let Some((_, actual_branch_protection)) = &actual_branch_protection {
333+
expected_branch_protection.push_allowances.extend(
334+
actual_branch_protection
335+
.push_allowances
336+
.iter()
337+
.filter(|allowance| matches!(allowance, PushAllowanceActor::App(_)))
338+
.cloned(),
339+
);
340+
}
341+
326342
let operation = {
327343
match actual_branch_protection {
328344
Some((database_id, bp)) if bp != expected_branch_protection => {

0 commit comments

Comments
 (0)