Skip to content

Commit 634cf46

Browse files
authored
Merge pull request #373 from github/jm_custom_report_title_and_output_file
feat: REPORT_TITLE and OUTPUT_FILE environment variables
2 parents 2c95dd3 + 82a5a61 commit 634cf46

9 files changed

+94
-22
lines changed

.env-example

+3
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,7 @@ HIDE_TIME_TO_CLOSE = "false"
1111
HIDE_TIME_TO_FIRST_RESPONSE = "false"
1212
IGNORE_USERS = "user1,user2"
1313
LABELS_TO_MEASURE = "waiting-for-review,waiting-for-manager"
14+
NON_MENTIONING_LINKS = "false"
15+
OUTPUT_FILE = ""
16+
REPORT_TITLE = "Issue Metrics"
1417
SEARCH_QUERY = "repo:owner/repo is:open is:issue"

README.md

+19-17
Original file line numberDiff line numberDiff line change
@@ -139,23 +139,25 @@ This action can be configured to authenticate with GitHub App Installation or Pe
139139

140140
#### Other Configuration Options
141141

142-
| field | required | default | description |
143-
| ----------------------------- | -------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
144-
| `GH_ENTERPRISE_URL` | False | `""` | URL of GitHub Enterprise instance to use for auth instead of github.com |
145-
| `HIDE_AUTHOR` | False | False | If set to `true`, the author will not be displayed in the generated Markdown file. |
146-
| `HIDE_ITEMS_CLOSED_COUNT` | False | False | If set to `true`, the number of items closed metric will not be displayed in the generated Markdown file. |
147-
| `HIDE_LABEL_METRICS` | False | False | If set to `true`, the time in label metrics will not be displayed in the generated Markdown file. |
148-
| `HIDE_TIME_TO_ANSWER` | False | False | If set to `true`, the time to answer a discussion will not be displayed in the generated Markdown file. |
149-
| `HIDE_TIME_TO_CLOSE` | False | False | If set to `true`, the time to close will not be displayed in the generated Markdown file. |
150-
| `HIDE_TIME_TO_FIRST_RESPONSE` | False | False | If set to `true`, the time to first response will not be displayed in the generated Markdown file. |
151-
| `IGNORE_USERS` | False | False | A comma separated list of users to ignore when calculating metrics. (ie. `IGNORE_USERS: 'user1,user2'`). To ignore bots, append `[bot]` to the user (ie. `IGNORE_USERS: 'github-actions[bot]'`) |
152-
| `ENABLE_MENTOR_COUNT` | False | False | If set to 'TRUE' count number of comments users left on discussions, issues and PRs and display number of active mentors |
153-
| `MIN_MENTOR_COMMENTS` | False | 10 | Minimum number of comments to count as a mentor |
154-
| `MAX_COMMENTS_EVAL` | False | 20 | Maximum number of comments per thread to evaluate for mentor stats |
155-
| `HEAVILY_INVOLVED_CUTOFF` | False | 3 | Cutoff after which a mentor's comments in one issue are no longer counted against their total score |
156-
| `LABELS_TO_MEASURE` | False | `""` | A comma separated list of labels to measure how much time the label is applied. If not provided, no labels durations will be measured. Not compatible with discussions at this time. |
157-
| `NON_MENTIONING_LINKS` | False | False | If set to `true`, will use non-mentioning GitHub links to avoid linking to the generated issue from the source repository. Links of the form `https://github.com` will be used. |
158-
| `SEARCH_QUERY` | True | `""` | The query by which you can filter issues/PRs which must contain a `repo:`, `org:`, `owner:`, or a `user:` entry. For discussions, include `type:discussions` in the query. |
142+
| field | required | default | description |
143+
| ----------------------------- | -------- | ------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
144+
| `GH_ENTERPRISE_URL` | False | `""` | URL of GitHub Enterprise instance to use for auth instead of github.com |
145+
| `HIDE_AUTHOR` | False | False | If set to `true`, the author will not be displayed in the generated Markdown file. |
146+
| `HIDE_ITEMS_CLOSED_COUNT` | False | False | If set to `true`, the number of items closed metric will not be displayed in the generated Markdown file. |
147+
| `HIDE_LABEL_METRICS` | False | False | If set to `true`, the time in label metrics will not be displayed in the generated Markdown file. |
148+
| `HIDE_TIME_TO_ANSWER` | False | False | If set to `true`, the time to answer a discussion will not be displayed in the generated Markdown file. |
149+
| `HIDE_TIME_TO_CLOSE` | False | False | If set to `true`, the time to close will not be displayed in the generated Markdown file. |
150+
| `HIDE_TIME_TO_FIRST_RESPONSE` | False | False | If set to `true`, the time to first response will not be displayed in the generated Markdown file. |
151+
| `IGNORE_USERS` | False | False | A comma separated list of users to ignore when calculating metrics. (ie. `IGNORE_USERS: 'user1,user2'`). To ignore bots, append `[bot]` to the user (ie. `IGNORE_USERS: 'github-actions[bot]'`) |
152+
| `ENABLE_MENTOR_COUNT` | False | False | If set to 'TRUE' count number of comments users left on discussions, issues and PRs and display number of active mentors |
153+
| `MIN_MENTOR_COMMENTS` | False | 10 | Minimum number of comments to count as a mentor |
154+
| `MAX_COMMENTS_EVAL` | False | 20 | Maximum number of comments per thread to evaluate for mentor stats |
155+
| `HEAVILY_INVOLVED_CUTOFF` | False | 3 | Cutoff after which a mentor's comments in one issue are no longer counted against their total score |
156+
| `LABELS_TO_MEASURE` | False | `""` | A comma separated list of labels to measure how much time the label is applied. If not provided, no labels durations will be measured. Not compatible with discussions at this time. |
157+
| `NON_MENTIONING_LINKS` | False | False | If set to `true`, will use non-mentioning GitHub links to avoid linking to the generated issue from the source repository. Links of the form `https://github.com` will be used. |
158+
| `OUTPUT_FILE` | False | `issue_metrics.md` or `issue_metrics.json` | Output filename. |
159+
| `REPORT_TITLE` | False | `"Issue Metrics"` | Title to have on the report issue. |
160+
| `SEARCH_QUERY` | True | `""` | The query by which you can filter issues/PRs which must contain a `repo:`, `org:`, `owner:`, or a `user:` entry. For discussions, include `type:discussions` in the query. |
159161

