Skip to content

Commit 29985e5

Browse files
committed
perf: call generate_markdown_content only once, use DRY principle
Signed-off-by: Zack Koppert <[email protected]>
1 parent 19315cc commit 29985e5

File tree

1 file changed

+13
-60
lines changed

1 file changed

+13
-60
lines changed

markdown.py

Lines changed: 13 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -62,41 +62,24 @@ def write_to_markdown(
6262
collaborators, start_date, end_date, total_contributions
6363
)
6464

65-
# Write the markdown file
66-
write_markdown_file(
67-
filename,
68-
start_date,
69-
end_date,
70-
organization,
71-
repository,
72-
table,
73-
summary_table,
65+
# Generate the markdown content once
66+
content = generate_markdown_content(
67+
start_date, end_date, organization, repository, table, summary_table
7468
)
7569

70+
# Write the markdown file
71+
write_markdown_file(filename, content)
72+
7673
# Also write to GitHub Actions Step Summary if available
77-
write_to_github_summary(
78-
start_date, end_date, organization, repository, table, summary_table
79-
)
74+
write_to_github_summary(content)
8075

8176

82-
def write_to_github_summary(
83-
start_date, end_date, organization, repository, table, summary_table
84-
):
77+
def write_to_github_summary(content):
8578
"""
8679
Write markdown content to GitHub Actions Step Summary.
8780
8881
Args:
89-
start_date (str): The start date of the date range for the contributor
90-
list.
91-
end_date (str): The end date of the date range for the contributor list.
92-
organization (str): The organization for which the contributors are
93-
being listed.
94-
repository (str): The repository for which the contributors are being
95-
listed.
96-
table (str): A string containing a markdown table of the contributors
97-
and the total contribution count.
98-
summary_table (str): A string containing a markdown table of the
99-
summary statistics.
82+
content (str): The pre-generated markdown content to write.
10083
10184
Returns:
10285
None
@@ -105,14 +88,6 @@ def write_to_github_summary(
10588
# environment
10689
github_step_summary = os.environ.get("GITHUB_STEP_SUMMARY")
10790
if github_step_summary:
108-
content = generate_markdown_content(
109-
start_date,
110-
end_date,
111-
organization,
112-
repository,
113-
table,
114-
summary_table,
115-
)
11691
with open(github_step_summary, "a", encoding="utf-8") as summary_file:
11792
summary_file.write(content)
11893

@@ -158,41 +133,19 @@ def generate_markdown_content(
158133
return content
159134

160135

161-
def write_markdown_file(
162-
filename,
163-
start_date,
164-
end_date,
165-
organization,
166-
repository,
167-
table,
168-
summary_table,
169-
):
136+
def write_markdown_file(filename, content):
170137
"""
171-
This function writes all the tables and data to a markdown file with
172-
tables to organize the information.
138+
This function writes the pre-generated markdown content to a file.
173139
174140
Args:
175-
filename (str): The path of the markdown file to which the table will
141+
filename (str): The path of the markdown file to which the content will
176142
be written.
177-
start_date (str): The start date of the date range for the contributor
178-
list.
179-
end_date (str): The end date of the date range for the contributor list.
180-
organization (str): The organization for which the contributors are
181-
being listed.
182-
repository (str): The repository for which the contributors are being
183-
listed.
184-
table (str): A string containing a markdown table of the contributors
185-
and the total contribution count.
186-
summary_table (str): A string containing a markdown table of the
187-
summary statistics.
143+
content (str): The pre-generated markdown content to write.
188144
189145
Returns:
190146
None
191147
192148
"""
193-
content = generate_markdown_content(
194-
start_date, end_date, organization, repository, table, summary_table
195-
)
196149
with open(filename, "w", encoding="utf-8") as markdown_file:
197150
markdown_file.write(content)
198151

0 commit comments

Comments
 (0)