createCheckRun method

Future<CheckRun> createCheckRun(
  1. RepositorySlug slug, {
  2. required String name,
  3. required String headSha,
  4. String? detailsUrl,
  5. String? externalId,
  6. CheckRunStatus status = CheckRunStatus.queued,
  7. DateTime? startedAt,
  8. CheckRunConclusion? conclusion,
  9. DateTime? completedAt,
  10. CheckRunOutput? output,
  11. List<CheckRunAction>? actions,
})

Creates a new check run for a specific commit in a repository. Your GitHub App must have the checks:write permission to create check runs.

  • name: The name of the check. For example, "code-coverage".
  • headSha: The SHA of the commit.
  • detailsUrl: The URL of the integrator's site that has the full details of the check.
  • externalId: A reference for the run on the integrator's system.
  • status: The current status. Can be one of queued, in_progress, or completed. Default: queued.
  • startedAt: The time that the check run began.
  • conclusion: Required if you provide completed_at or a status of completed. The final conclusion of the check. When the conclusion is action_required, additional details should be provided on the site specified by details_url. Note: Providing conclusion will automatically set the status parameter to completed.
  • completedAt: The time the check completed.
  • output: Check runs can accept a variety of data in the output object, including a title and summary and can optionally provide descriptive details about the run.
  • actions: Displays a button on GitHub that can be clicked to alert your app to do additional tasks. For example, a code linting app can display a button that automatically fixes detected errors. The button created in this object is displayed after the check run completes. When a user clicks the button, GitHub sends the check_run.requested_action webhook to your app. A maximum of three actions are accepted.

API docs: https://developer.github.com/v3/checks/runs/#create-a-check-run

Implementation

Future<CheckRun> createCheckRun(
  RepositorySlug slug, {
  required String name,
  required String headSha,
  String? detailsUrl,
  String? externalId,
  CheckRunStatus status = CheckRunStatus.queued,
  DateTime? startedAt,
  CheckRunConclusion? conclusion,
  DateTime? completedAt,
  CheckRunOutput? output,
  List<CheckRunAction>? actions,
}) async {
  assert(conclusion != null ||
      (completedAt == null && status != CheckRunStatus.completed));
  assert(actions == null || actions.length <= 3);
  return github.postJSON<Map<String, dynamic>, CheckRun>(
    '/repos/${slug.fullName}/check-runs',
    statusCode: StatusCodes.CREATED,
    preview: _previewHeader,
    body: jsonEncode(createNonNullMap(<String, dynamic>{
      'name': name,
      'head_sha': headSha,
      'details_url': detailsUrl,
      'external_id': externalId,
      'status': status,
      'started_at': dateToGitHubIso8601(startedAt),
      'conclusion': conclusion,
      'completed_at': dateToGitHubIso8601(completedAt),
      'output': output,
      'actions': actions,
    })),
    convert: CheckRun.fromJson,
  );
}