160162
## Further Documentation
161163

config.py

+14
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ class EnvVars:
4040
max_comments_eval (str): If set, defines the maximum number of comments to look at for mentor evaluation
4141
heavily_involved_cutoff (str): If set, defines the cutoff after which heavily involved commentors in
4242
search_query (str): Search query used to filter issues/prs/discussions on GitHub
43+
non_mentioning_links (bool): If set to TRUE, links do not cause a notification in the desitnation repository
44+
report_title (str): The title of the report
45+
output_file (str): The name of the file to write the report to
4346
"""
4447

4548
def __init__(
@@ -63,6 +66,8 @@ def __init__(
6366
heavily_involved_cutoff: str,
6467
search_query: str,
6568
non_mentioning_links: bool,
69+
report_title: str,
70+
output_file: str,
6671
):
6772
self.gh_app_id = gh_app_id
6873
self.gh_app_installation_id = gh_app_installation_id
@@ -83,6 +88,8 @@ def __init__(
8388
self.heavily_involved_cutoff = heavily_involved_cutoff
8489
self.search_query = search_query
8590
self.non_mentioning_links = non_mentioning_links
91+
self.report_title = report_title
92+
self.output_file = output_file
8693

8794
def __repr__(self):
8895
return (
@@ -106,6 +113,8 @@ def __repr__(self):
106113
f"{self.heavily_involved_cutoff},"
107114
f"{self.search_query}"
108115
f"{self.non_mentioning_links}"
116+
f"{self.report_title}"
117+
f"{self.output_file}"
109118
)
110119

111120

@@ -187,6 +196,9 @@ def get_env_vars(test: bool = False) -> EnvVars:
187196
if ignore_users:
188197
ignore_users_list = ignore_users.split(",")
189198

199+
report_title = os.getenv("REPORT_TITLE", "Issue Metrics")
200+
output_file = os.getenv("OUTPUT_FILE", "")
201+
190202
# Hidden columns
191203
hide_author = get_bool_env_var("HIDE_AUTHOR", False)
192204
hide_items_closed_count = get_bool_env_var("HIDE_ITEMS_CLOSED_COUNT", False)
@@ -220,4 +232,6 @@ def get_env_vars(test: bool = False) -> EnvVars:
220232
heavily_involved_cutoff,
221233
search_query,
222234
non_mentioning_links,
235+
report_title,
236+
output_file,
223237
)

issue_metrics.py

+6
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,8 @@ def main():
307307
ignore_users = env_vars.ignore_users
308308
hide_items_closed_count = env_vars.hide_items_closed_count
309309
non_mentioning_links = env_vars.non_mentioning_links
310+
report_title = env_vars.report_title
311+
output_file = env_vars.output_file
310312

311313
gh_app_id = env_vars.gh_app_id
312314
gh_app_installation_id = env_vars.gh_app_installation_id
@@ -401,6 +403,8 @@ def main():
401403
num_issues_closed,
402404
num_mentor_count,
403405
search_query,
406+
report_title,
407+
output_file,
404408
)
405409

406410
write_to_markdown(
@@ -416,6 +420,8 @@ def main():
416420
search_query,
417421
hide_items_closed_count,
418422
non_mentioning_links,
423+
report_title,
424+
output_file,
419425
)
420426

421427
max_char_count = 65535

json_writer.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
num_issues_opened: int,
1010
num_issues_closed: int,
1111
search_query: str,
12+
output_file: str,
1213
) -> str:
1314
Write the issues with metrics to a json file.
1415
@@ -32,6 +33,7 @@ def write_to_json(
3233
num_issues_closed: Union[int, None],
3334
num_mentor_count: Union[int, None],
3435
search_query: str,
36+
output_file: str,
3537
) -> str:
3638
"""
3739
Write the issues with metrics to a JSON file called issue_metrics.json.
@@ -168,7 +170,8 @@ def write_to_json(
168170
print(f"metrics={metrics_json}", file=file_handle)
169171

170172
# Write the metrics to a JSON file
171-
with open("issue_metrics.json", "w", encoding="utf-8") as file:
173+
output_file_name = output_file if output_file else "issue_metrics.json"
174+
with open(output_file_name, "w", encoding="utf-8") as file:
172175
json.dump(metrics, file, indent=4)
173176

174177
return metrics_json

markdown_writer.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ def write_to_markdown(
8686
hide_label_metrics=False,
8787
hide_items_closed_count=False,
8888
non_mentioning_links=False,
89+
report_title="",
90+
output_file="",
8991
) -> None:
9092
"""Write the issues with metrics to a markdown file.
9193
@@ -105,14 +107,18 @@ def write_to_markdown(
105107
search_query (str): The search query used to find the issues.
106108
hide_label_metrics (bool): Represents whether the user has chosen to hide label metrics in the output
107109
hide_items_closed_count (bool): Represents whether the user has chosen to hide the number of items closed
110+
non_mentioning_links (bool): Represents whether links do not cause a notification in the desitnation repository
111+
report_title (str): The title of the report
112+
output_file (str): The name of the file to write the report to
108113
109114
Returns:
110115
None.
111116
112117
"""
113118
columns = get_non_hidden_columns(labels)
114-
with open("issue_metrics.md", "w", encoding="utf-8") as file:
115-
file.write("# Issue Metrics\n\n")
119+
output_file_name = output_file if output_file else "issue_metrics.md"
120+
with open(output_file_name, "w", encoding="utf-8") as file:
121+
file.write(f"# {report_title}\n\n")
116122

117123
# If all the metrics are None, then there are no issues
118124
if not issues_with_metrics or len(issues_with_metrics) == 0:

test_config.py

+21-1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ def setUp(self):
7979
"HIDE_TIME_TO_FIRST_RESPONSE",
8080
"IGNORE_USERS",
8181
"LABELS_TO_MEASURE",
82+
"NON_MENTIONING_LINKS",
83+
"OUTPUT_FILE",
84+
"REPORT_TITLE",
8285
"SEARCH_QUERY",
8386
]
8487
for key in env_keys:
@@ -101,6 +104,9 @@ def setUp(self):
101104
"HIDE_TIME_TO_FIRST_RESPONSE": "",
102105
"IGNORE_USERS": "",
103106
"LABELS_TO_MEASURE": "",
107+
"NON_MENTIONING_LINKS": "false",
108+
"OUTPUT_FILE": "",
109+
"REPORT_TITLE": "",
104110
"SEARCH_QUERY": SEARCH_QUERY,
105111
},
106112
clear=True,
@@ -127,6 +133,8 @@ def test_get_env_vars_with_github_app(self):
127133
"3",
128134
SEARCH_QUERY,
129135
False,
136+
"",
137+
"",
130138
)
131139
result = get_env_vars(True)
132140
self.assertEqual(str(result), str(expected_result))
@@ -147,6 +155,9 @@ def test_get_env_vars_with_github_app(self):
147155
"HIDE_TIME_TO_FIRST_RESPONSE": "",
148156
"IGNORE_USERS": "",
149157
"LABELS_TO_MEASURE": "",
158+
"NON_MENTIONING_LINKS": "false",
159+
"OUTPUT_FILE": "",
160+
"REPORT_TITLE": "",
150161
"SEARCH_QUERY": SEARCH_QUERY,
151162
},
152163
clear=True,
@@ -173,6 +184,8 @@ def test_get_env_vars_with_token(self):
173184
"3",
174185
SEARCH_QUERY,
175186
False,
187+
"",
188+
"",
176189
)
177190
result = get_env_vars(True)
178191
self.assertEqual(str(result), str(expected_result))
@@ -228,6 +241,9 @@ def test_get_env_vars_missing_query(self):
228241
"HIDE_TIME_TO_FIRST_RESPONSE": "true",
229242
"IGNORE_USERS": "",
230243
"LABELS_TO_MEASURE": "waiting-for-review,waiting-for-manager",
244+
"NON_MENTIONING_LINKS": "true",
245+
"OUTPUT_FILE": "issue_metrics.md",
246+
"REPORT_TITLE": "Issue Metrics",
231247
"SEARCH_QUERY": SEARCH_QUERY,
232248
},
233249
)
@@ -252,7 +268,9 @@ def test_get_env_vars_optional_values(self):
252268
20,
253269
3,
254270
SEARCH_QUERY,
255-
False,
271+
True,
272+
"Issue Metrics",
273+
"issue_metrics.md",
256274
)
257275
result = get_env_vars(True)
258276
self.assertEqual(str(result), str(expected_result))
@@ -290,6 +308,8 @@ def test_get_env_vars_optionals_are_defaulted(self):
290308
"3",
291309
SEARCH_QUERY,
292310
False,
311+
"Issue Metrics",
312+
"",
293313
)
294314
result = get_env_vars(True)
295315
self.assertEqual(str(result), str(expected_result))

