Future _applyFrameworkRepoLabels()

in app_dart/lib/src/request_handlers/github_webhook.dart [194:253]


  Future<void> _applyFrameworkRepoLabels(GitHub gitHubClient, String? eventAction, PullRequest pr) async {
    if (pr.user!.login == 'engine-flutter-autoroll') {
      return;
    }

    final RepositorySlug slug = pr.base!.repo!.slug();
    log.info('Applying framework repo labels for: owner=${slug.owner} repo=${slug.name} and pr=${pr.number}');
    final Stream<PullRequestFile> files = gitHubClient.pullRequests.listFiles(slug, pr.number!);

    final Set<String> labels = <String>{};
    bool hasTests = false;
    bool needsTests = false;

    await for (PullRequestFile file in files) {
      // When null, do not assume 0 lines have been added.
      final String filename = file.filename!;
      final int linesAdded = file.additionsCount ?? 1;
      final int linesDeleted = file.deletionsCount ?? 0;
      final int linesTotal = file.changesCount ?? linesDeleted + linesAdded;
      final bool addedCode = linesAdded > 0 || linesDeleted != linesTotal;

      if (addedCode &&
          !filename.contains('AUTHORS') &&
          !filename.contains('pubspec.yaml') &&
          !filename.contains('.ci.yaml') &&
          !filename.contains('.github') &&
          !filename.endsWith('.md') &&
          !filename.startsWith('dev/devicelab/bin/tasks') &&
          !filename.startsWith('dev/devicelab/lib/tasks') &&
          !filename.startsWith('dev/bots/')) {
        needsTests = !_allChangesAreCodeComments(file);
      }

      if ((filename.endsWith('_test.dart') ||
              filename.endsWith('.expect') ||
              filename.contains('test_fixes') ||
              filename.startsWith('dev/bots/test.dart') ||
              filename.startsWith('dev/bots/analyze.dart')) &&
          !kNotActuallyATest.any(filename.endsWith)) {
        hasTests = true;
      }
      labels.addAll(getLabelsForFrameworkPath(filename));
    }

    if (pr.user!.login == 'fluttergithubbot') {
      needsTests = false;
      labels.addAll(<String>['team', 'tech-debt', 'team: flakes']);
    }

    if (labels.isNotEmpty) {
      await gitHubClient.issues.addLabelsToIssue(slug, pr.number!, labels.toList());
    }

    if (!hasTests && needsTests && !pr.draft!) {
      final String body = config.missingTestsPullRequestMessage;
      if (!await _alreadyCommented(gitHubClient, pr, body)) {
        await gitHubClient.issues.createComment(slug, pr.number!, body);
      }
    }
  }