Skip to content

Commit

Permalink
fix: Remove ignore_users authored items from markdown results
Browse files Browse the repository at this point in the history
Signed-off-by: Zack Koppert <[email protected]>
  • Loading branch information
zkoppert committed Sep 24, 2024
1 parent c2911b8 commit ce411c0
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ 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. |
| `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]'`) |
| `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 |
| `MIN_MENTOR_COMMENTS` | False | 10 | Minimum number of comments to count as a mentor |
| `MAX_COMMENTS_EVAL` | False | 20 | Maximum number of comments per thread to evaluate for mentor stats |
Expand Down
3 changes: 3 additions & 0 deletions issue_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,9 @@ def get_per_issue_metrics(
else:
num_issues_open += 1
else:
if ignore_users and issue.user["login"] in ignore_users: # type: ignore
continue

issue_with_metrics = IssueWithMetrics(
issue.title, # type: ignore
issue.html_url, # type: ignore
Expand Down
96 changes: 92 additions & 4 deletions test_issue_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def test_get_per_issue_metrics_with_hide_envs(self):
mock_issue1 = MagicMock(
title="Issue 1",
html_url="https://github.com/user/repo/issues/1",
author="alice",
user={"login": "alice"},
state="open",
comments=1,
created_at="2023-01-01T00:00:00Z",
Expand All @@ -209,7 +209,7 @@ def test_get_per_issue_metrics_with_hide_envs(self):
mock_issue2 = MagicMock(
title="Issue 2",
html_url="https://github.com/user/repo/issues/2",
author="bob",
user={"login": "bob"},
state="closed",
comments=1,
created_at="2023-01-01T00:00:00Z",
Expand Down Expand Up @@ -304,7 +304,7 @@ def test_get_per_issue_metrics_without_hide_envs(self):
mock_issue1 = MagicMock(
title="Issue 1",
html_url="https://github.com/user/repo/issues/1",
author="alice",
user={"login": "alice"},
state="open",
comments=1,
created_at="2023-01-01T00:00:00Z",
Expand All @@ -318,7 +318,7 @@ def test_get_per_issue_metrics_without_hide_envs(self):
mock_issue2 = MagicMock(
title="Issue 2",
html_url="https://github.com/user/repo/issues/2",
author="bob",
user={"login": "bob"},
state="closed",
comments=1,
created_at="2023-01-01T00:00:00Z",
Expand Down Expand Up @@ -391,6 +391,94 @@ def test_get_per_issue_metrics_without_hide_envs(self):
expected_issues_with_metrics[1].time_to_close,
)

@patch.dict(
os.environ,
{
"GH_TOKEN": "test_token",
"SEARCH_QUERY": "is:issue is:open repo:user/repo",
"IGNORE_USERS": "alice",
},
)
def test_get_per_issue_metrics_with_ignore_users(self):
"""
Test that the function correctly filters out issues with authors in the IGNORE_USERS variable
"""

# Create mock data
mock_issue1 = MagicMock(
title="Issue 1",
html_url="https://github.com/user/repo/issues/1",
user={"login": "alice"},
state="open",
comments=1,
created_at="2023-01-01T00:00:00Z",
)

mock_comment1 = MagicMock()
mock_comment1.created_at = datetime.fromisoformat("2023-01-02T00:00:00Z")
mock_issue1.issue.comments.return_value = [mock_comment1]
mock_issue1.issue.pull_request_urls = None

mock_issue2 = MagicMock(
title="Issue 2",
html_url="https://github.com/user/repo/issues/2",
user={"login": "bob"},
state="closed",
comments=1,
created_at="2023-01-01T00:00:00Z",
closed_at="2023-01-04T00:00:00Z",
)

mock_comment2 = MagicMock()
mock_comment2.created_at = datetime.fromisoformat("2023-01-03T00:00:00Z")
mock_issue2.issue.comments.return_value = [mock_comment2]
mock_issue2.issue.pull_request_urls = None

issues = [
mock_issue1,
mock_issue2,
]

# Call the function and check the result
with unittest.mock.patch( # type:ignore
"issue_metrics.measure_time_to_first_response",
measure_time_to_first_response,
), unittest.mock.patch( # type:ignore
"issue_metrics.measure_time_to_close", measure_time_to_close
):
(
result_issues_with_metrics,
result_num_issues_open,
result_num_issues_closed,
) = get_per_issue_metrics(
issues,
env_vars=get_env_vars(test=True),
ignore_users=["alice"],
)
expected_issues_with_metrics = [
IssueWithMetrics(
"Issue 2",
"https://github.com/user/repo/issues/2",
"bob",
timedelta(days=2),
timedelta(days=3),
None,
None,
),
]
expected_num_issues_open = 0
expected_num_issues_closed = 1
self.assertEqual(result_num_issues_open, expected_num_issues_open)
self.assertEqual(result_num_issues_closed, expected_num_issues_closed)
self.assertEqual(
result_issues_with_metrics[0].time_to_first_response,
expected_issues_with_metrics[0].time_to_first_response,
)
self.assertEqual(
result_issues_with_metrics[0].time_to_close,
expected_issues_with_metrics[0].time_to_close,
)


class TestDiscussionMetrics(unittest.TestCase):
"""Test suite for the discussion_metrics function."""
Expand Down

0 comments on commit ce411c0

Please sign in to comment.