Skip to content

Commit 7c09c70

Browse files
committed
feat: Add option to hide Number of items closed metric
Signed-off-by: Zack Koppert <[email protected]>
1 parent cd573ba commit 7c09c70

File tree

7 files changed

+85
-25
lines changed

7 files changed

+85
-25
lines changed

.env-example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ GH_APP_PRIVATE_KEY=""
44
GH_ENTERPRISE_URL = ""
55
GH_TOKEN = ""
66
HIDE_AUTHOR = "false"
7+
HIDE_ITEMS_CLOSED_COUNT="false"
78
HIDE_LABEL_METRICS = "false"
89
HIDE_TIME_TO_ANSWER = "false"
910
HIDE_TIME_TO_CLOSE = "false"

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ This action can be configured to authenticate with GitHub App Installation or Pe
154154
| `HEAVILY_INVOLVED_CUTOFF` | False | 3 | Cutoff after which a mentor's comments in one issue are no longer counted against their total score |
155155
| `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. |
156156
| `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. |
157+
| `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. |
157158

158159
## Further Documentation
159160

config.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class EnvVars:
2828
gh_token (str | None): GitHub personal access token (PAT) for API authentication
2929
ghe (str): The GitHub Enterprise URL to use for authentication
3030
hide_author (bool): If true, the author's information is hidden in the output
31+
hide_items_closed_count (bool): If true, the number of items closed metric is hidden in the output
3132
hide_label_metrics (bool): If true, the label metrics are hidden in the output
3233
hide_time_to_answer (bool): If true, the time to answer discussions is hidden in the output
3334
hide_time_to_close (bool): If true, the time to close metric is hidden in the output
@@ -49,6 +50,7 @@ def __init__(
4950
gh_token: str | None,
5051
ghe: str | None,
5152
hide_author: bool,
53+
hide_items_closed_count: bool,
5254
hide_label_metrics: bool,
5355
hide_time_to_answer: bool,
5456
hide_time_to_close: bool,
@@ -69,6 +71,7 @@ def __init__(
6971
self.ignore_users = ignore_user
7072
self.labels_to_measure = labels_to_measure
7173
self.hide_author = hide_author
74+
self.hide_items_closed_count = hide_items_closed_count
7275
self.hide_label_metrics = hide_label_metrics
7376
self.hide_time_to_answer = hide_time_to_answer
7477
self.hide_time_to_close = hide_time_to_close
@@ -88,6 +91,7 @@ def __repr__(self):
8891
f"{self.gh_token},"
8992
f"{self.ghe},"
9093
f"{self.hide_author},"
94+
f"{self.hide_items_closed_count}),"
9195
f"{self.hide_label_metrics},"
9296
f"{self.hide_time_to_answer},"
9397
f"{self.hide_time_to_close},"
@@ -98,7 +102,7 @@ def __repr__(self):
98102
f"{self.min_mentor_comments},"
99103
f"{self.max_comments_eval},"
100104
f"{self.heavily_involved_cutoff},"
101-
f"{self.search_query})"
105+
f"{self.search_query}"
102106
)
103107

104108

@@ -182,6 +186,7 @@ def get_env_vars(test: bool = False) -> EnvVars:
182186

183187
# Hidden columns
184188
hide_author = get_bool_env_var("HIDE_AUTHOR", False)
189+
hide_items_closed_count = get_bool_env_var("HIDE_ITEMS_CLOSED_COUNT", False)
185190
hide_label_metrics = get_bool_env_var("HIDE_LABEL_METRICS", False)
186191
hide_time_to_answer = get_bool_env_var("HIDE_TIME_TO_ANSWER", False)
187192
hide_time_to_close = get_bool_env_var("HIDE_TIME_TO_CLOSE", False)
@@ -198,6 +203,7 @@ def get_env_vars(test: bool = False) -> EnvVars:
198203
gh_token,
199204
ghe,
200205
hide_author,
206+
hide_items_closed_count,
201207
hide_label_metrics,
202208
hide_time_to_answer,
203209
hide_time_to_close,

issue_metrics.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ def main():
305305
search_query = env_vars.search_query
306306
token = env_vars.gh_token
307307
ignore_users = env_vars.ignore_users
308+
hide_items_closed_count = env_vars.hide_items_closed_count
308309

309310
gh_app_id = env_vars.gh_app_id
310311
gh_app_installation_id = env_vars.gh_app_installation_id
@@ -412,6 +413,7 @@ def main():
412413
num_mentor_count,
413414
labels,
414415
search_query,
416+
hide_items_closed_count,
415417
)
416418

417419
max_char_count = 65535

markdown_writer.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ def write_to_markdown(
8484
labels=None,
8585
search_query=None,
8686
hide_label_metrics=False,
87+
hide_items_closed_count=False,
8788
) -> None:
8889
"""Write the issues with metrics to a markdown file.
8990
@@ -102,6 +103,7 @@ def write_to_markdown(
102103
labels (List[str]): A list of the labels that are used in the issues.
103104
search_query (str): The search query used to find the issues.
104105
hide_label_metrics (bool): Represents whether the user has chosen to hide label metrics in the output
106+
hide_items_closed_count (bool): Represents whether the user has chosen to hide the number of items closed
105107
106108
Returns:
107109
None.
@@ -135,6 +137,7 @@ def write_to_markdown(
135137
columns,
136138
file,
137139
hide_label_metrics,
140+
hide_items_closed_count,
138141
)
139142

140143
# Write second table with individual issue/pr/discussion metrics
@@ -193,6 +196,7 @@ def write_overall_metrics_tables(
193196
columns,
194197
file,
195198
hide_label_metrics,
199+
hide_items_closed_count=False,
196200
):
197201
"""Write the overall metrics tables to the markdown file."""
198202
if (
@@ -250,6 +254,7 @@ def write_overall_metrics_tables(
250254
file.write("| Metric | Count |\n")
251255
file.write("| --- | ---: |\n")
252256
file.write(f"| Number of items that remain open | {num_issues_opened} |\n")
253-
file.write(f"| Number of items closed | {num_issues_closed} |\n")
257+
if not hide_items_closed_count:
258+
file.write(f"| Number of items closed | {num_issues_closed} |\n")
254259
file.write(f"| Number of most active mentors | {num_mentor_count} |\n")
255260
file.write(f"| Total number of items created | {len(issues_with_metrics)} |\n\n")

test_config.py

Lines changed: 67 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ def setUp(self):
7272
"GH_TOKEN",
7373
"GHE",
7474
"HIDE_AUTHOR",
75+
"HIDE_ITEMS_CLOSED_COUNT",
7576
"HIDE_LABEL_METRICS",
7677
"HIDE_TIME_TO_ANSWER",
7778
"HIDE_TIME_TO_CLOSE",
@@ -93,6 +94,7 @@ def setUp(self):
9394
"GH_TOKEN": "",
9495
"GH_ENTERPRISE_URL": "",
9596
"HIDE_AUTHOR": "",
97+
"HIDE_ITEMS_CLOSED_COUNT": "false",
9698
"HIDE_LABEL_METRICS": "",
9799
"HIDE_TIME_TO_ANSWER": "",
98100
"HIDE_TIME_TO_CLOSE": "",
@@ -116,6 +118,7 @@ def test_get_env_vars_with_github_app(self):
116118
False,
117119
False,
118120
False,
121+
False,
119122
[],
120123
[],
121124
False,
@@ -136,6 +139,7 @@ def test_get_env_vars_with_github_app(self):
136139
"GH_ENTERPRISE_URL": "",
137140
"GH_TOKEN": TOKEN,
138141
"HIDE_AUTHOR": "",
142+
"HIDE_ITEMS_CLOSED_COUNT": "false",
139143
"HIDE_LABEL_METRICS": "",
140144
"HIDE_TIME_TO_ANSWER": "",
141145
"HIDE_TIME_TO_CLOSE": "",
@@ -159,6 +163,7 @@ def test_get_env_vars_with_token(self):
159163
False,
160164
False,
161165
False,
166+
False,
162167
[],
163168
[],
164169
False,
@@ -170,6 +175,41 @@ def test_get_env_vars_with_token(self):
170175
result = get_env_vars(True)
171176
self.assertEqual(str(result), str(expected_result))
172177

178+
@patch.dict(
179+
os.environ,
180+
{
181+
"GH_APP_ID": "",
182+
"GH_APP_INSTALLATION_ID": "",
183+
"GH_APP_PRIVATE_KEY": "",
184+
"GH_TOKEN": "",
185+
"SEARCH_QUERY": SEARCH_QUERY,
186+
"HIDE_ITEMS_CLOSED_COUNT": "false",
187+
},
188+
clear=True,
189+
)
190+
def test_get_env_vars_missing_token(self):
191+
"""Test that an error is raised if the TOKEN environment variables is not set"""
192+
with self.assertRaises(ValueError):
193+
get_env_vars(True)
194+
195+
@patch.dict(
196+
os.environ,
197+
{
198+
"GH_APP_ID": "",
199+
"GH_APP_INSTALLATION_ID": "",
200+
"GH_APP_PRIVATE_KEY": "",
201+
"GH_TOKEN": TOKEN,
202+
"SEARCH_QUERY": "",
203+
"HIDE_ITEMS_CLOSED_COUNT": "false",
204+
},
205+
clear=True,
206+
)
207+
def test_get_env_vars_missing_query(self):
208+
"""Test that an error is raised if the SEARCH_QUERY environment variable is not set."""
209+
210+
with self.assertRaises(ValueError):
211+
get_env_vars(True)
212+
173213
@patch.dict(
174214
os.environ,
175215
{
@@ -179,6 +219,7 @@ def test_get_env_vars_with_token(self):
179219
"GH_TOKEN": TOKEN,
180220
"GH_ENTERPRISE_URL": "",
181221
"HIDE_AUTHOR": "true",
222+
"HIDE_ITEMS_CLOSED_COUNT": "true",
182223
"HIDE_LABEL_METRICS": "true",
183224
"HIDE_TIME_TO_ANSWER": "true",
184225
"HIDE_TIME_TO_CLOSE": "true",
@@ -201,6 +242,7 @@ def test_get_env_vars_optional_values(self):
201242
True,
202243
True,
203244
True,
245+
True,
204246
[],
205247
["waiting-for-review", "waiting-for-manager"],
206248
False,
@@ -218,32 +260,35 @@ def test_get_env_vars_optional_values(self):
218260
"GH_APP_ID": "",
219261
"GH_APP_INSTALLATION_ID": "",
220262
"GH_APP_PRIVATE_KEY": "",
221-
"GH_TOKEN": "",
263+
"GH_TOKEN": "TOKEN",
222264
"SEARCH_QUERY": SEARCH_QUERY,
223265
},
224266
clear=True,
225267
)
226-
def test_get_env_vars_missing_token(self):
227-
"""Test that an error is raised if the TOKEN environment variables is not set"""
228-
with self.assertRaises(ValueError):
229-
get_env_vars(True)
230-
231-
@patch.dict(
232-
os.environ,
233-
{
234-
"GH_APP_ID": "",
235-
"GH_APP_INSTALLATION_ID": "",
236-
"GH_APP_PRIVATE_KEY": "",
237-
"GH_TOKEN": TOKEN,
238-
"SEARCH_QUERY": "",
239-
},
240-
clear=True,
241-
)
242-
def test_get_env_vars_missing_query(self):
243-
"""Test that an error is raised if the SEARCH_QUERY environment variable is not set."""
244-
245-
with self.assertRaises(ValueError):
246-
get_env_vars(True)
268+
def test_get_env_vars_optionals_are_defaulted(self):
269+
"""Test that optional values are set to their default values if not provided"""
270+
expected_result = EnvVars(
271+
None,
272+
None,
273+
b"",
274+
"TOKEN",
275+
"",
276+
False,
277+
False,
278+
False,
279+
False,
280+
False,
281+
False,
282+
[],
283+
[],
284+
False,
285+
"10",
286+
"20",
287+
"3",
288+
SEARCH_QUERY,
289+
)
290+
result = get_env_vars(True)
291+
self.assertEqual(str(result), str(expected_result))
247292

248293

249294
if __name__ == "__main__":

test_markdown_writer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ def test_writes_markdown_file_with_non_hidden_columns_only(self):
313313
labels=["label1"],
314314
search_query="repo:user/repo is:issue",
315315
hide_label_metrics=True,
316+
hide_items_closed_count=True,
316317
)
317318

318319
# Check that the function writes the correct markdown file
@@ -323,7 +324,6 @@ def test_writes_markdown_file_with_non_hidden_columns_only(self):
323324
"| Metric | Count |\n"
324325
"| --- | ---: |\n"
325326
"| Number of items that remain open | 2 |\n"
326-
"| Number of items closed | 1 |\n"
327327
"| Number of most active mentors | 5 |\n"
328328
"| Total number of items created | 2 |\n\n"
329329
"| Title | URL | Author |\n"

0 commit comments

Comments
 (0)