Skip to content

Commit d2eafd9

Browse files
committed
fix: handle created_at with diff types
Fixes #489 We union dict and github3.search.IssueSearchResult types but their created at attributes are accessed differently. issue["createdAt"] for dict issue.issue.created_at for github3.search.IssueSearchResult - [x] turned off HIDE_CREATED_AT on some tests to ensure we are handling that scenario Signed-off-by: jmeridth <jmeridth@gmail.com>
1 parent 8757e03 commit d2eafd9

File tree

4 files changed

+28
-19
lines changed

4 files changed

+28
-19
lines changed

issue_metrics.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,10 @@ def get_per_issue_metrics(
161161
elif issue.state == "open": # type: ignore
162162
num_issues_open += 1
163163
if not env_vars.hide_created_at:
164-
issue_with_metrics.created_at = issue["created_at"]
164+
if issue is github3.search.IssueSearchResult: # type: ignore
165+
issue_with_metrics.created_at = issue.issue.created_at # type: ignore
166+
elif issue is dict: # type: ignore
167+
issue_with_metrics.created_at = issue["createdAt"] # type: ignore
165168
issues_with_metrics.append(issue_with_metrics)
166169

167170
return issues_with_metrics, num_issues_open, num_issues_closed

test_config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ def setUp(self):
7272
"GH_TOKEN",
7373
"GHE",
7474
"HIDE_AUTHOR",
75+
"HIDE_CREATED_AT",
7576
"HIDE_ITEMS_CLOSED_COUNT",
7677
"HIDE_LABEL_METRICS",
7778
"HIDE_TIME_TO_ANSWER",

test_issue_metrics.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -374,9 +374,7 @@ def setUp(self):
374374
self.issue1 = {
375375
"title": "Issue 1",
376376
"url": "github.com/user/repo/issues/1",
377-
"user": {
378-
"login": "alice",
379-
},
377+
"user": {"login": "alice"},
380378
"createdAt": "2023-01-01T00:00:00Z",
381379
"comments": {
382380
"nodes": [
@@ -392,9 +390,7 @@ def setUp(self):
392390
self.issue2 = {
393391
"title": "Issue 2",
394392
"url": "github.com/user/repo/issues/2",
395-
"user": {
396-
"login": "bob",
397-
},
393+
"user": {"login": "bob"},
398394
"createdAt": "2023-01-01T00:00:00Z",
399395
"comments": {"nodes": [{"createdAt": "2023-01-03T00:00:00Z"}]},
400396
"answerChosenAt": "2023-01-05T00:00:00Z",
@@ -441,6 +437,7 @@ def test_get_per_issue_metrics_with_discussion(self):
441437
"GH_TOKEN": "test_token",
442438
"SEARCH_QUERY": "is:issue is:open repo:user/repo",
443439
"HIDE_AUTHOR": "true",
440+
"HIDE_CREATED_AT": "false",
444441
"HIDE_LABEL_METRICS": "true",
445442
"HIDE_TIME_TO_ANSWER": "true",
446443
"HIDE_TIME_TO_CLOSE": "true",

test_markdown_writer.py

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"SEARCH_QUERY": "is:open repo:user/repo",
2323
"GH_TOKEN": "test_token",
2424
"DRAFT_PR_TRACKING": "True",
25+
"HIDE_CREATED_AT": "False",
2526
},
2627
)
2728
class TestWriteToMarkdown(unittest.TestCase):
@@ -44,6 +45,7 @@ def test_write_to_markdown(self):
4445
title="Issue 1",
4546
html_url="https://github.com/user/repo/issues/1",
4647
author="alice",
48+
created_at=timedelta(days=-5),
4749
time_to_first_response=timedelta(days=1),
4850
time_to_close=timedelta(days=2),
4951
time_to_answer=timedelta(days=3),
@@ -54,6 +56,7 @@ def test_write_to_markdown(self):
5456
title="Issue 2\r",
5557
html_url="https://github.com/user/repo/issues/2",
5658
author="bob",
59+
created_at=timedelta(days=-5),
5760
time_to_first_response=timedelta(days=3),
5861
time_to_close=timedelta(days=4),
5962
time_to_answer=timedelta(days=5),
@@ -129,12 +132,12 @@ def test_write_to_markdown(self):
129132
"| Number of most active mentors | 5 |\n"
130133
"| Total number of items created | 2 |\n\n"
131134
"| Title | URL | Author | Time to first response | Time to close |"
132-
" Time to answer | Time in draft | Time spent in bug |\n"
133-
"| --- | --- | --- | --- | --- | --- | --- | --- |\n"
135+
" Time to answer | Time in draft | Time spent in bug | Created At |\n"
136+
"| --- | --- | --- | --- | --- | --- | --- | --- | --- |\n"
134137
"| Issue 1 | https://github.com/user/repo/issues/1 | [alice](https://github.com/alice) | 1 day, 0:00:00 | "
135-
"2 days, 0:00:00 | 3 days, 0:00:00 | 1 day, 0:00:00 | 4 days, 0:00:00 |\n"
138+
"2 days, 0:00:00 | 3 days, 0:00:00 | 1 day, 0:00:00 | 4 days, 0:00:00 | -5 days, 0:00:00 |\n"
136139
"| Issue 2 | https://github.com/user/repo/issues/2 | [bob](https://github.com/bob) | 3 days, 0:00:00 | "
137-
"4 days, 0:00:00 | 5 days, 0:00:00 | 1 day, 0:00:00 | 2 days, 0:00:00 |\n\n"
140+
"4 days, 0:00:00 | 5 days, 0:00:00 | 1 day, 0:00:00 | 2 days, 0:00:00 | -5 days, 0:00:00 |\n\n"
138141
"_This report was generated with the [Issue Metrics Action](https://github.com/github/issue-metrics)_\n"
139142
"Search query used to find these items: `is:issue is:open label:bug`\n"
140143
)
@@ -156,6 +159,7 @@ def test_write_to_markdown_with_vertical_bar_in_title(self):
156159
title="Issue 1",
157160
html_url="https://github.com/user/repo/issues/1",
158161
author="alice",
162+
created_at=timedelta(days=-5),
159163
time_to_first_response=timedelta(days=1),
160164
time_to_close=timedelta(days=2),
161165
time_to_answer=timedelta(days=3),
@@ -166,6 +170,7 @@ def test_write_to_markdown_with_vertical_bar_in_title(self):
166170
title="feat| Issue 2", # title contains a vertical bar
167171
html_url="https://github.com/user/repo/issues/2",
168172
author="bob",
173+
created_at=timedelta(days=-5),
169174
time_to_first_response=timedelta(days=3),
170175
time_to_close=timedelta(days=4),
171176
time_to_answer=timedelta(days=5),
@@ -238,12 +243,12 @@ def test_write_to_markdown_with_vertical_bar_in_title(self):
238243
"| Number of most active mentors | 5 |\n"
239244
"| Total number of items created | 2 |\n\n"
240245
"| Title | URL | Author | Time to first response | Time to close |"
241-
" Time to answer | Time in draft | Time spent in bug |\n"
242-
"| --- | --- | --- | --- | --- | --- | --- | --- |\n"
246+
" Time to answer | Time in draft | Time spent in bug | Created At |\n"
247+
"| --- | --- | --- | --- | --- | --- | --- | --- | --- |\n"
243248
"| Issue 1 | https://github.com/user/repo/issues/1 | [alice](https://github.com/alice) | 1 day, 0:00:00 | "
244-
"2 days, 0:00:00 | 3 days, 0:00:00 | 1 day, 0:00:00 | 1 day, 0:00:00 |\n"
249+
"2 days, 0:00:00 | 3 days, 0:00:00 | 1 day, 0:00:00 | 1 day, 0:00:00 | -5 days, 0:00:00 |\n"
245250
"| feat&#124; Issue 2 | https://github.com/user/repo/issues/2 | [bob](https://github.com/bob) | 3 days, 0:00:00 | "
246-
"4 days, 0:00:00 | 5 days, 0:00:00 | None | 2 days, 0:00:00 |\n\n"
251+
"4 days, 0:00:00 | 5 days, 0:00:00 | None | 2 days, 0:00:00 | -5 days, 0:00:00 |\n\n"
247252
"_This report was generated with the [Issue Metrics Action](https://github.com/github/issue-metrics)_\n"
248253
)
249254
self.assertEqual(content, expected_content)
@@ -309,6 +314,7 @@ def test_writes_markdown_file_with_non_hidden_columns_only(self):
309314
title="Issue 1",
310315
html_url="https://github.com/user/repo/issues/1",
311316
author="alice",
317+
created_at=timedelta(days=-5),
312318
time_to_first_response=timedelta(minutes=10),
313319
time_to_close=timedelta(days=1),
314320
time_to_answer=timedelta(hours=2),
@@ -321,6 +327,7 @@ def test_writes_markdown_file_with_non_hidden_columns_only(self):
321327
title="Issue 2",
322328
html_url="https://github.com/user/repo/issues/2",
323329
author="bob",
330+
created_at=timedelta(days=-5),
324331
time_to_first_response=timedelta(minutes=20),
325332
time_to_close=timedelta(days=2),
326333
time_to_answer=timedelta(hours=4),
@@ -363,17 +370,18 @@ def test_writes_markdown_file_with_non_hidden_columns_only(self):
363370
# Check that the function writes the correct markdown file
364371
with open("issue_metrics.md", "r", encoding="utf-8") as file:
365372
content = file.read()
373+
366374
expected_content = (
367375
"# Issue Metrics\n\n"
368376
"| Metric | Count |\n"
369377
"| --- | ---: |\n"
370378
"| Number of items that remain open | 2 |\n"
371379
"| Number of most active mentors | 5 |\n"
372380
"| Total number of items created | 2 |\n\n"
373-
"| Title | URL | Author |\n"
374-
"| --- | --- | --- |\n"
375-
"| Issue 1 | https://www.github.com/user/repo/issues/1 | [alice](https://github.com/alice) |\n"
376-
"| Issue 2 | https://www.github.com/user/repo/issues/2 | [bob](https://github.com/bob) |\n\n"
381+
"| Title | URL | Author | Created At |\n"
382+
"| --- | --- | --- | --- |\n"
383+
"| Issue 1 | https://www.github.com/user/repo/issues/1 | [alice](https://github.com/alice) | -5 days, 0:00:00 |\n"
384+
"| Issue 2 | https://www.github.com/user/repo/issues/2 | [bob](https://github.com/bob) | -5 days, 0:00:00 |\n\n"
377385
"_This report was generated with the [Issue Metrics Action](https://github.com/github/issue-metrics)_\n"
378386
"Search query used to find these items: `repo:user/repo is:issue`\n"
379387
)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy