Skip to content

Commit 8cee549

Browse files
authored
Merge pull request #379 from github/ignored-users-in-report
fix: Remove ignore_users authored items from markdown results
2 parents c2911b8 + 04a9ee2 commit 8cee549

File tree

3 files changed

+114
-23
lines changed

3 files changed

+114
-23
lines changed

README.md

+19-19
Original file line numberDiff line numberDiff line change
@@ -139,25 +139,25 @@ This action can be configured to authenticate with GitHub App Installation or Pe
139139

140140
#### Other Configuration Options
141141

142-
| field | required | default | description |
143-
| ----------------------------- | -------- | ------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
144-
| `GH_ENTERPRISE_URL` | False | `""` | URL of GitHub Enterprise instance to use for auth instead of github.com |
145-
| `HIDE_AUTHOR` | False | False | If set to `true`, the author will not be displayed in the generated Markdown file. |
146-
| `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. |
147-
| `HIDE_LABEL_METRICS` | False | False | If set to `true`, the time in label metrics will not be displayed in the generated Markdown file. |
148-
| `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. |
149-
| `HIDE_TIME_TO_CLOSE` | False | False | If set to `true`, the time to close will not be displayed in the generated Markdown file. |
150-
| `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. |
151-
| `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]'`) |
152-
| `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 |
153-
| `MIN_MENTOR_COMMENTS` | False | 10 | Minimum number of comments to count as a mentor |
154-
| `MAX_COMMENTS_EVAL` | False | 20 | Maximum number of comments per thread to evaluate for mentor stats |
155-
| `HEAVILY_INVOLVED_CUTOFF` | False | 3 | Cutoff after which a mentor's comments in one issue are no longer counted against their total score |
156-
| `LABELS_TO_MEASURE` | False | `""` | A comma separated list of labels to measure how much time the label is applied. If not provided, no labels durations will be measured. Not compatible with discussions at this time. |
157-
| `NON_MENTIONING_LINKS` | False | False | If set to `true`, will use non-mentioning GitHub links to avoid linking to the generated issue from the source repository. Links of the form `https://www.github.com` will be used. |
158-
| `OUTPUT_FILE` | False | `issue_metrics.md` or `issue_metrics.json` | Output filename. |
159-
| `REPORT_TITLE` | False | `"Issue Metrics"` | Title to have on the report issue. |
160-
| `SEARCH_QUERY` | True | `""` | The query by which you can filter issues/PRs which must contain a `repo:`, `org:`, `owner:`, or a `user:` entry. For discussions, include `type:discussions` in the query. |
142+
| field | required | default | description |
143+
| ----------------------------- | -------- | ------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
144+
| `GH_ENTERPRISE_URL` | False | `""` | URL of GitHub Enterprise instance to use for auth instead of github.com |
145+
| `HIDE_AUTHOR` | False | False | If set to `true`, the author will not be displayed in the generated Markdown file. |
146+
| `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. |
147+
| `HIDE_LABEL_METRICS` | False | False | If set to `true`, the time in label metrics will not be displayed in the generated Markdown file. |
148+
| `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. |
149+
| `HIDE_TIME_TO_CLOSE` | False | False | If set to `true`, the time to close will not be displayed in the generated Markdown file. |
150+
| `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. |
151+
| `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. |
152+
| `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 |
153+
| `MIN_MENTOR_COMMENTS` | False | 10 | Minimum number of comments to count as a mentor |
154+
| `MAX_COMMENTS_EVAL` | False | 20 | Maximum number of comments per thread to evaluate for mentor stats |
155+
| `HEAVILY_INVOLVED_CUTOFF` | False | 3 | Cutoff after which a mentor's comments in one issue are no longer counted against their total score |
156+
| `LABELS_TO_MEASURE` | False | `""` | A comma separated list of labels to measure how much time the label is applied. If not provided, no labels durations will be measured. Not compatible with discussions at this time. |
157+
| `NON_MENTIONING_LINKS` | False | False | If set to `true`, will use non-mentioning GitHub links to avoid linking to the generated issue from the source repository. Links of the form `https://www.github.com` will be used. |
158+
| `OUTPUT_FILE` | False | `issue_metrics.md` or `issue_metrics.json` | Output filename. |
159+
| `REPORT_TITLE` | False | `"Issue Metrics"` | Title to have on the report issue. |
160+
| `SEARCH_QUERY` | True | `""` | The query by which you can filter issues/PRs which must contain a `repo:`, `org:`, `owner:`, or a `user:` entry. For discussions, include `type:discussions` in the query. |
161161

162162
## Further Documentation
163163

issue_metrics.py

