88
99
1010class Version :
11+ """
12+ This class represents a single version of Modmail.
13+
14+ Parameters
15+ ----------
16+ bot : Bot
17+ The Modmail bot.
18+ version : str
19+ The version string (ie. "v2.12.0").
20+ lines : str
21+ The lines of changelog messages for this version.
22+
23+ Attributes
24+ ----------
25+ bot : Bot
26+ The Modmail bot.
27+ version : str
28+ The version string (ie. "v2.12.0").
29+ lines : List[str]
30+ A list of lines of changelog messages for this version.
31+ fields : defaultdict[str, str]
32+ A dict of fields separated by "Fixed", "Changed", etc sections.
33+ description : str
34+ General description of the version.
35+ """
36+
1137 def __init__ (self , bot : Bot , version : str , lines : str ):
1238 self .bot = bot
1339 self .version = version
@@ -20,6 +46,13 @@ def __repr__(self) -> str:
2046 return f'Version({ self .version } , description="{ self .description } ")'
2147
2248 def parse (self ) -> None :
49+ """
50+ Parse the lines and split them into `description` and `fields`.
51+ .
52+ Returns
53+ -------
54+ None
55+ """
2356 curr_action = None
2457
2558 for line in self .lines :
@@ -32,6 +65,9 @@ def parse(self) -> None:
3265
3366 @property
3467 def embed (self ) -> Embed :
68+ """
69+ Embed: the formatted `Embed` of this `Version`.
70+ """
3571 embed = Embed (color = Color .green (), description = self .description )
3672 embed .set_author (
3773 name = f'{ self .version } - Changelog' ,
@@ -46,31 +82,81 @@ def embed(self) -> Embed:
4682 return embed
4783
4884
49- class ChangeLog :
50- changelog_url = ('https://raw.githubusercontent.com/'
85+ class Changelog :
86+ """
87+ This class represents the complete changelog of Modmail.
88+
89+ Parameters
90+ ----------
91+ bot : Bot
92+ The Modmail bot.
93+ text : str
94+ The complete changelog text.
95+
96+ Attributes
97+ ----------
98+ bot : Bot
99+ The Modmail bot.
100+ text : str
101+ The complete changelog text.
102+ versions : List[Version]
103+ A list of `Version`'s within the changelog.
104+
105+ Class Attributes
106+ ----------------
107+ CHANGELOG_URL : str
108+ The URL to Modmail changelog.
109+ VERSION_REGEX : re.Pattern
110+ The regex used to parse the versions.
111+ """
112+
113+ CHANGELOG_URL = ('https://raw.githubusercontent.com/'
51114 'kyb3r/modmail/master/CHANGELOG.md' )
52- regex = re .compile (r'# (v\d+\.\d+\.\d+)([\S\s]*?(?=# v|$))' )
115+ VERSION_REGEX = re .compile (r'# (v\d+\.\d+\.\d+)([\S\s]*?(?=# v|$))' )
53116
54117 def __init__ (self , bot : Bot , text : str ):
55118 self .bot = bot
56119 self .text = text
57- self .versions = [Version (bot , * m ) for m in self .regex .findall (text )]
120+ self .versions = [Version (bot , * m )
121+ for m in self .VERSION_REGEX .findall (text )]
58122
59123 @property
60124 def latest_version (self ) -> Version :
125+ """
126+ Version: The latest `Version` of the `Changelog`.
127+ """
61128 return self .versions [0 ]
62129
63130 @property
64131 def embeds (self ) -> List [Embed ]:
132+ """
133+ List[Embed]: A list of `Embed`'s for each of the `Version`.
134+ """
65135 return [v .embed for v in self .versions ]
66136
67137 @classmethod
68- async def from_repo (cls , bot , url : str = '' ) -> 'ChangeLog' :
69- url = url or cls .changelog_url
138+ async def from_url (cls , bot : Bot , url : str = '' ) -> 'Changelog' :
139+ """
140+ Create a `Changelog` from a URL.
141+
142+ Parameters
143+ ----------
144+ bot : Bot
145+ The Modmail bot.
146+ url : str, optional
147+ Defaults to `CHANGELOG_URL`.
148+ The URL to the changelog.
149+
150+ Returns
151+ -------
152+ Changelog
153+ The newly created `Changelog` parsed from the `url`.
154+ """
155+ url = url or cls .CHANGELOG_URL
70156 resp = await bot .session .get (url )
71157 return cls (bot , await resp .text ())
72158
73159
74160if __name__ == '__main__' :
75161 with open ('../CHANGELOG.md' ) as f :
76- print (ChangeLog (..., f .read ()).latest_version )
162+ print (Changelog (..., f .read ()).latest_version )
0 commit comments