2323 "GH_TOKEN" : "test_token" ,
2424 "DRAFT_PR_TRACKING" : "True" ,
2525 "HIDE_CREATED_AT" : "False" ,
26+ "HIDE_STATUS" : "False" ,
2627 },
2728)
2829class TestWriteToMarkdown (unittest .TestCase ):
@@ -128,20 +129,21 @@ def test_write_to_markdown(self):
128129 "| Time to answer | 4 days, 0:00:00 | 4 days, 0:00:00 | 4 days, 0:00:00 |\n "
129130 "| Time in draft | 1 day, 0:00:00 | 1 day, 0:00:00 | 1 day, 0:00:00 |\n "
130131 "| Time spent in bug | 1 day, 12:00:00 | 1 day, 12:00:00 | 1 day, 12:00:00 |\n "
132+ "| Status | | | |\n "
131133 "\n "
132134 "| Metric | Count |\n "
133135 "| --- | ---: |\n "
134136 "| Number of items that remain open | 2 |\n "
135137 "| Number of items closed | 1 |\n "
136138 "| 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 "
140142 "| Issue 1 | https://github.com/user/repo/issues/1 | [charlie](https://github.com/charlie) | "
141143 "[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 "
143145 "| 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 "
145147 "_This report was generated with the [Issue Metrics Action](https://github.com/github/issue-metrics)_\n "
146148 "Search query used to find these items: `is:issue is:open label:bug`\n "
147149 )
@@ -182,6 +184,7 @@ def test_write_to_markdown_with_vertical_bar_in_title(self):
182184 time_to_first_response = timedelta (days = 3 ),
183185 time_to_close = timedelta (days = 4 ),
184186 time_to_answer = timedelta (days = 5 ),
187+ time_in_draft = None ,
185188 labels_metrics = {"bug" : timedelta (days = 2 )},
186189 ),
187190 ]
@@ -243,21 +246,22 @@ def test_write_to_markdown_with_vertical_bar_in_title(self):
243246 "| Time to answer | 4 days, 0:00:00 | 4 days, 0:00:00 | 4 days, 0:00:00 |\n "
244247 "| Time in draft | 1 day, 0:00:00 | 1 day, 0:00:00 | 1 day, 0:00:00 |\n "
245248 "| Time spent in bug | 1 day, 12:00:00 | 1 day, 12:00:00 | 1 day, 12:00:00 |\n "
249+ "| Status | | | |\n "
246250 "\n "
247251 "| Metric | Count |\n "
248252 "| --- | ---: |\n "
249253 "| Number of items that remain open | 2 |\n "
250254 "| Number of items closed | 1 |\n "
251255 "| 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 "
255259 "| Issue 1 | https://github.com/user/repo/issues/1 | [charlie](https://github.com/charlie) | "
256260 "[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 "
258262 "| feat| Issue 2 | https://github.com/user/repo/issues/2 | None | "
259263 "[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 "
261265 "_This report was generated with the [Issue Metrics Action](https://github.com/github/issue-metrics)_\n "
262266 )
263267 self .assertEqual (content , expected_content )
@@ -308,6 +312,7 @@ def test_write_to_markdown_no_issues(self):
308312 "HIDE_LABEL_METRICS" : "True" ,
309313 "NON_MENTIONING_LINKS" : "True" ,
310314 "GH_ENTERPRISE_URL" : "https://ghe.com" ,
315+ "HIDE_STATUS" : "False" ,
311316 },
312317)
313318class TestWriteToMarkdownWithEnv (unittest .TestCase ):
@@ -400,7 +405,116 @@ def test_writes_markdown_file_with_non_hidden_columns_only(self):
400405 "| Number of items that remain open | 2 |\n "
401406 "| Number of most active mentors | 5 |\n "
402407 "| 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
404518 "| --- | --- | --- | --- | --- |\n "
405519 "| Issue 1 | https://www.ghe.com/user/repo/issues/1 | [charlie](https://ghe.com/charlie) | "
406520 "[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):
410524 )
411525 self .assertEqual (content , expected_content )
412526 os .remove ("issue_metrics.md" )
527+
528+
529+ if __name__ == "__main__" :
530+ unittest .main ()
0 commit comments