@@ -676,25 +676,33 @@ impl CreateRepoDiff {
676
676
677
677
impl std:: fmt:: Display for CreateRepoDiff {
678
678
fn fmt ( & self , mut f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
679
+ let CreateRepoDiff {
680
+ org,
681
+ name,
682
+ settings,
683
+ permissions,
684
+ branch_protections,
685
+ } = self ;
686
+
679
687
let RepoSettings {
680
688
description,
681
689
homepage,
682
690
archived : _,
683
691
auto_merge_enabled,
684
- } = & self . settings ;
692
+ } = & settings;
685
693
686
694
writeln ! ( f, "➕ Creating repo:" ) ?;
687
- writeln ! ( f, " Org: {}" , self . org ) ?;
688
- writeln ! ( f, " Name: {}" , self . name ) ?;
689
- writeln ! ( f, " Description: {:?}" , description ) ?;
690
- writeln ! ( f, " Homepage: {:?}" , homepage ) ?;
691
- writeln ! ( f, " Auto-merge: {}" , auto_merge_enabled ) ?;
695
+ writeln ! ( f, " Org: {org}" ) ?;
696
+ writeln ! ( f, " Name: {name}" ) ?;
697
+ writeln ! ( f, " Description: {description}" ) ?;
698
+ writeln ! ( f, " Homepage: {homepage :?}" ) ?;
699
+ writeln ! ( f, " Auto-merge: {auto_merge_enabled}" ) ?;
692
700
writeln ! ( f, " Permissions:" ) ?;
693
- for diff in & self . permissions {
701
+ for diff in permissions {
694
702
write ! ( f, "{diff}" ) ?;
695
703
}
696
704
writeln ! ( f, " Branch Protections:" ) ?;
697
- for ( branch_name, branch_protection) in & self . branch_protections {
705
+ for ( branch_name, branch_protection) in branch_protections {
698
706
writeln ! ( & mut f, " {branch_name}" ) ?;
699
707
log_branch_protection ( branch_protection, None , & mut f) ?;
700
708
}
@@ -719,9 +727,18 @@ impl UpdateRepoDiff {
719
727
return true ;
720
728
}
721
729
722
- self . settings_diff . 0 == self . settings_diff . 1
723
- && self . permission_diffs . is_empty ( )
724
- && self . branch_protection_diffs . is_empty ( )
730
+ let UpdateRepoDiff {
731
+ org : _,
732
+ name : _,
733
+ repo_node_id : _,
734
+ settings_diff,
735
+ permission_diffs,
736
+ branch_protection_diffs,
737
+ } = self ;
738
+
739
+ settings_diff. 0 == settings_diff. 1
740
+ && permission_diffs. is_empty ( )
741
+ && branch_protection_diffs. is_empty ( )
725
742
}
726
743
727
744
fn can_be_modified ( & self ) -> bool {
@@ -770,8 +787,18 @@ impl std::fmt::Display for UpdateRepoDiff {
770
787
if self . noop ( ) {
771
788
return Ok ( ( ) ) ;
772
789
}
773
- writeln ! ( f, "📝 Editing repo '{}/{}':" , self . org, self . name) ?;
774
- let ( settings_old, settings_new) = & self . settings_diff ;
790
+
791
+ let UpdateRepoDiff {
792
+ org,
793
+ name,
794
+ repo_node_id : _,
795
+ settings_diff,
796
+ permission_diffs,
797
+ branch_protection_diffs,
798
+ } = self ;
799
+
800
+ writeln ! ( f, "📝 Editing repo '{org}/{name}':" ) ?;
801
+ let ( settings_old, settings_new) = & settings_diff;
775
802
let RepoSettings {
776
803
description,
777
804
homepage,
@@ -803,17 +830,17 @@ impl std::fmt::Display for UpdateRepoDiff {
803
830
( true , false ) => writeln ! ( f, " Disable auto-merge" ) ?,
804
831
_ => { }
805
832
}
806
- if !self . permission_diffs . is_empty ( ) {
833
+ if !permission_diffs. is_empty ( ) {
807
834
writeln ! ( f, " Permission Changes:" ) ?;
835
+ for permission_diff in permission_diffs {
836
+ write ! ( f, "{permission_diff}" ) ?;
837
+ }
808
838
}
809
- for permission_diff in & self . permission_diffs {
810
- write ! ( f, "{permission_diff}" ) ?;
811
- }
812
- if !self . branch_protection_diffs . is_empty ( ) {
839
+ if !branch_protection_diffs. is_empty ( ) {
813
840
writeln ! ( f, " Branch Protections:" ) ?;
814
- }
815
- for branch_protection_diff in & self . branch_protection_diffs {
816
- write ! ( f , "{branch_protection_diff}" ) ? ;
841
+ for branch_protection_diff in branch_protection_diffs {
842
+ write ! ( f , "{branch_protection_diff}" ) ? ;
843
+ }
817
844
}
818
845
819
846
Ok ( ( ) )
@@ -854,11 +881,13 @@ impl RepoPermissionAssignmentDiff {
854
881
855
882
impl std:: fmt:: Display for RepoPermissionAssignmentDiff {
856
883
fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
857
- let name = match & self . collaborator {
884
+ let RepoPermissionAssignmentDiff { collaborator, diff } = self ;
885
+
886
+ let name = match & collaborator {
858
887
RepoCollaborator :: Team ( name) => format ! ( "team '{name}'" ) ,
859
888
RepoCollaborator :: User ( name) => format ! ( "user '{name}'" ) ,
860
889
} ;
861
- match & self . diff {
890
+ match & diff {
862
891
RepoPermissionDiff :: Create ( p) => {
863
892
writeln ! ( f, " Giving {name} {p} permission" )
864
893
}
@@ -950,9 +979,21 @@ fn log_branch_protection(
950
979
new : Option < & api:: BranchProtection > ,
951
980
mut result : impl Write ,
952
981
) -> std:: fmt:: Result {
982
+ let api:: BranchProtection {
983
+ // Pattern identifies the branch protection, so it has to be same between `current`
984
+ // and `new`.
985
+ pattern : _,
986
+ is_admin_enforced,
987
+ dismisses_stale_reviews,
988
+ required_approving_review_count,
989
+ required_status_check_contexts,
990
+ push_allowances,
991
+ requires_approving_reviews,
992
+ } = current;
993
+
953
994
macro_rules! log {
954
995
( $str: literal, $field1: ident) => {
955
- let old = & current . $field1;
996
+ let old = $field1;
956
997
let new = new. map( |n| & n. $field1) ;
957
998
log!( $str, old, new) ;
958
999
} ;
@@ -968,10 +1009,12 @@ fn log_branch_protection(
968
1009
}
969
1010
970
1011
log ! ( "Dismiss Stale Reviews" , dismisses_stale_reviews) ;
1012
+ log ! ( "Is admin enforced" , is_admin_enforced) ;
971
1013
log ! (
972
1014
"Required Approving Review Count" ,
973
1015
required_approving_review_count
974
1016
) ;
1017
+ log ! ( "Requires PR" , requires_approving_reviews) ;
975
1018
log ! ( "Required Checks" , required_status_check_contexts) ;
976
1019
log ! ( "Allowances" , push_allowances) ;
977
1020
Ok ( ( ) )
@@ -1042,20 +1085,28 @@ impl CreateTeamDiff {
1042
1085
1043
1086
impl std:: fmt:: Display for CreateTeamDiff {
1044
1087
fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
1088
+ let CreateTeamDiff {
1089
+ org,
1090
+ name,
1091
+ description,
1092
+ privacy,
1093
+ members,
1094
+ } = self ;
1095
+
1045
1096
writeln ! ( f, "➕ Creating team:" ) ?;
1046
- writeln ! ( f, " Org: {}" , self . org ) ?;
1047
- writeln ! ( f, " Name: {}" , self . name ) ?;
1048
- writeln ! ( f, " Description: {}" , self . description ) ?;
1097
+ writeln ! ( f, " Org: {org}" ) ?;
1098
+ writeln ! ( f, " Name: {name}" ) ?;
1099
+ writeln ! ( f, " Description: {description}" ) ?;
1049
1100
writeln ! (
1050
1101
f,
1051
1102
" Privacy: {}" ,
1052
- match self . privacy {
1103
+ match privacy {
1053
1104
TeamPrivacy :: Secret => "secret" ,
1054
1105
TeamPrivacy :: Closed => "closed" ,
1055
1106
}
1056
1107
) ?;
1057
1108
writeln ! ( f, " Members:" ) ?;
1058
- for ( name, role) in & self . members {
1109
+ for ( name, role) in members {
1059
1110
writeln ! ( f, " {name}: {role}" ) ?;
1060
1111
}
1061
1112
Ok ( ( ) )
@@ -1095,10 +1146,19 @@ impl EditTeamDiff {
1095
1146
}
1096
1147
1097
1148
fn noop ( & self ) -> bool {
1098
- self . name_diff . is_none ( )
1099
- && self . description_diff . is_none ( )
1100
- && self . privacy_diff . is_none ( )
1101
- && self . member_diffs . iter ( ) . all ( |( _, d) | d. is_noop ( ) )
1149
+ let EditTeamDiff {
1150
+ org : _,
1151
+ name : _,
1152
+ name_diff,
1153
+ description_diff,
1154
+ privacy_diff,
1155
+ member_diffs,
1156
+ } = self ;
1157
+
1158
+ name_diff. is_none ( )
1159
+ && description_diff. is_none ( )
1160
+ && privacy_diff. is_none ( )
1161
+ && member_diffs. iter ( ) . all ( |( _, d) | d. is_noop ( ) )
1102
1162
}
1103
1163
}
1104
1164
@@ -1107,21 +1167,31 @@ impl std::fmt::Display for EditTeamDiff {
1107
1167
if self . noop ( ) {
1108
1168
return Ok ( ( ) ) ;
1109
1169
}
1110
- writeln ! ( f, "📝 Editing team '{}/{}':" , self . org, self . name) ?;
1111
- if let Some ( n) = & self . name_diff {
1170
+
1171
+ let EditTeamDiff {
1172
+ org,
1173
+ name,
1174
+ name_diff,
1175
+ description_diff,
1176
+ privacy_diff,
1177
+ member_diffs,
1178
+ } = self ;
1179
+
1180
+ writeln ! ( f, "📝 Editing team '{org}/{name}':" ) ?;
1181
+ if let Some ( n) = name_diff {
1112
1182
writeln ! ( f, " New name: {n}" ) ?;
1113
1183
}
1114
- if let Some ( ( old, new) ) = & self . description_diff {
1184
+ if let Some ( ( old, new) ) = & description_diff {
1115
1185
writeln ! ( f, " New description: '{old}' => '{new}'" ) ?;
1116
1186
}
1117
- if let Some ( ( old, new) ) = & self . privacy_diff {
1187
+ if let Some ( ( old, new) ) = & privacy_diff {
1118
1188
let display = |privacy : & TeamPrivacy | match privacy {
1119
1189
TeamPrivacy :: Secret => "secret" ,
1120
1190
TeamPrivacy :: Closed => "closed" ,
1121
1191
} ;
1122
1192
writeln ! ( f, " New privacy: '{}' => '{}'" , display( old) , display( new) ) ?;
1123
1193
}
1124
- for ( member, diff) in & self . member_diffs {
1194
+ for ( member, diff) in member_diffs {
1125
1195
match diff {
1126
1196
MemberDiff :: Create ( r) => {
1127
1197
writeln ! ( f, " Adding member '{member}' with {r} role" ) ?;
0 commit comments