Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add option to hide Number of items closed metric #313

Merged
merged 3 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions .env-example
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ GH_APP_PRIVATE_KEY=""
GH_ENTERPRISE_URL = ""
GH_TOKEN = ""
HIDE_AUTHOR = "false"
HIDE_ITEMS_CLOSED_COUNT="false"
HIDE_LABEL_METRICS = "false"
HIDE_TIME_TO_ANSWER = "false"
HIDE_TIME_TO_CLOSE = "false"
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ This action can be configured to authenticate with GitHub App Installation or Pe
|-------------------------------|----------|---------|-------------|
| `GH_ENTERPRISE_URL` | False | `""` | URL of GitHub Enterprise instance to use for auth instead of github.com |
| `HIDE_AUTHOR` | False | False | If set to `true`, the author will not be displayed in the generated Markdown file. |
| `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. |
| `HIDE_LABEL_METRICS` | False | False | If set to `true`, the time in label metrics will not be displayed in the generated Markdown file. |
| `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. |
Expand Down
8 changes: 7 additions & 1 deletion config.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class EnvVars:
gh_token (str | None): GitHub personal access token (PAT) for API authentication
ghe (str): The GitHub Enterprise URL to use for authentication
hide_author (bool): If true, the author's information is hidden in the output
hide_items_closed_count (bool): If true, the number of items closed metric is hidden in the output
hide_label_metrics (bool): If true, the label metrics are hidden in the output
hide_time_to_answer (bool): If true, the time to answer discussions is hidden in the output
hide_time_to_close (bool): If true, the time to close metric is hidden in the output
Expand All @@ -49,6 +50,7 @@ def __init__(
gh_token: str | None,
ghe: str | None,
hide_author: bool,
hide_items_closed_count: bool,
hide_label_metrics: bool,
hide_time_to_answer: bool,
hide_time_to_close: bool,
Expand All @@ -69,6 +71,7 @@ def __init__(
self.ignore_users = ignore_user
self.labels_to_measure = labels_to_measure
self.hide_author = hide_author
self.hide_items_closed_count = hide_items_closed_count
self.hide_label_metrics = hide_label_metrics
self.hide_time_to_answer = hide_time_to_answer
self.hide_time_to_close = hide_time_to_close
Expand All @@ -88,6 +91,7 @@ def __repr__(self):
f"{self.gh_token},"
f"{self.ghe},"
f"{self.hide_author},"
f"{self.hide_items_closed_count}),"
f"{self.hide_label_metrics},"
f"{self.hide_time_to_answer},"
f"{self.hide_time_to_close},"
Expand All @@ -98,7 +102,7 @@ def __repr__(self):
f"{self.min_mentor_comments},"
f"{self.max_comments_eval},"
f"{self.heavily_involved_cutoff},"
f"{self.search_query})"
f"{self.search_query}"
)


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

# Hidden columns
hide_author = get_bool_env_var("HIDE_AUTHOR", False)
hide_items_closed_count = get_bool_env_var("HIDE_ITEMS_CLOSED_COUNT", False)
hide_label_metrics = get_bool_env_var("HIDE_LABEL_METRICS", False)
hide_time_to_answer = get_bool_env_var("HIDE_TIME_TO_ANSWER", False)
hide_time_to_close = get_bool_env_var("HIDE_TIME_TO_CLOSE", False)
Expand All @@ -198,6 +203,7 @@ def get_env_vars(test: bool = False) -> EnvVars:
gh_token,
ghe,
hide_author,
hide_items_closed_count,
hide_label_metrics,
hide_time_to_answer,
hide_time_to_close,
Expand Down
2 changes: 2 additions & 0 deletions issue_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ def main():
search_query = env_vars.search_query
token = env_vars.gh_token
ignore_users = env_vars.ignore_users
hide_items_closed_count = env_vars.hide_items_closed_count

gh_app_id = env_vars.gh_app_id
gh_app_installation_id = env_vars.gh_app_installation_id
Expand Down Expand Up @@ -412,6 +413,7 @@ def main():
num_mentor_count,
labels,
search_query,
hide_items_closed_count,
)