+3
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,9 @@ def get_per_issue_metrics(
202202
else:
203203
num_issues_open += 1
204204
else:
205+
if ignore_users and issue.user["login"] in ignore_users: # type: ignore
206+
continue
207+
205208
issue_with_metrics = IssueWithMetrics(
206209
issue.title, # type: ignore
207210
issue.html_url, # type: ignore

test_issue_metrics.py

+92-4
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ def test_get_per_issue_metrics_with_hide_envs(self):
195195
mock_issue1 = MagicMock(
196196
title="Issue 1",
197197
html_url="https://github.com/user/repo/issues/1",
198-
author="alice",
198+
user={"login": "alice"},
199199
state="open",
200200
comments=1,
201201
created_at="2023-01-01T00:00:00Z",
@@ -209,7 +209,7 @@ def test_get_per_issue_metrics_with_hide_envs(self):
209209
mock_issue2 = MagicMock(
210210
title="Issue 2",
211211
html_url="https://github.com/user/repo/issues/2",
212-
author="bob",
212+
user={"login": "bob"},
213213
state="closed",
214214
comments=1,
215215
created_at="2023-01-01T00:00:00Z",
@@ -304,7 +304,7 @@ def test_get_per_issue_metrics_without_hide_envs(self):
304304
mock_issue1 = MagicMock(
305305
title="Issue 1",
306306
html_url="https://github.com/user/repo/issues/1",
307-
author="alice",
307+
user={"login": "alice"},
308308
state="open",
309309
comments=1,
310310
created_at="2023-01-01T00:00:00Z",
@@ -318,7 +318,7 @@ def test_get_per_issue_metrics_without_hide_envs(self):
318318
mock_issue2 = MagicMock(
319319
title="Issue 2",
320320
html_url="https://github.com/user/repo/issues/2",
321-
author="bob",
321+
user={"login": "bob"},
322322
state="closed",
323323
comments=1,
324324
created_at="2023-01-01T00:00:00Z",
@@ -391,6 +391,94 @@ def test_get_per_issue_metrics_without_hide_envs(self):
391391
expected_issues_with_metrics[1].time_to_close,
392392
)
393393

394+
@patch.dict(
395+
os.environ,
396+
{
397+
"GH_TOKEN": "test_token",
398+
"SEARCH_QUERY": "is:issue is:open repo:user/repo",
399+
"IGNORE_USERS": "alice",
400+
},
401+
)
402+
def test_get_per_issue_metrics_with_ignore_users(self):
403+
"""
404+
Test that the function correctly filters out issues with authors in the IGNORE_USERS variable
405+
"""
406+
407+
# Create mock data
408+
mock_issue1 = MagicMock(
409+
title="Issue 1",
410+
html_url="https://github.com/user/repo/issues/1",
411+
user={"login": "alice"},
412+
state="open",
413+
comments=1,
414+
created_at="2023-01-01T00:00:00Z",
415+
)
416+
417+
mock_comment1 = MagicMock()
418+
mock_comment1.created_at = datetime.fromisoformat("2023-01-02T00:00:00Z")
419+
mock_issue1.issue.comments.return_value = [mock_comment1]
420+
mock_issue1.issue.pull_request_urls = None
421+
422+
mock_issue2 = MagicMock(
423+
title="Issue 2",
424+
html_url="https://github.com/user/repo/issues/2",
425+
user={"login": "bob"},
426+
state="closed",
427+
comments=1,
428+
created_at="2023-01-01T00:00:00Z",
429+
closed_at="2023-01-04T00:00:00Z",
430+
)
431+
432+
mock_comment2 = MagicMock()
433+
mock_comment2.created_at = datetime.fromisoformat("2023-01-03T00:00:00Z")
434+
mock_issue2.issue.comments.return_value = [mock_comment2]
435+
mock_issue2.issue.pull_request_urls = None
436+
437+
issues = [
438+
mock_issue1,
439+
mock_issue2,
440+
]
441+
442+
# Call the function and check the result
443+
with unittest.mock.patch( # type:ignore
444+
"issue_metrics.measure_time_to_first_response",
445+
measure_time_to_first_response,
446+
), unittest.mock.patch( # type:ignore
447+
"issue_metrics.measure_time_to_close", measure_time_to_close
448+
):
449+
(
450+
result_issues_with_metrics,
451+
result_num_issues_open,
452+
result_num_issues_closed,
453+
) = get_per_issue_metrics(
454+
issues,
455+
env_vars=get_env_vars(test=True),
456+
ignore_users=["alice"],
457+
)
458+
expected_issues_with_metrics = [
459+
IssueWithMetrics(
460+
"Issue 2",
461+
"https://github.com/user/repo/issues/2",
462+
"bob",
463+
timedelta(days=2),
464+
timedelta(days=3),
465+
None,
466+
None,
467+
),
468+
]
469+
expected_num_issues_open = 0
470+
expected_num_issues_closed = 1
471+
self.assertEqual(result_num_issues_open, expected_num_issues_open)
472+
self.assertEqual(result_num_issues_closed, expected_num_issues_closed)
473+
self.assertEqual(
474+
result_issues_with_metrics[0].time_to_first_response,
475+
expected_issues_with_metrics[0].time_to_first_response,
476+
)
477+
self.assertEqual(
478+
result_issues_with_metrics[0].time_to_close,
479+
expected_issues_with_metrics[0].time_to_close,
480+
)
481+
394482

395483
class TestDiscussionMetrics(unittest.TestCase):
396484
"""Test suite for the discussion_metrics function."""

0 commit comments

Comments
 (0)