Skip to content

Commit 2d0e934

Browse files
committed
feat: add OUTPUT_FILENAME to customize markdown output
Expose OUTPUT_FILENAME env var with default contributors.md, wire into markdown output, and document/test it. Signed-off-by: Venu Vardhan Reddy Tekula <venuvrtekula@gmail.com>
1 parent e2771ed commit 2d0e934

4 files changed

Lines changed: 51 additions & 2 deletions

File tree

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ This action can be configured to authenticate with GitHub App Installation or Pe
9393
| `END_DATE` | False | Current Date | The date at which you want to stop gathering contributor information. Must be later than the `START_DATE`. ie. Aug 2nd, 2023 would be `2023-08-02` |
9494
| `SPONSOR_INFO` | False | False | If you want to include sponsor information in the output. This will include the sponsor count and the sponsor URL. This will impact action performance. ie. SPONSOR_INFO = "False" or SPONSOR_INFO = "True" |
9595
| `LINK_TO_PROFILE` | False | True | If you want to link usernames to their GitHub profiles in the output. ie. LINK_TO_PROFILE = "True" or LINK_TO_PROFILE = "False" |
96+
| `OUTPUT_FILENAME` | False | contributors.md | The output filename for the markdown report. ie. OUTPUT_FILENAME = "my-report.md" |
9697

9798
**Note**: If `start_date` and `end_date` are specified then the action will determine if the contributor is new. A new contributor is one that has contributed in the date range specified but not before the start date.
9899

@@ -244,7 +245,7 @@ jobs:
244245

245246
When running as a GitHub Action, the contributors report is automatically displayed in the [GitHub Actions Job Summary](https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#adding-a-job-summary). This provides immediate visibility of the results directly in the workflow run interface without needing to check separate files or issues.
246247

247-
The job summary contains the same markdown content that is written to the `contributors.md` file, making it easy to view contributor information right in the GitHub Actions UI.
248+
The job summary contains the same markdown content that is written to the configured output file, making it easy to view contributor information right in the GitHub Actions UI.
248249

249250
## Local usage without Docker
250251

contributors.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ def main():
2727
end_date,
2828
sponsor_info,
2929
link_to_profile,
30+
output_filename,
3031
) = env.get_env_vars()
3132

3233
# Auth to GitHub.com
@@ -75,7 +76,7 @@ def main():
7576
# print(contributors)
7677
markdown.write_to_markdown(
7778
contributors,
78-
"contributors.md",
79+
output_filename,
7980
start_date,
8081
end_date,
8182
organization,

env.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ def get_env_vars(
115115
str,
116116
bool,
117117
bool,
118+
str,
118119
]:
119120
"""
120121
Get the environment variables for use in the action.
@@ -135,6 +136,7 @@ def get_env_vars(
135136
end_date (str): The end date to get contributor information to.
136137
sponsor_info (str): Whether to get sponsor information on the contributor
137138
link_to_profile (str): Whether to link username to Github profile in markdown output
139+
output_filename (str): The output filename for the markdown report
138140
"""
139141

140142
if not test:
@@ -176,6 +178,7 @@ def get_env_vars(
176178

177179
sponsor_info = get_bool_env_var("SPONSOR_INFO", False)
178180
link_to_profile = get_bool_env_var("LINK_TO_PROFILE", False)
181+
output_filename = os.getenv("OUTPUT_FILENAME", "").strip() or "contributors.md"
179182

180183
# Separate repositories_str into a list based on the comma separator
181184
repositories_list = []
@@ -197,4 +200,5 @@ def get_env_vars(
197200
end_date,
198201
sponsor_info,
199202
link_to_profile,
203+
output_filename,
200204
)

test_env.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ def setUp(self):
2323
"GITHUB_APP_ENTERPRISE_ONLY",
2424
"GH_TOKEN",
2525
"ORGANIZATION",
26+
"OUTPUT_FILENAME",
2627
"REPOSITORY",
2728
"START_DATE",
2829
]
@@ -65,6 +66,7 @@ def test_get_env_vars(self):
6566
end_date,
6667
sponsor_info,
6768
link_to_profile,
69+
output_filename,
6870
) = env.get_env_vars()
6971

7072
self.assertEqual(organization, "org")
@@ -79,6 +81,7 @@ def test_get_env_vars(self):
7981
self.assertEqual(end_date, "2022-12-31")
8082
self.assertFalse(sponsor_info)
8183
self.assertTrue(link_to_profile)
84+
self.assertEqual(output_filename, "contributors.md")
8285

8386
@patch.dict(
8487
os.environ,
@@ -175,6 +178,7 @@ def test_get_env_vars_no_dates(self):
175178
end_date,
176179
sponsor_info,
177180
link_to_profile,
181+
output_filename,
178182
) = env.get_env_vars()
179183

180184
self.assertEqual(organization, "org")
@@ -189,6 +193,45 @@ def test_get_env_vars_no_dates(self):
189193
self.assertEqual(end_date, "")
190194
self.assertFalse(sponsor_info)
191195
self.assertTrue(link_to_profile)
196+
self.assertEqual(output_filename, "contributors.md")
197+
198+
@patch.dict(
199+
os.environ,
200+
{
201+
"ORGANIZATION": "org",
202+
"REPOSITORY": "repo,repo2",
203+
"GH_APP_ID": "",
204+
"GH_APP_INSTALLATION_ID": "",
205+
"GH_APP_PRIVATE_KEY": "",
206+
"GH_TOKEN": "token",
207+
"GH_ENTERPRISE_URL": "",
208+
"START_DATE": "",
209+
"END_DATE": "",
210+
"SPONSOR_INFO": "False",
211+
"LINK_TO_PROFILE": "True",
212+
"OUTPUT_FILENAME": "custom-report.md",
213+
},
214+
clear=True,
215+
)
216+
def test_get_env_vars_custom_output_filename(self):
217+
"""Test that OUTPUT_FILENAME overrides the default output filename."""
218+
(
219+
_organization,
220+
_repository_list,
221+
_gh_app_id,
222+
_gh_app_installation_id,
223+
_gh_app_private_key,
224+
_gh_app_enterprise_only,
225+
_token,
226+
_ghe,
227+
_start_date,
228+
_end_date,
229+
_sponsor_info,
230+
_link_to_profile,
231+
output_filename,
232+
) = env.get_env_vars()
233+
234+
self.assertEqual(output_filename, "custom-report.md")
192235

193236
@patch.dict(os.environ, {})
194237
def test_get_env_vars_missing_org_or_repo(self):

0 commit comments

Comments
 (0)