Future executeCommand()

in github-label-notifier/symbolizer/lib/bot.dart [140:191]


  Future<void> executeCommand(
    RepositorySlug repo,
    Issue issue,
    IssueComment commandComment, {
    @required bool authorized,
  }) async {
    if (!authorized) {
      await github.issues.createComment(repo, issue.number, '''
@${commandComment.user.login} Sorry, only **public members of Flutter org** can trigger my services.

Check your privacy settings as described [here](https://docs.github.com/en/free-pro-team@latest/github/setting-up-and-managing-your-github-user-account/publicizing-or-hiding-organization-membership).
''');
      return;
    }

    final command = parseCommand(issue.number, commandComment.body);
    if (command == null) {
      return;
    }

    // Comments which potentially contain crashes by their id.
    Map<int, _Comment> worklist;
    if (command.shouldProcessAll) {
      worklist = await processAllComments(repo, issue);
    } else {
      worklist = {};
      if (command.symbolizeThis) {
        worklist[commandComment.id] = _Comment.fromComment(commandComment);
      }

      // Process worklist from the command and fetch comment bodies.
      for (var ref in command.worklist) {
        // ref has one of the following formats: issue-id or issuecomment-id
        final c = ref.split('-');
        final id = int.parse(c[1]);
        if (c[0] == 'issue') {
          worklist[issue.id] = _Comment.fromIssue(issue);
        } else {
          try {
            final comment = await github.issues.getComment(repo, id);
            worklist[comment.id] = _Comment.fromComment(comment);
          } catch (e) {
            // Ignore.
          }
        }
      }
    }

    // Process comments from the worklist.
    await symbolizeGiven(
        repo, issue, commandComment.user, worklist, command.overrides);
  }