max_char_count = 65535
Expand Down
7 changes: 6 additions & 1 deletion markdown_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ def write_to_markdown(
labels=None,
search_query=None,
hide_label_metrics=False,
hide_items_closed_count=False,
) -> None:
"""Write the issues with metrics to a markdown file.

Expand All @@ -102,6 +103,7 @@ def write_to_markdown(
labels (List[str]): A list of the labels that are used in the issues.
search_query (str): The search query used to find the issues.
hide_label_metrics (bool): Represents whether the user has chosen to hide label metrics in the output
hide_items_closed_count (bool): Represents whether the user has chosen to hide the number of items closed

Returns:
None.
Expand Down Expand Up @@ -135,6 +137,7 @@ def write_to_markdown(
columns,
file,
hide_label_metrics,
hide_items_closed_count,
)

# Write second table with individual issue/pr/discussion metrics
Expand Down Expand Up @@ -193,6 +196,7 @@ def write_overall_metrics_tables(
columns,
file,
hide_label_metrics,
hide_items_closed_count=False,
):
"""Write the overall metrics tables to the markdown file."""
if (
Expand Down Expand Up @@ -250,6 +254,7 @@ def write_overall_metrics_tables(
file.write("| Metric | Count |\n")
file.write("| --- | ---: |\n")
file.write(f"| Number of items that remain open | {num_issues_opened} |\n")
file.write(f"| Number of items closed | {num_issues_closed} |\n")
if not hide_items_closed_count:
file.write(f"| Number of items closed | {num_issues_closed} |\n")
file.write(f"| Number of most active mentors | {num_mentor_count} |\n")
file.write(f"| Total number of items created | {len(issues_with_metrics)} |\n\n")
89 changes: 67 additions & 22 deletions test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def setUp(self):
"GH_TOKEN",
"GHE",
"HIDE_AUTHOR",
"HIDE_ITEMS_CLOSED_COUNT",
"HIDE_LABEL_METRICS",
"HIDE_TIME_TO_ANSWER",
"HIDE_TIME_TO_CLOSE",
Expand All @@ -93,6 +94,7 @@ def setUp(self):
"GH_TOKEN": "",
"GH_ENTERPRISE_URL": "",
"HIDE_AUTHOR": "",
"HIDE_ITEMS_CLOSED_COUNT": "false",
"HIDE_LABEL_METRICS": "",
"HIDE_TIME_TO_ANSWER": "",
"HIDE_TIME_TO_CLOSE": "",
Expand All @@ -116,6 +118,7 @@ def test_get_env_vars_with_github_app(self):
False,
False,
False,
False,
[],
[],
False,
Expand All @@ -136,6 +139,7 @@ def test_get_env_vars_with_github_app(self):
"GH_ENTERPRISE_URL": "",
"GH_TOKEN": TOKEN,
"HIDE_AUTHOR": "",
"HIDE_ITEMS_CLOSED_COUNT": "false",
"HIDE_LABEL_METRICS": "",
"HIDE_TIME_TO_ANSWER": "",
"HIDE_TIME_TO_CLOSE": "",
Expand All @@ -159,6 +163,7 @@ def test_get_env_vars_with_token(self):
False,
False,
False,
False,
[],
[],
False,
Expand All @@ -170,6 +175,41 @@ def test_get_env_vars_with_token(self):
result = get_env_vars(True)
self.assertEqual(str(result), str(expected_result))

@patch.dict(
os.environ,
{
"GH_APP_ID": "",
"GH_APP_INSTALLATION_ID": "",
"GH_APP_PRIVATE_KEY": "",
"GH_TOKEN": "",
"SEARCH_QUERY": SEARCH_QUERY,
"HIDE_ITEMS_CLOSED_COUNT": "false",
},
clear=True,
)
def test_get_env_vars_missing_token(self):
"""Test that an error is raised if the TOKEN environment variables is not set"""
with self.assertRaises(ValueError):
get_env_vars(True)

@patch.dict(
os.environ,
{
"GH_APP_ID": "",
"GH_APP_INSTALLATION_ID": "",
"GH_APP_PRIVATE_KEY": "",
"GH_TOKEN": TOKEN,
"SEARCH_QUERY": "",
"HIDE_ITEMS_CLOSED_COUNT": "false",
},
clear=True,
)
def test_get_env_vars_missing_query(self):
"""Test that an error is raised if the SEARCH_QUERY environment variable is not set."""

with self.assertRaises(ValueError):
get_env_vars(True)

@patch.dict(
os.environ,
{
Expand All @@ -179,6 +219,7 @@ def test_get_env_vars_with_token(self):
"GH_TOKEN": TOKEN,
"GH_ENTERPRISE_URL": "",
"HIDE_AUTHOR": "true",
"HIDE_ITEMS_CLOSED_COUNT": "true",
"HIDE_LABEL_METRICS": "true",
"HIDE_TIME_TO_ANSWER": "true",
"HIDE_TIME_TO_CLOSE": "true",
Expand All @@ -201,6 +242,7 @@ def test_get_env_vars_optional_values(self):
True,
True,
True,
True,
[],
["waiting-for-review", "waiting-for-manager"],
False,
Expand All @@ -218,32 +260,35 @@ def test_get_env_vars_optional_values(self):
"GH_APP_ID": "",
"GH_APP_INSTALLATION_ID": "",
"GH_APP_PRIVATE_KEY": "",
"GH_TOKEN": "",
"GH_TOKEN": "TOKEN",
"SEARCH_QUERY": SEARCH_QUERY,
},
clear=True,
)
def test_get_env_vars_missing_token(self):
"""Test that an error is raised if the TOKEN environment variables is not set"""
with self.assertRaises(ValueError):
get_env_vars(True)

@patch.dict(
os.environ,
{
"GH_APP_ID": "",
"GH_APP_INSTALLATION_ID": "",
"GH_APP_PRIVATE_KEY": "",
"GH_TOKEN": TOKEN,
"SEARCH_QUERY": "",
},
clear=True,
)
def test_get_env_vars_missing_query(self):
"""Test that an error is raised if the SEARCH_QUERY environment variable is not set."""

with self.assertRaises(ValueError):
get_env_vars(True)
def test_get_env_vars_optionals_are_defaulted(self):
"""Test that optional values are set to their default values if not provided"""
expected_result = EnvVars(
None,
None,
b"",
"TOKEN",
"",
False,
False,
False,
False,
False,
False,
[],
[],
False,
"10",
"20",
"3",
SEARCH_QUERY,
)
result = get_env_vars(True)
self.assertEqual(str(result), str(expected_result))


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion test_markdown_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ def test_writes_markdown_file_with_non_hidden_columns_only(self):
labels=["label1"],
search_query="repo:user/repo is:issue",
hide_label_metrics=True,
hide_items_closed_count=True,
)

# Check that the function writes the correct markdown file
Expand All @@ -323,7 +324,6 @@ def test_writes_markdown_file_with_non_hidden_columns_only(self):
"| Metric | Count |\n"
"| --- | ---: |\n"
"| Number of items that remain open | 2 |\n"
"| Number of items closed | 2 |\n"
"| Number of most active mentors | 5 |\n"
"| Total number of items created | 2 |\n\n"
"| Title | URL | Author |\n"
Expand Down