test_json_writer.py

+2
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ def test_write_to_json(self):
115115
num_issues_closed=num_issues_closed,
116116
num_mentor_count=num_mentor_count,
117117
search_query="is:issue repo:owner/repo",
118+
output_file="issue_metrics.json",
118119
),
119120
json.dumps(expected_output),
120121
)
@@ -206,6 +207,7 @@ def test_write_to_json_with_no_response(self):
206207
num_issues_closed=num_issues_closed,
207208
num_mentor_count=num_mentor_count,
208209
search_query="is:issue repo:owner/repo",
210+
output_file="issue_metrics.json",
209211
),
210212
json.dumps(expected_output),
211213
)

test_markdown_writer.py

+17-1
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ def test_write_to_markdown(self):
9292
num_mentor_count=num_mentor_count,
9393
labels=["bug"],
9494
search_query="is:issue is:open label:bug",
95+
report_title="Issue Metrics",
96+
output_file="issue_metrics.md",
9597
)
9698

9799
# Check that the function writes the correct markdown file
@@ -191,6 +193,8 @@ def test_write_to_markdown_with_vertical_bar_in_title(self):
191193
num_issues_closed=num_issues_closed,
192194
num_mentor_count=num_mentor_count,
193195
labels=["bug"],
196+
report_title="Issue Metrics",
197+
output_file="issue_metrics.md",
194198
)
195199

196200
# Check that the function writes the correct markdown file
@@ -227,7 +231,17 @@ def test_write_to_markdown_no_issues(self):
227231
"""Test that write_to_markdown writes the correct markdown file when no issues are found."""
228232
# Call the function with no issues
229233
with patch("builtins.open", mock_open()) as mock_open_file:
230-
write_to_markdown(None, None, None, None, None, None, None, None)
234+
write_to_markdown(
235+
None,
236+
None,
237+
None,
238+
None,
239+
None,
240+
None,
241+
None,
242+
None,
243+
report_title="Issue Metrics",
244+
)
231245

232246
# Check that the file was written correctly
233247
expected_output = [
@@ -316,6 +330,8 @@ def test_writes_markdown_file_with_non_hidden_columns_only(self):
316330
hide_label_metrics=True,
317331
hide_items_closed_count=True,
318332
non_mentioning_links=True,
333+
report_title="Issue Metrics",
334+
output_file="issue_metrics.md",
319335
)
320336

321337
# Check that the function writes the correct markdown file

0 commit comments

Comments
 (0)