@@ -21,7 +21,8 @@ class RepositoryConfiguration {
2121 static const String supportNoReviewRevertKey = 'support_no_review_revert' ;
2222 static const String requiredCheckRunsOnRevertKey =
2323 'required_checkruns_on_revert' ;
24- static const String baseCommitAllowedDaysKey = 'base_commit_allowed_days' ;
24+ static const String stalePrProtectionInDaysForBaseRefsKey =
25+ 'stale_pr_protection_in_days_for_base_refs' ;
2526
2627 static const String defaultBranchStr = 'default' ;
2728
@@ -34,7 +35,7 @@ class RepositoryConfiguration {
3435 bool ? runCi,
3536 bool ? supportNoReviewReverts,
3637 Set <String >? requiredCheckRunsOnRevert,
37- int ? baseCommitAllowedDays ,
38+ Map < String , int > ? stalePrProtectionInDaysForBaseRefs ,
3839 }) : allowConfigOverride = allowConfigOverride ?? false ,
3940 defaultBranch = defaultBranch ?? defaultBranchStr,
4041 autoApprovalAccounts = autoApprovalAccounts ?? < String > {},
@@ -43,7 +44,8 @@ class RepositoryConfiguration {
4344 runCi = runCi ?? true ,
4445 supportNoReviewReverts = supportNoReviewReverts ?? true ,
4546 requiredCheckRunsOnRevert = requiredCheckRunsOnRevert ?? < String > {},
46- baseCommitAllowedDays = baseCommitAllowedDays ?? 0 ;
47+ stalePrProtectionInDaysForBaseRefs =
48+ stalePrProtectionInDaysForBaseRefs ?? < String , int > {};
4749
4850 /// This flag allows the repository to override the org level configuration.
4951 bool allowConfigOverride;
@@ -74,9 +76,9 @@ class RepositoryConfiguration {
7476 /// merged.
7577 Set <String > requiredCheckRunsOnRevert;
7678
77- /// The number of days that the base commit of the pull request can not be
78- /// older than. If less than 1 then it will not be checked .
79- int baseCommitAllowedDays ;
79+ /// A map of [slug] / [branch] as a key and number of days to validate PR base
80+ /// date is not older than on that [slug] / [branch] .
81+ Map < String , int > stalePrProtectionInDaysForBaseRefs ;
8082
8183 @override
8284 String toString () {
@@ -95,7 +97,13 @@ class RepositoryConfiguration {
9597 for (var checkrun in requiredCheckRunsOnRevert) {
9698 stringBuffer.writeln (' - $checkrun ' );
9799 }
98- stringBuffer.writeln ('$baseCommitAllowedDaysKey : $baseCommitAllowedDays ' );
100+ if (stalePrProtectionInDaysForBaseRefs.isNotEmpty) {
101+ stringBuffer.writeln ('$stalePrProtectionInDaysForBaseRefsKey :' );
102+ for (final MapEntry (key: branch, value: days)
103+ in stalePrProtectionInDaysForBaseRefs.entries) {
104+ stringBuffer.writeln (' $branch : $days ' );
105+ }
106+ }
99107 return stringBuffer.toString ();
100108 }
101109
@@ -124,6 +132,27 @@ class RepositoryConfiguration {
124132 }
125133 }
126134
135+ final stalePrProtectionInDaysForBaseRefs = < String , int > {};
136+ final yamlstalePrProtectionInDaysForBaseRefs =
137+ yamlDoc[stalePrProtectionInDaysForBaseRefsKey] as YamlMap ? ;
138+ if (yamlstalePrProtectionInDaysForBaseRefs != null ) {
139+ for (var entry in yamlstalePrProtectionInDaysForBaseRefs.entries) {
140+ if (entry.value is ! int ) {
141+ throw ConfigurationException (
142+ 'The value for ${entry .key } must be an integer.' ,
143+ );
144+ }
145+ if (entry.value as int <= 0 ) {
146+ throw ConfigurationException (
147+ 'The value for ${entry .key } must be greater than zero.' ,
148+ );
149+ }
150+
151+ stalePrProtectionInDaysForBaseRefs[entry.key as String ] =
152+ entry.value as int ;
153+ }
154+ }
155+
127156 return RepositoryConfiguration (
128157 allowConfigOverride: yamlDoc[allowConfigOverrideKey] as bool ? ,
129158 defaultBranch: yamlDoc[defaultBranchKey] as String ? ,
@@ -133,7 +162,7 @@ class RepositoryConfiguration {
133162 runCi: yamlDoc[runCiKey] as bool ? ,
134163 supportNoReviewReverts: yamlDoc[supportNoReviewRevertKey] as bool ? ,
135164 requiredCheckRunsOnRevert: requiredCheckRunsOnRevert,
136- baseCommitAllowedDays : yamlDoc[baseCommitAllowedDaysKey] as int ? ,
165+ stalePrProtectionInDaysForBaseRefs : stalePrProtectionInDaysForBaseRefs ,
137166 );
138167 }
139168}
0 commit comments