Skip to content

Commit f5c0d3b

Browse files
authored
Merge pull request #553 from github/status-column
feat: Status column
2 parents 7112261 + 543e100 commit f5c0d3b

File tree

8 files changed

+185
-12
lines changed

8 files changed

+185
-12
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,8 @@ This action can be configured to authenticate with GitHub App Installation or Pe
154154
| `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. |
155155
| `HIDE_TIME_TO_CLOSE` | False | False | If set to `true`, the time to close will not be displayed in the generated Markdown file. |
156156
| `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. |
157-
| `HIDE_CREATED_AT` | False | True | If set to `true`, the creation timestmap will not be displayed in the generated Markdown file. |
157+
| `HIDE_STATUS` | False | True | If set to `true`, the status column will not be shown |
158+
| `HIDE_CREATED_AT` | False | True | If set to `true`, the creation timestamp will not be displayed in the generated Markdown file. |
158159
| `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. |
159160
| `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. |
160161
| `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 |

classes.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class IssueWithMetrics:
2424
label_metrics (dict, optional): A dictionary containing the label metrics
2525
mentor_activity (dict, optional): A dictionary containing active mentors
2626
created_at (datetime, optional): The time the issue was created.
27+
status (str, optional): The status of the issue, e.g., "open", "closed as completed",
2728
"""
2829

2930
# pylint: disable=too-many-instance-attributes
@@ -42,6 +43,7 @@ def __init__(
4243
created_at=None,
4344
assignee=None,
4445
assignees=None,
46+
status=None,
4547
):
4648
self.title = title
4749
self.html_url = html_url
@@ -55,3 +57,4 @@ def __init__(
5557
self.label_metrics = labels_metrics
5658
self.mentor_activity = mentor_activity
5759
self.created_at = created_at
60+
self.status = status

config.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ class EnvVars:
3939
hide_time_to_close (bool): If true, the time to close metric is hidden in the output
4040
hide_time_to_first_response (bool): If true, the time to first response metric is hidden
4141
in the output
42+
hide_created_at (bool): If true, the created at timestamp is hidden in the output
43+
hide_status (bool): If true, the status column is hidden in the output
4244
ignore_users (List[str]): List of usernames to ignore when calculating metrics
4345
labels_to_measure (List[str]): List of labels to measure how much time the label is applied
4446
enable_mentor_count (bool): If set to TRUE, compute number of mentors
@@ -73,6 +75,7 @@ def __init__(
7375
hide_time_to_close: bool,
7476
hide_time_to_first_response: bool,
7577
hide_created_at: bool,
78+
hide_status: bool,
7679
ignore_user: List[str],
7780
labels_to_measure: List[str],
7881
enable_mentor_count: bool,
@@ -102,6 +105,7 @@ def __init__(
102105
self.hide_time_to_close = hide_time_to_close
103106
self.hide_time_to_first_response = hide_time_to_first_response
104107
self.hide_created_at = hide_created_at
108+
self.hide_status = hide_status
105109
self.enable_mentor_count = enable_mentor_count
106110
self.min_mentor_comments = min_mentor_comments
107111
self.max_comments_eval = max_comments_eval
@@ -130,6 +134,7 @@ def __repr__(self):
130134
f"{self.hide_time_to_close},"
131135
f"{self.hide_time_to_first_response},"
132136
f"{self.hide_created_at},"
137+
f"{self.hide_status},"
133138
f"{self.ignore_users},"
134139
f"{self.labels_to_measure},"
135140
f"{self.enable_mentor_count},"
@@ -238,6 +243,7 @@ def get_env_vars(test: bool = False) -> EnvVars:
238243
hide_time_to_close = get_bool_env_var("HIDE_TIME_TO_CLOSE", False)
239244
hide_time_to_first_response = get_bool_env_var("HIDE_TIME_TO_FIRST_RESPONSE", False)
240245
hide_created_at = get_bool_env_var("HIDE_CREATED_AT", True)
246+
hide_status = get_bool_env_var("HIDE_STATUS", True)
241247
enable_mentor_count = get_bool_env_var("ENABLE_MENTOR_COUNT", False)
242248
min_mentor_comments = os.getenv("MIN_MENTOR_COMMENTS", "10")
243249
max_comments_eval = os.getenv("MAX_COMMENTS_EVAL", "20")
@@ -259,6 +265,7 @@ def get_env_vars(test: bool = False) -> EnvVars:
259265
hide_time_to_close,
260266
hide_time_to_first_response,
261267
hide_created_at,
268+
hide_status,
262269
ignore_users_list,
263270
labels_to_measure_list,
264271
enable_mentor_count,

issue_metrics.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,12 @@ def get_per_issue_metrics(
175175
issue_with_metrics.time_to_close = measure_time_to_close(
176176
issue, None
177177
)
178+
if not env_vars.hide_status:
179+
issue_with_metrics.status = f"{issue.issue.state} as {issue.issue.state_reason}" # type: ignore
178180
elif issue.state == "open": # type: ignore
179181
num_issues_open += 1
182+
if not env_vars.hide_status:
183+
issue_with_metrics.status = f"{issue.issue.state}" # type: ignore
180184
if not env_vars.hide_created_at:
181185
if isinstance(issue, github3.search.IssueSearchResult): # type: ignore
182186
issue_with_metrics.created_at = issue.issue.created_at # type: ignore

markdown_writer.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ def get_non_hidden_columns(labels) -> List[str]:
7575
if not hide_time_to_answer:
7676
columns.append("Time to answer")
7777

78+
hide_status = env_vars.hide_status
79+
if not hide_status:
80+
columns.append("Status")
81+
7882
enable_time_in_draft = env_vars.draft_pr_tracking
7983
if enable_time_in_draft:
8084
columns.append("Time in draft")
@@ -232,6 +236,8 @@ def write_to_markdown(
232236
file.write(f" {issue.label_metrics[label]} |")
233237
if "Created At" in columns:
234238
file.write(f" {issue.created_at} |")
239+
if "Status" in columns:
240+
file.write(f" {issue.status} |")
235241
file.write("\n")
236242
file.write(
237243
"\n_This report was generated with the \
@@ -324,6 +330,8 @@ def write_overall_metrics_tables(
324330
f"| {stats_time_in_labels['med'][label]} "
325331
f"| {stats_time_in_labels['90p'][label]} |\n"
326332
)
333+
if "Status" in columns: # Add logic for the 'status' column
334+
file.write("| Status | | | |\n")
327335

328336
file.write("\n")
329337
# Write count stats to a separate table

test_assignee_functionality.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,34 @@ def test_get_non_hidden_columns_hides_both_assignee_and_author(self):
7575
self.assertNotIn("Assignee", columns)
7676
self.assertNotIn("Author", columns)
7777

78+
@patch.dict(
79+
os.environ,
80+
{
81+
"GH_TOKEN": "test_token",
82+
"SEARCH_QUERY": "is:issue is:open repo:user/repo",
83+
"HIDE_STATUS": "false",
84+
},
85+
clear=True,
86+
)
87+
def test_get_non_hidden_columns_includes_status_by_default(self):
88+
"""Test that status column is included by default."""
89+
columns = get_non_hidden_columns(labels=None)
90+
self.assertIn("Status", columns)
91+
92+
@patch.dict(
93+
os.environ,
94+
{
95+
"GH_TOKEN": "test_token",
96+
"SEARCH_QUERY": "is:issue is:open repo:user/repo",
97+
"HIDE_STATUS": "true",
98+
},
99+
clear=True,
100+
)
101+
def test_get_non_hidden_columns_hides_status_when_env_set(self):
102+
"""Test that status column is hidden when HIDE_STATUS is true."""
103+
columns = get_non_hidden_columns(labels=None)
104+
self.assertNotIn("Status", columns)
105+
78106
def test_assignee_column_position(self):
79107
"""Test that assignee column appears before author column."""
80108
with patch.dict(

test_config.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ def test_get_env_vars_with_github_app(self):
131131
hide_time_to_close=False,
132132
hide_time_to_first_response=False,
133133
hide_created_at=True,
134+
hide_status=True,
134135
ignore_user=[],
135136
labels_to_measure=[],
136137
enable_mentor_count=False,
@@ -186,6 +187,7 @@ def test_get_env_vars_with_token(self):
186187
hide_time_to_close=False,
187188
hide_time_to_first_response=False,
188189
hide_created_at=True,
190+
hide_status=True,
189191
ignore_user=[],
190192
labels_to_measure=[],
191193
enable_mentor_count=False,
@@ -276,6 +278,7 @@ def test_get_env_vars_optional_values(self):
276278
hide_time_to_close=True,
277279
hide_time_to_first_response=True,
278280
hide_created_at=True,
281+
hide_status=True,
279282
ignore_user=[],
280283
labels_to_measure=["waiting-for-review", "waiting-for-manager"],
281284
enable_mentor_count=False,
@@ -320,6 +323,7 @@ def test_get_env_vars_optionals_are_defaulted(self):
320323
hide_time_to_close=False,
321324
hide_time_to_first_response=False,
322325
hide_created_at=True,
326+
hide_status=True,
323327
ignore_user=[],
324328
labels_to_measure=[],
325329
enable_mentor_count=False,

0 commit comments

Comments
 (0)