Add delay between deflake github requests (#2201)

diff --git a/app_dart/lib/src/request_handlers/check_flaky_builders.dart b/app_dart/lib/src/request_handlers/check_flaky_builders.dart
index eca5314..5b40997 100644
--- a/app_dart/lib/src/request_handlers/check_flaky_builders.dart
+++ b/app_dart/lib/src/request_handlers/check_flaky_builders.dart
@@ -81,6 +81,9 @@
           await bigquery.listRecentBuildRecordsForBuilder(kBigQueryProjectId, builder: info.name, limit: kRecordNumber);
       if (_shouldDeflake(builderRecords)) {
         await _deflakyPullRequest(gitHub, slug, info: info, ciContent: ciContent, testOwnership: testOwnership);
+        // Manually add a 1s delay between consecutive GitHub requests to deal with secondary rate limit error.
+        // https://docs.github.com/en/rest/guides/best-practices-for-integrators#dealing-with-secondary-rate-limits
+        await Future.delayed(config.githubRequestDelay);
       } else if (_shouldFileIssue(builderRecords, info)) {
         final BuilderDetail builderDetail = BuilderDetail(
           statistic: stagingBuilderStatisticList
diff --git a/app_dart/lib/src/service/config.dart b/app_dart/lib/src/service/config.dart
index 753e660..eae4182 100644
--- a/app_dart/lib/src/service/config.dart
+++ b/app_dart/lib/src/service/config.dart
@@ -271,6 +271,9 @@
   // Default number of commits to return for benchmark dashboard.
   int /*!*/ get maxRecords => 50;
 
+  // Delay between consecutive GitHub deflake request calls.
+  Duration get githubRequestDelay => const Duration(seconds: 1);
+
   // Repository status context for github status.
   String get flutterBuild => 'flutter-build';
 
diff --git a/app_dart/test/src/datastore/fake_config.dart b/app_dart/test/src/datastore/fake_config.dart
index 2822877..2116840 100644
--- a/app_dart/test/src/datastore/fake_config.dart
+++ b/app_dart/test/src/datastore/fake_config.dart
@@ -55,6 +55,7 @@
     this.supportedBranchesValue,
     this.supportedReposValue,
     this.batchSizeValue,
+    this.githubRequestDelayValue,
     FakeDatastoreDB? dbValue,
   }) : dbValue = dbValue ?? FakeDatastoreDB();
 
@@ -95,6 +96,7 @@
   List<String>? supportedBranchesValue;
   String? overrideTreeStatusLabelValue;
   Set<gh.RepositorySlug>? supportedReposValue;
+  Duration? githubRequestDelayValue;
 
   @override
   Future<gh.GitHub> createGitHubClient({gh.PullRequest? pullRequest, gh.RepositorySlug? slug}) async => githubClient!;
@@ -124,6 +126,9 @@
   FakeDatastoreDB get db => dbValue;
 
   @override
+  Duration get githubRequestDelay => githubRequestDelayValue ?? Duration.zero;
+
+  @override
   int get maxTaskRetries => maxTaskRetriesValue!;
 
   /// Size of the shards to send to buildBucket when scheduling builds.