Skip to content

Commit cbd995c

Browse files
authored
Merge pull request #460 from Chocrates/created_at
feat: Adding 'Created_At' column, defaulting to false
2 parents 7d6c495 + ad3c5e1 commit cbd995c

File tree

7 files changed

+22
-2
lines changed

7 files changed

+22
-2
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ This action can be configured to authenticate with GitHub App Installation or Pe
153153
| `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. |
154154
| `HIDE_TIME_TO_CLOSE` | False | False | If set to `true`, the time to close will not be displayed in the generated Markdown file. |
155155
| `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. |
156+
| `HIDE_CREATED_AT` | False | True | If set to `true`, the creation timestmap will not be displayed in the generated Markdown file. |
156157
| `DRAFT_PR_TRACKING` | False | False | If set to `true`, draft PRs will be included in the metrics as a new column and in the summary stats. |
157158
| `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]'`) Users in this list will also have their authored issues and pull requests removed from the Markdown table. |
158159
| `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 |

auth.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def get_github_app_installation_token(
5959
) -> str | None:
6060
"""
6161
Get a GitHub App Installation token.
62-
API: https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/authenticating-as-a-github-app-installation
62+
API: https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/authenticating-as-a-github-app-installation # noqa: E501
6363
6464
Args:
6565
ghe (str): the GitHub Enterprise endpoint

classes.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class IssueWithMetrics:
2121
time_in_draft (timedelta, optional): The time the PR was in draft state.
2222
label_metrics (dict, optional): A dictionary containing the label metrics
2323
mentor_activity (dict, optional): A dictionary containing active mentors
24-
24+
created_at (datetime, optional): The time the issue was created.
2525
"""
2626

2727
# pylint: disable=too-many-instance-attributes
@@ -37,6 +37,7 @@ def __init__(
3737
time_in_draft=None,
3838
labels_metrics=None,
3939
mentor_activity=None,
40+
created_at=None,
4041
):
4142
self.title = title
4243
self.html_url = html_url
@@ -47,3 +48,4 @@ def __init__(
4748
self.time_in_draft = time_in_draft
4849
self.label_metrics = labels_metrics
4950
self.mentor_activity = mentor_activity
51+
self.created_at = created_at

config.py

+5
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ def __init__(
7070
hide_time_to_answer: bool,
7171
hide_time_to_close: bool,
7272
hide_time_to_first_response: bool,
73+
hide_created_at: bool,
7374
ignore_user: List[str],
7475
labels_to_measure: List[str],
7576
enable_mentor_count: bool,
@@ -97,6 +98,7 @@ def __init__(
9798
self.hide_time_to_answer = hide_time_to_answer
9899
self.hide_time_to_close = hide_time_to_close
99100
self.hide_time_to_first_response = hide_time_to_first_response
101+
self.hide_created_at = hide_created_at
100102
self.enable_mentor_count = enable_mentor_count
101103
self.min_mentor_comments = min_mentor_comments
102104
self.max_comments_eval = max_comments_eval
@@ -123,6 +125,7 @@ def __repr__(self):
123125
f"{self.hide_time_to_answer},"
124126
f"{self.hide_time_to_close},"
125127
f"{self.hide_time_to_first_response},"
128+
f"{self.hide_created_at},"
126129
f"{self.ignore_users},"
127130
f"{self.labels_to_measure},"
128131
f"{self.enable_mentor_count},"
@@ -229,6 +232,7 @@ def get_env_vars(test: bool = False) -> EnvVars:
229232
hide_time_to_answer = get_bool_env_var("HIDE_TIME_TO_ANSWER", False)
230233
hide_time_to_close = get_bool_env_var("HIDE_TIME_TO_CLOSE", False)
231234
hide_time_to_first_response = get_bool_env_var("HIDE_TIME_TO_FIRST_RESPONSE", False)
235+
hide_created_at = get_bool_env_var("HIDE_CREATED_AT", True)
232236
enable_mentor_count = get_bool_env_var("ENABLE_MENTOR_COUNT", False)
233237
min_mentor_comments = os.getenv("MIN_MENTOR_COMMENTS", "10")
234238
max_comments_eval = os.getenv("MAX_COMMENTS_EVAL", "20")
@@ -248,6 +252,7 @@ def get_env_vars(test: bool = False) -> EnvVars:
248252
hide_time_to_answer,
249253
hide_time_to_close,
250254
hide_time_to_first_response,
255+
hide_created_at,
251256
ignore_users_list,
252257
labels_to_measure_list,
253258
enable_mentor_count,

issue_metrics.py

+2
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@ def get_per_issue_metrics(
159159
)
160160
elif issue.state == "open": # type: ignore
161161
num_issues_open += 1
162+
if not env_vars.hide_created_at:
163+
issue_with_metrics.created_at = issue["createdAt"]
162164
issues_with_metrics.append(issue_with_metrics)
163165

164166
return issues_with_metrics, num_issues_open, num_issues_closed

markdown_writer.py

+6
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ def get_non_hidden_columns(labels) -> List[str]:
7979
if not hide_label_metrics and labels:
8080
for label in labels:
8181
columns.append(f"Time spent in {label}")
82+
hide_created_at = env_vars.hide_created_at
83+
if not hide_created_at:
84+
columns.append("Created At")
8285

8386
return columns
8487

@@ -212,6 +215,8 @@ def write_to_markdown(
212215
for label in labels:
213216
if f"Time spent in {label}" in columns:
214217
file.write(f" {issue.label_metrics[label]} |")
218+
if "Created At" in columns:
219+
file.write(f" {issue.created_at} |")
215220
file.write("\n")
216221
file.write(
217222
"\n_This report was generated with the \
@@ -303,6 +308,7 @@ def write_overall_metrics_tables(
303308
f"| {stats_time_in_labels['med'][label]} "
304309
f"| {stats_time_in_labels['90p'][label]} |\n"
305310
)
311+
306312
file.write("\n")
307313
# Write count stats to a separate table
308314
file.write("| Metric | Count |\n")

test_config.py

+4
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ def test_get_env_vars_with_github_app(self):
128128
hide_time_to_answer=False,
129129
hide_time_to_close=False,
130130
hide_time_to_first_response=False,
131+
hide_created_at=True,
131132
ignore_user=[],
132133
labels_to_measure=[],
133134
enable_mentor_count=False,
@@ -181,6 +182,7 @@ def test_get_env_vars_with_token(self):
181182
hide_time_to_answer=False,
182183
hide_time_to_close=False,
183184
hide_time_to_first_response=False,
185+
hide_created_at=True,
184186
ignore_user=[],
185187
labels_to_measure=[],
186188
enable_mentor_count=False,
@@ -269,6 +271,7 @@ def test_get_env_vars_optional_values(self):
269271
hide_time_to_answer=True,
270272
hide_time_to_close=True,
271273
hide_time_to_first_response=True,
274+
hide_created_at=True,
272275
ignore_user=[],
273276
labels_to_measure=["waiting-for-review", "waiting-for-manager"],
274277
enable_mentor_count=False,
@@ -311,6 +314,7 @@ def test_get_env_vars_optionals_are_defaulted(self):
311314
hide_time_to_answer=False,
312315
hide_time_to_close=False,
313316
hide_time_to_first_response=False,
317+
hide_created_at=True,
314318
ignore_user=[],
315319
labels_to_measure=[],
316320
enable_mentor_count=False,

0 commit comments

Comments
 (0)