23
23
"GH_TOKEN" : "test_token" ,
24
24
"DRAFT_PR_TRACKING" : "True" ,
25
25
"HIDE_CREATED_AT" : "False" ,
26
+ "HIDE_STATUS" : "False" ,
26
27
},
27
28
)
28
29
class TestWriteToMarkdown (unittest .TestCase ):
@@ -128,20 +129,21 @@ def test_write_to_markdown(self):
128
129
"| Time to answer | 4 days, 0:00:00 | 4 days, 0:00:00 | 4 days, 0:00:00 |\n "
129
130
"| Time in draft | 1 day, 0:00:00 | 1 day, 0:00:00 | 1 day, 0:00:00 |\n "
130
131
"| Time spent in bug | 1 day, 12:00:00 | 1 day, 12:00:00 | 1 day, 12:00:00 |\n "
132
+ "| Status | | | |\n "
131
133
"\n "
132
134
"| Metric | Count |\n "
133
135
"| --- | ---: |\n "
134
136
"| Number of items that remain open | 2 |\n "
135
137
"| Number of items closed | 1 |\n "
136
138
"| Total number of items created | 2 |\n \n "
137
- "| Title | URL | Assignee | Author | Time to first response | Time to close |"
138
- " Time to answer | Time in draft | Time spent in bug | Created At |\n "
139
- "| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |\n "
139
+ "| Title | URL | Assignee | Author | Time to first response | Time to close | "
140
+ "Time to answer | Status | Time in draft | Time spent in bug | Created At |\n "
141
+ "| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | \n "
140
142
"| Issue 1 | https://github.com/user/repo/issues/1 | [charlie](https://github.com/charlie) | "
141
143
"[alice](https://github.com/alice) | 1 day, 0:00:00 | 2 days, 0:00:00 | 3 days, 0:00:00 | "
142
- "1 day, 0:00:00 | 4 days, 0:00:00 | -5 days, 0:00:00 |\n "
144
+ "1 day, 0:00:00 | 4 days, 0:00:00 | -5 days, 0:00:00 | None | \n "
143
145
"| Issue 2 | https://github.com/user/repo/issues/2 | None | [bob](https://github.com/bob) | 3 days, 0:00:00 | "
144
- "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 "
146
+ "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 | None | \n \n "
145
147
"_This report was generated with the [Issue Metrics Action](https://github.com/github/issue-metrics)_\n "
146
148
"Search query used to find these items: `is:issue is:open label:bug`\n "
147
149
)
@@ -182,6 +184,7 @@ def test_write_to_markdown_with_vertical_bar_in_title(self):
182
184
time_to_first_response = timedelta (days = 3 ),
183
185
time_to_close = timedelta (days = 4 ),
184
186
time_to_answer = timedelta (days = 5 ),
187
+ time_in_draft = None ,
185
188
labels_metrics = {"bug" : timedelta (days = 2 )},
186
189
),
187
190
]
@@ -243,21 +246,22 @@ def test_write_to_markdown_with_vertical_bar_in_title(self):
243
246
"| Time to answer | 4 days, 0:00:00 | 4 days, 0:00:00 | 4 days, 0:00:00 |\n "
244
247
"| Time in draft | 1 day, 0:00:00 | 1 day, 0:00:00 | 1 day, 0:00:00 |\n "
245
248
"| Time spent in bug | 1 day, 12:00:00 | 1 day, 12:00:00 | 1 day, 12:00:00 |\n "
249
+ "| Status | | | |\n "
246
250
"\n "
247
251
"| Metric | Count |\n "
248
252
"| --- | ---: |\n "
249
253
"| Number of items that remain open | 2 |\n "
250
254
"| Number of items closed | 1 |\n "
251
255
"| Total number of items created | 2 |\n \n "
252
- "| Title | URL | Assignee | Author | Time to first response | Time to close |"
253
- " Time to answer | Time in draft | Time spent in bug | Created At |\n "
254
- "| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |\n "
256
+ "| Title | URL | Assignee | Author | Time to first response | Time to close | "
257
+ "Time to answer | Status | Time in draft | Time spent in bug | Created At |\n "
258
+ "| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | \n "
255
259
"| Issue 1 | https://github.com/user/repo/issues/1 | [charlie](https://github.com/charlie) | "
256
260
"[alice](https://github.com/alice) | 1 day, 0:00:00 | 2 days, 0:00:00 | 3 days, 0:00:00 | "
257
- "1 day, 0:00:00 | 1 day, 0:00:00 | -5 days, 0:00:00 |\n "
261
+ "1 day, 0:00:00 | 1 day, 0:00:00 | -5 days, 0:00:00 | None | \n "
258
262
"| feat| Issue 2 | https://github.com/user/repo/issues/2 | None | "
259
263
"[bob](https://github.com/bob) | 3 days, 0:00:00 | "
260
- "4 days, 0:00:00 | 5 days, 0:00:00 | None | 2 days, 0:00:00 | -5 days, 0:00:00 |\n \n "
264
+ "4 days, 0:00:00 | 5 days, 0:00:00 | None | 2 days, 0:00:00 | -5 days, 0:00:00 | None | \n \n "
261
265
"_This report was generated with the [Issue Metrics Action](https://github.com/github/issue-metrics)_\n "
262
266
)
263
267
self .assertEqual (content , expected_content )
@@ -308,6 +312,7 @@ def test_write_to_markdown_no_issues(self):
308
312
"HIDE_LABEL_METRICS" : "True" ,
309
313
"NON_MENTIONING_LINKS" : "True" ,
310
314
"GH_ENTERPRISE_URL" : "https://ghe.com" ,
315
+ "HIDE_STATUS" : "False" ,
311
316
},
312
317
)
313
318
class TestWriteToMarkdownWithEnv (unittest .TestCase ):
@@ -400,7 +405,116 @@ def test_writes_markdown_file_with_non_hidden_columns_only(self):
400
405
"| Number of items that remain open | 2 |\n "
401
406
"| Number of most active mentors | 5 |\n "
402
407
"| Total number of items created | 2 |\n \n "
403
- "| Title | URL | Assignee | Author | Created At |\n "
408
+ "| Title | URL | Assignee | Author | Status | Created At |\n "
409
+ "| --- | --- | --- | --- | --- | --- |\n "
410
+ "| Issue 1 | https://www.ghe.com/user/repo/issues/1 | [charlie](https://ghe.com/charlie) | "
411
+ "[alice](https://ghe.com/alice) | -5 days, 0:00:00 | None |\n "
412
+ "| Issue 2 | https://www.ghe.com/user/repo/issues/2 | None | [bob](https://ghe.com/bob) | -5 days, 0:00:00 | None |\n \n "
413
+ "_This report was generated with the [Issue Metrics Action](https://github.com/github/issue-metrics)_\n "
414
+ "Search query used to find these items: `repo:user/repo is:issue`\n "
415
+ )
416
+ self .assertEqual (content , expected_content )
417
+ os .remove ("issue_metrics.md" )
418
+
419
+ @patch .dict (
420
+ os .environ ,
421
+ {
422
+ "SEARCH_QUERY" : "is:open repo:user/repo" ,
423
+ "GH_TOKEN" : "test_token" ,
424
+ "HIDE_CREATED_AT" : "False" ,
425
+ "HIDE_TIME_TO_FIRST_RESPONSE" : "True" ,
426
+ "HIDE_TIME_TO_CLOSE" : "True" ,
427
+ "HIDE_TIME_TO_ANSWER" : "True" ,
428
+ "HIDE_LABEL_METRICS" : "True" ,
429
+ "NON_MENTIONING_LINKS" : "True" ,
430
+ "GH_ENTERPRISE_URL" : "https://ghe.com" ,
431
+ "HIDE_STATUS" : "True" , # Status column should be hidden
432
+ },
433
+ )
434
+ def test_writes_markdown_file_with_hidden_status_column (self ):
435
+ """
436
+ Test that write_to_markdown writes the correct markdown file
437
+ when HIDE_STATUS is set to True, ensuring the Status column
438
+ is not present in the output.
439
+ """
440
+ # Create mock data
441
+ issues_with_metrics = [
442
+ IssueWithMetrics (
443
+ title = "Issue 1" ,
444
+ html_url = "https://ghe.com/user/repo/issues/1" ,
445
+ author = "alice" ,
446
+ assignee = "charlie" ,
447
+ assignees = ["charlie" ],
448
+ created_at = timedelta (days = - 5 ),
449
+ time_to_first_response = timedelta (minutes = 10 ),
450
+ time_to_close = timedelta (days = 1 ),
451
+ time_to_answer = timedelta (hours = 2 ),
452
+ time_in_draft = timedelta (days = 1 ),
453
+ labels_metrics = {
454
+ "label1" : timedelta (days = 1 ),
455
+ },
456
+ ),
457
+ IssueWithMetrics (
458
+ title = "Issue 2" ,
459
+ html_url = "https://ghe.com/user/repo/issues/2" ,
460
+ author = "bob" ,
461
+ assignee = None ,
462
+ assignees = [],
463
+ created_at = timedelta (days = - 5 ),
464
+ time_to_first_response = timedelta (minutes = 20 ),
465
+ time_to_close = timedelta (days = 2 ),
466
+ time_to_answer = timedelta (hours = 4 ),
467
+ labels_metrics = {
468
+ "label1" : timedelta (days = 1 ),
469
+ },
470
+ ),
471
+ ]
472
+ average_time_to_first_response = timedelta (minutes = 15 )
473
+ average_time_to_close = timedelta (days = 1.5 )
474
+ average_time_to_answer = timedelta (hours = 3 )
475
+ average_time_in_draft = timedelta (days = 1 )
476
+ average_time_in_labels = {
477
+ "label1" : timedelta (days = 1 ),
478
+ }
479
+ num_issues_opened = 2
480
+ num_issues_closed = 2
481
+ num_mentor_count = 5
482
+ ghe = "https://ghe.com"
483
+
484
+ # Call the function
485
+ write_to_markdown (
486
+ issues_with_metrics = issues_with_metrics ,
487
+ average_time_to_first_response = average_time_to_first_response ,
488
+ average_time_to_close = average_time_to_close ,
489
+ average_time_to_answer = average_time_to_answer ,
490
+ average_time_in_labels = average_time_in_labels ,
491
+ average_time_in_draft = average_time_in_draft ,
492
+ num_issues_opened = num_issues_opened ,
493
+ num_issues_closed = num_issues_closed ,
494
+ num_mentor_count = num_mentor_count ,
495
+ labels = ["label1" ],
496
+ search_query = "repo:user/repo is:issue" ,
497
+ hide_label_metrics = True ,
498
+ hide_items_closed_count = True ,
499
+ enable_mentor_count = True ,
500
+ non_mentioning_links = True ,
501
+ report_title = "Issue Metrics" ,
502
+ output_file = "issue_metrics.md" ,
503
+ ghe = ghe ,
504
+ )
505
+
506
+ # Check that the function writes the correct markdown file
507
+ with open ("issue_metrics.md" , "r" , encoding = "utf-8" ) as file :
508
+ content = file .read ()
509
+
510
+ expected_content = (
511
+ "# Issue Metrics\n \n "
512
+ "| Metric | Count |\n "
513
+ "| --- | ---: |\n "
514
+ "| Number of items that remain open | 2 |\n "
515
+ "| Number of most active mentors | 5 |\n "
516
+ "| Total number of items created | 2 |\n \n "
517
+ "| Title | URL | Assignee | Author | Created At |\n " # Status column should be missing
404
518
"| --- | --- | --- | --- | --- |\n "
405
519
"| Issue 1 | https://www.ghe.com/user/repo/issues/1 | [charlie](https://ghe.com/charlie) | "
406
520
"[alice](https://ghe.com/alice) | -5 days, 0:00:00 |\n "
@@ -410,3 +524,7 @@ def test_writes_markdown_file_with_non_hidden_columns_only(self):
410
524
)
411
525
self .assertEqual (content , expected_content )
412
526
os .remove ("issue_metrics.md" )
527
+
528
+
529
+ if __name__ == "__main__" :
530
+ unittest .main ()
0 commit comments