Coverage for src/types/milestones.py: 37.14%
35 statements
« prev ^ index » next coverage.py v7.17.2, created at 2026-11-07 23:50 +0000
« prev ^ index » next coverage.py v7.17.2, created at 2026-11-07 23:50 +0000
1#!/usr/bin/env python3
3# Standard libraries
4import datetime
5import re
7# Components
8from ..package.bundle import Bundle
10# MilestoneDescription class, pylint: disable=too-few-public-methods
11class MilestoneDescription:
13 # Constants
14 AUTOGENERATED_HINT: str = f'<!-- DO NOT EDIT, GENERATED BY: {Bundle.NAME} -->'
15 AUTOGENERATED_START: str = f'<!-- {Bundle.NAME}-start -->'
16 AUTOGENERATED_STOP: str = f'<!-- {Bundle.NAME}-stop -->'
17 AUTOGENERATED_UPDATED: str = f'<!-- {Bundle.NAME}-updated -->'
18 DUE_DATE_UNDEFINED: str = '9999-12-31'
20 # Inject statistics
21 @staticmethod
22 def inject_statistics(description: str, statistics: str) -> str:
24 # Variables
25 detailed: bool = False
27 # Strip old statistics
28 description = re.sub(
29 r'(?ms)'
30 f'\n{MilestoneDescription.AUTOGENERATED_START}'
31 r'.*'
32 f'\n{MilestoneDescription.AUTOGENERATED_STOP}',
33 '',
34 description,
35 )
37 # Detect detailed description
38 if description:
39 detailed = True
40 if not description.endswith('\n'):
41 description += '\n'
43 # Inject statistics start
44 description += f'\n{MilestoneDescription.AUTOGENERATED_START}'
45 description += f'\n{MilestoneDescription.AUTOGENERATED_HINT}'
46 description += '\n'
48 # Inject statistics separator
49 if detailed:
50 description += '\n---'
51 description += '\n'
53 # Inject statistics content
54 description += f'\n{statistics}'
56 # Inject milestone update
57 date_updated = datetime.datetime.now(
58 datetime.timezone.utc).strftime('%Y-%m-%d %H:%M:%S UTC')
59 description += '\n'
60 description += f'\n_Last update using {Bundle.NAME} : {date_updated}_' \
61 f' {MilestoneDescription.AUTOGENERATED_UPDATED}'
63 # Inject statistics stop
64 description += '\n'
65 description += f'\n{MilestoneDescription.AUTOGENERATED_STOP}'
67 # Result
68 return description
70 # Updated statistics
71 @staticmethod
72 def updated_statistics(description_current: str, description_new: str) -> bool:
74 # Filter updated comment line
75 description_current = '\n'.join(
76 line for line in description_current.splitlines()
77 if MilestoneDescription.AUTOGENERATED_UPDATED not in line)
78 description_new = '\n'.join(
79 line for line in description_new.splitlines()
80 if MilestoneDescription.AUTOGENERATED_UPDATED not in line)
82 # Compare descriptions
83 return description_current != description_new