Skip to content

Commit c757eb1

Browse files
committed
Generate Yard docs for the the GithubActionCheckRunFormatter class
1 parent 26d8de3 commit c757eb1

File tree

1 file changed

+42
-1
lines changed

1 file changed

+42
-1
lines changed

src/github_action_check_run_formatter.rb

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,35 @@
33

44
module Pronto
55
module Formatter
6+
# The GithubActionCheckRunFormatter class is responsible for formatting and creating
7+
# GitHub Action Check Runs. It extends the Pronto::Formatter::Base class
8+
# and integrates with GitHub Actions to generate check runs based
9+
# on the messages produced by Pronto runners.
10+
#
11+
# This class handles the interaction with the GitHub API to create check runs for each
12+
# runner, providing detailed annotations and summaries of the analysis results.
13+
#
14+
# @attr_accessor [Array<Pronto::Message>] messages
15+
# The collection of messages that need to be formatted into check runs.
16+
#
17+
# @attr_accessor [Pronto::Git::Repository] repo
18+
# The repository object representing the Git repository being analyzed.
19+
#
20+
# @attr_accessor [String] sha
21+
# The commit SHA for which the check runs are being created. This is typically
22+
# the SHA of the head commit in the repository.
23+
#
24+
# @attr_accessor [Object] check_run
25+
# The check run object that represents the current check run being processed.
26+
# This object is used to store and manage the state of the check run.
627
class GithubActionCheckRunFormatter < Base
728
attr_accessor :messages, :repo, :sha, :check_run
829

30+
# Formats the messages into GitHub Action Check Runs.
31+
#
32+
# @param messages [Array<Pronto::Message>] The collection of messages to be formatted.
33+
# @param repo [Pronto::Git::Repository] The repository being analyzed.
34+
# @return [String] A summary of the number of check runs created.
935
def format(messages, repo, _)
1036
self.messages = messages
1137
self.repo = repo
@@ -18,6 +44,7 @@ def format(messages, repo, _)
1844
"#{Runner.runners.size} Check Runs created"
1945
end
2046

47+
# @return [Octokit::Client] The Octokit client configured with GitHub API credentials.
2148
def client
2249
@client ||= Octokit::Client.new(
2350
api_endpoint: config.github_api_endpoint,
@@ -26,14 +53,19 @@ def client
2653
)
2754
end
2855

56+
# Creates a GitHub Action Check Run for a given runner and its messages.
57+
#
58+
# @param runner [Object] The runner for which the check run is being created.
59+
# @param runner_messages [Array<Pronto::Message>] The messages associated with the runner.
60+
# @return [void]
2961
def create_check_run(runner, runner_messages)
3062
line_annotations, no_line_annotations = runner_messages.map do |message|
3163
Annotation.new(message)
3264
end.partition(&:line?)
3365
output = OpenStruct.new(
3466
title: runner.title,
3567
summary: check_run_summary(runner, runner_messages),
36-
annotations: line_annotations.map(&:to_h).first(50),
68+
annotations: line_annotations.map(&:to_h).first(50)
3769
)
3870
if no_line_annotations.any?
3971
output.text = <<~TXT
@@ -55,6 +87,11 @@ def create_check_run(runner, runner_messages)
5587
)
5688
end
5789

90+
# Generates a summary for a GitHub Action Check Run.
91+
#
92+
# @param runner [Object] The runner for which the summary is being generated.
93+
# @param runner_messages [Array<Pronto::Message>] The messages associated with the runner.
94+
# @return [String] A summary of the check run, indicating the number of issues or a success message.
5895
def check_run_summary(runner, runner_messages)
5996
if runner_messages.any?
6097
<<~TXT
@@ -66,6 +103,10 @@ def check_run_summary(runner, runner_messages)
66103
end
67104
end
68105

106+
# Retrieves the repository slug from the GitHub event or configuration.
107+
#
108+
# @return [String] The full name of the repository in the format "owner/repo".
109+
# @raise [RuntimeError] If the GitHub event path is not set and the slug is not found in the config.
69110
def repo_slug
70111
@repo_slug ||= if ENV.key?('GITHUB_EVENT_PATH')
71112
event = JSON.parse(File.read(ENV.fetch('GITHUB_EVENT_PATH')))

0 commit comments

Comments
 (0)