Skip to content

Commit da328ef

Browse files
authored
Merge pull request #491 from github/jm_fix_hide_created_at_false
fix: handle created_at with diff types
2 parents 8757e03 + be847c8 commit da328ef

File tree

4 files changed

+29
-19
lines changed

4 files changed

+29
-19
lines changed

issue_metrics.py

+4-1
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 isinstance(issue, github3.search.IssueSearchResult): # type: ignore
165+
issue_with_metrics.created_at = issue.issue.created_at # type: ignore
166+
elif isinstance(issue, 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

+1
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

+3-6
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

+21-12
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| 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)
@@ -287,6 +292,7 @@ def test_write_to_markdown_no_issues(self):
287292
{
288293
"SEARCH_QUERY": "is:open repo:user/repo",
289294
"GH_TOKEN": "test_token",
295+
"HIDE_CREATED_AT": "False",
290296
"HIDE_TIME_TO_FIRST_RESPONSE": "True",
291297
"HIDE_TIME_TO_CLOSE": "True",
292298
"HIDE_TIME_TO_ANSWER": "True",
@@ -309,6 +315,7 @@ def test_writes_markdown_file_with_non_hidden_columns_only(self):
309315
title="Issue 1",
310316
html_url="https://github.com/user/repo/issues/1",
311317
author="alice",
318+
created_at=timedelta(days=-5),
312319
time_to_first_response=timedelta(minutes=10),
313320
time_to_close=timedelta(days=1),
314321
time_to_answer=timedelta(hours=2),
@@ -321,6 +328,7 @@ def test_writes_markdown_file_with_non_hidden_columns_only(self):
321328
title="Issue 2",
322329
html_url="https://github.com/user/repo/issues/2",
323330
author="bob",
331+
created_at=timedelta(days=-5),
324332
time_to_first_response=timedelta(minutes=20),
325333
time_to_close=timedelta(days=2),
326334
time_to_answer=timedelta(hours=4),
@@ -363,17 +371,18 @@ def test_writes_markdown_file_with_non_hidden_columns_only(self):
363371
# Check that the function writes the correct markdown file
364372
with open("issue_metrics.md", "r", encoding="utf-8") as file:
365373
content = file.read()
374+
366375
expected_content = (
367376
"# Issue Metrics\n\n"
368377
"| Metric | Count |\n"
369378
"| --- | ---: |\n"
370379
"| Number of items that remain open | 2 |\n"
371380
"| Number of most active mentors | 5 |\n"
372381
"| 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"
382+
"| Title | URL | Author | Created At |\n"
383+
"| --- | --- | --- | --- |\n"
384+
"| Issue 1 | https://www.github.com/user/repo/issues/1 | [alice](https://github.com/alice) | -5 days, 0:00:00 |\n"
385+
"| Issue 2 | https://www.github.com/user/repo/issues/2 | [bob](https://github.com/bob) | -5 days, 0:00:00 |\n\n"
377386
"_This report was generated with the [Issue Metrics Action](https://github.com/github/issue-metrics)_\n"
378387
"Search query used to find these items: `repo:user/repo is:issue`\n"
379388
)

0 commit comments

Comments
 (0)