Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ This action can be configured to authenticate with GitHub App Installation or Pe
| `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. |
| `HIDE_TIME_TO_CLOSE` | False | False | If set to `true`, the time to close will not be displayed in the generated Markdown file. |
| `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. |
| `HIDE_CREATED_AT` | False | True | If set to `true`, the creation timestmap will not be displayed in the generated Markdown file. |
| `HIDE_STATUS` | False | True | If set to `true`, the status column will not be shown |
| `HIDE_CREATED_AT` | False | True | If set to `true`, the creation timestamp will not be displayed in the generated Markdown file. |
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HIDE_CREATED_AT is not related to this change. I just noticed it wasn't properly documented.

| `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. |
| `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. |
| `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 |
Expand Down
3 changes: 3 additions & 0 deletions classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class IssueWithMetrics:
label_metrics (dict, optional): A dictionary containing the label metrics
mentor_activity (dict, optional): A dictionary containing active mentors
created_at (datetime, optional): The time the issue was created.
status (str, optional): The status of the issue, e.g., "open", "closed as completed",
"""

# pylint: disable=too-many-instance-attributes
Expand All @@ -42,6 +43,7 @@ def __init__(
created_at=None,
assignee=None,
assignees=None,
status=None,
):
self.title = title
self.html_url = html_url
Expand All @@ -55,3 +57,4 @@ def __init__(
self.label_metrics = labels_metrics
self.mentor_activity = mentor_activity
self.created_at = created_at
self.status = status
7 changes: 7 additions & 0 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class EnvVars:
hide_time_to_close (bool): If true, the time to close metric is hidden in the output
hide_time_to_first_response (bool): If true, the time to first response metric is hidden
in the output
hide_created_at (bool): If true, the created at timestamp is hidden in the output
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hide_created_at is not related to this change. I just noticed it wasn't properly documented.

hide_status (bool): If true, the status column is hidden in the output
ignore_users (List[str]): List of usernames to ignore when calculating metrics
labels_to_measure (List[str]): List of labels to measure how much time the label is applied
enable_mentor_count (bool): If set to TRUE, compute number of mentors
Expand Down Expand Up @@ -73,6 +75,7 @@ def __init__(
hide_time_to_close: bool,
hide_time_to_first_response: bool,
hide_created_at: bool,
hide_status: bool,
ignore_user: List[str],
labels_to_measure: List[str],
enable_mentor_count: bool,
Expand Down Expand Up @@ -102,6 +105,7 @@ def __init__(
self.hide_time_to_close = hide_time_to_close
self.hide_time_to_first_response = hide_time_to_first_response
self.hide_created_at = hide_created_at
self.hide_status = hide_status
self.enable_mentor_count = enable_mentor_count
self.min_mentor_comments = min_mentor_comments
self.max_comments_eval = max_comments_eval
Expand Down Expand Up @@ -130,6 +134,7 @@ def __repr__(self):
f"{self.hide_time_to_close},"
f"{self.hide_time_to_first_response},"
f"{self.hide_created_at},"
f"{self.hide_status},"
f"{self.ignore_users},"
f"{self.labels_to_measure},"
f"{self.enable_mentor_count},"
Expand Down Expand Up @@ -238,6 +243,7 @@ def get_env_vars(test: bool = False) -> EnvVars:
hide_time_to_close = get_bool_env_var("HIDE_TIME_TO_CLOSE", False)
hide_time_to_first_response = get_bool_env_var("HIDE_TIME_TO_FIRST_RESPONSE", False)
hide_created_at = get_bool_env_var("HIDE_CREATED_AT", True)
hide_status = get_bool_env_var("HIDE_STATUS", True)
enable_mentor_count = get_bool_env_var("ENABLE_MENTOR_COUNT", False)
min_mentor_comments = os.getenv("MIN_MENTOR_COMMENTS", "10")
max_comments_eval = os.getenv("MAX_COMMENTS_EVAL", "20")
Expand All @@ -259,6 +265,7 @@ def get_env_vars(test: bool = False) -> EnvVars:
hide_time_to_close,
hide_time_to_first_response,
hide_created_at,
hide_status,
ignore_users_list,
labels_to_measure_list,
enable_mentor_count,
Expand Down
4 changes: 4 additions & 0 deletions issue_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,12 @@ def get_per_issue_metrics(
issue_with_metrics.time_to_close = measure_time_to_close(
issue, None
)
if env_vars.hide_status is False:
issue_with_metrics.status = f"{issue.issue.state} as {issue.issue.state_reason}" # type: ignore
elif issue.state == "open": # type: ignore
num_issues_open += 1
if env_vars.hide_status is False:
issue_with_metrics.status = f"{issue.issue.state}" # type: ignore
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

open issues don't have a state_reason

if not env_vars.hide_created_at:
if isinstance(issue, github3.search.IssueSearchResult): # type: ignore
issue_with_metrics.created_at = issue.issue.created_at # type: ignore
Expand Down
8 changes: 8 additions & 0 deletions markdown_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ def get_non_hidden_columns(labels) -> List[str]:
if not hide_time_to_answer:
columns.append("Time to answer")

hide_status = env_vars.hide_status
if not hide_status:
columns.append("Status")

enable_time_in_draft = env_vars.draft_pr_tracking
if enable_time_in_draft:
columns.append("Time in draft")
Expand Down Expand Up @@ -232,6 +236,8 @@ def write_to_markdown(
file.write(f" {issue.label_metrics[label]} |")
if "Created At" in columns:
file.write(f" {issue.created_at} |")
if "Status" in columns:
file.write(f" {issue.status} |")
file.write("\n")
file.write(
"\n_This report was generated with the \
Expand Down Expand Up @@ -324,6 +330,8 @@ def write_overall_metrics_tables(
f"| {stats_time_in_labels['med'][label]} "
f"| {stats_time_in_labels['90p'][label]} |\n"
)
if "Status" in columns: # Add logic for the 'status' column
file.write("| Status | | | |\n")

file.write("\n")
# Write count stats to a separate table
Expand Down
28 changes: 28 additions & 0 deletions test_assignee_functionality.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,34 @@ def test_get_non_hidden_columns_hides_both_assignee_and_author(self):
self.assertNotIn("Assignee", columns)
self.assertNotIn("Author", columns)

@patch.dict(
os.environ,
{
"GH_TOKEN": "test_token",
"SEARCH_QUERY": "is:issue is:open repo:user/repo",
"HIDE_STATUS": "false",
},
clear=True,
)
def test_get_non_hidden_columns_includes_status_by_default(self):
"""Test that status column is included by default."""
columns = get_non_hidden_columns(labels=None)
self.assertIn("Status", columns)

@patch.dict(
os.environ,
{
"GH_TOKEN": "test_token",
"SEARCH_QUERY": "is:issue is:open repo:user/repo",
"HIDE_STATUS": "true",
},
clear=True,
)
def test_get_non_hidden_columns_hides_status_when_env_set(self):
"""Test that status column is hidden when HIDE_STATUS is true."""
columns = get_non_hidden_columns(labels=None)
self.assertNotIn("Status", columns)

def test_assignee_column_position(self):
"""Test that assignee column appears before author column."""
with patch.dict(
Expand Down
4 changes: 4 additions & 0 deletions test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ def test_get_env_vars_with_github_app(self):
hide_time_to_close=False,
hide_time_to_first_response=False,
hide_created_at=True,
hide_status=True,
ignore_user=[],
labels_to_measure=[],
enable_mentor_count=False,
Expand Down Expand Up @@ -186,6 +187,7 @@ def test_get_env_vars_with_token(self):
hide_time_to_close=False,
hide_time_to_first_response=False,
hide_created_at=True,
hide_status=True,
ignore_user=[],
labels_to_measure=[],
enable_mentor_count=False,
Expand Down Expand Up @@ -276,6 +278,7 @@ def test_get_env_vars_optional_values(self):
hide_time_to_close=True,
hide_time_to_first_response=True,
hide_created_at=True,
hide_status=True,
ignore_user=[],
labels_to_measure=["waiting-for-review", "waiting-for-manager"],
enable_mentor_count=False,
Expand Down Expand Up @@ -320,6 +323,7 @@ def test_get_env_vars_optionals_are_defaulted(self):
hide_time_to_close=False,
hide_time_to_first_response=False,
hide_created_at=True,
hide_status=True,
ignore_user=[],
labels_to_measure=[],
enable_mentor_count=False,
Expand Down
Loading
Loading