Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

234

from typing import Dict, Type, List 

 

from ..config import CONFIG 

from ..labels import BRANCH_TYPES, BRANCH_TYPE_OTHER, UNRELEASED_LABEL, UNRELEASED 

from ..registry import Registry 

 

__author__ = 'Artur Barseghyan' 

__copyright__ = '2019 Artur Barseghyan' 

__license__ = 'GPL-2.0-only OR LGPL-2.0-or-later' 

__all__ = ( 

'BaseRenderer', 

'RendererRegistry', 

) 

 

 

class RendererRegistry(Registry): 

"""Renderer registry.""" 

 

REGISTRY: Dict[str, Type] = {} 

 

 

class AbstractRenderer(metaclass=RendererRegistry): 

 

uid: str = None 

instance: Type 

changelog: List[str] = [] 

 

def __init__(self, *args, **kwargs): 

if not self.uid: 

raise NotImplementedError 

 

def get_config(self) -> Dict[str, str]: 

return dict(CONFIG[self.uid]) 

 

def render_changelog(self, 

tree: dict, 

include_other: bool, 

headings_only: bool, 

show_description: bool) -> str: 

raise NotImplementedError 

 

def render_releases_changelog(self, 

releases_tree: dict, 

include_other: bool, 

headings_only: bool, 

show_description: bool) -> str: 

raise NotImplementedError 

 

 

class BaseRenderer(AbstractRenderer): 

 

def append_release(self, release_label: str): 

raise NotImplementedError 

 

def append_feature_type(self, branch_type: str): 

raise NotImplementedError 

 

def append_ticket_title(self, ticket_number: str, ticket_title: str): 

raise NotImplementedError 

 

def append_ticket_description(self, ticket_description: str): 

raise NotImplementedError 

 

def append_commit_message(self, 

commit_data: Dict[str, str], 

branch_type: str, 

counter: int = 0): 

raise NotImplementedError 

 

def render_changelog(self, 

tree: dict, 

include_other: bool, 

headings_only: bool, 

fetch_description: bool) -> str: 

# changelog = [] 

self.changelog = [] 

for branch_type, tickets in tree.items(): 

# Skip adding orphaned commits if explicitly asked not to. 

if branch_type == BRANCH_TYPE_OTHER and not include_other: 

continue 

 

# Do not add branch type if no related branches found 

if not tickets: 

continue 

 

if BRANCH_TYPES.get(branch_type): 

# Feature type label `append_feature_type` 

self.append_feature_type(branch_type) 

# changelog.append( 

# "\n**{}**{}".format( 

# BRANCH_TYPES.get(branch_type), 

# '\n' if branch_type == BRANCH_TYPE_OTHER else '' 

# ) 

# ) 

 

# Add tickets 

for ticket_number, ticket_data in tickets.items(): 

if 'title' not in ticket_data: 

continue 

 

if branch_type != BRANCH_TYPE_OTHER: 

# Ticket name `append_ticket_title` 

self.append_ticket_title( 

ticket_number, 

ticket_data['title'] 

) 

# changelog.append( 

# "\n*{} {}*".format( 

# ticket_number, 

# ticket_data['title'] 

# ) 

# ) 

 

if fetch_description and ticket_data['description']: 

# Description quote `append_ticket_description` 

self.append_ticket_description( 

ticket_data['description'] 

) 

# changelog.append( 

# "\n```\n{}\n```".format( 

# ticket_data['description'].strip() 

# ) 

# ) 

 

if headings_only: 

continue 

 

counter = 0 

for commit_hash, commit_data in ticket_data['commits'].items(): 

# Commit text `append_commit_message` 

self.append_commit_message( 

commit_data=commit_data, 

branch_type=branch_type, 

counter=counter 

) 

# changelog.append( 

# "{}- {} [{}]".format( 

# '\n' if counter == 0 and branch_type != BRANCH_TYPE_OTHER else '', 

# commit_data['title'], 

# commit_data['author'] 

# ) 

# ) 

counter = counter + 1 

 

# return '\n'.join(changelog) 

return '\n'.join(self.changelog) 

 

def render_releases_changelog(self, 

releases_tree: dict, 

include_other: bool, 

headings_only: bool, 

fetch_description: bool) -> str: 

# changelog = [] 

self.changelog = [] 

for release, branches in releases_tree.items(): 

release_label = UNRELEASED_LABEL \ 

if release == UNRELEASED \ 

else release 

 

# Release label `append_release` 

self.append_release(release_label) 

# changelog.append("\n### {}".format(release_label)) 

 

for branch_type, tickets in branches.items(): 

 

# Skip adding orphaned commits if explicitly asked not to. 

if branch_type == BRANCH_TYPE_OTHER and not include_other: 

continue 

 

# Do not add branch type if no related branches found 

if not tickets: 

continue 

 

# Feature type label `append_feature_type` 

if BRANCH_TYPES.get(branch_type): 

self.append_feature_type(branch_type) 

# changelog.append( 

# "\n**{}**{}".format( 

# BRANCH_TYPES.get(branch_type), 

# '\n' if branch_type == BRANCH_TYPE_OTHER else '' 

# ) 

# ) 

 

# Add tickets 

for ticket_number, ticket_data in tickets.items(): 

if 'title' not in ticket_data: 

continue 

 

if branch_type != BRANCH_TYPE_OTHER: 

# Ticket name `append_ticket_title` 

self.append_ticket_title( 

ticket_number, 

ticket_data['title'] 

) 

# changelog.append( 

# "\n*{} {}*".format( 

# ticket_number, 

# ticket_data['title'] 

# ) 

# ) 

 

if fetch_description and ticket_data['description']: 

# Description quote `append_ticket_description` 

self.append_ticket_description( 

ticket_data['description'] 

) 

# changelog.append( 

# "\n```\n{}\n```".format( 

# ticket_data['description'].strip() 

# ) 

# ) 

 

if headings_only: 

continue 

 

counter = 0 

for commit_hash, commit_data in ticket_data['commits'].items(): # NOQA 

# Commit text `append_commit_message` 

self.append_commit_message( 

commit_data=commit_data, 

branch_type=branch_type, 

counter=counter 

) 

# changelog.append( 

# "{}- {} [{}]".format( 

# '\n' if counter == 0 and branch_type != BRANCH_TYPE_OTHER else '', 

# commit_data['title'], 

# commit_data['author'] 

# ) 

# ) 

counter = counter + 1 

 

# return '\n'.join(changelog) 

return '\n'.join(self.changelog)