23
23
import sys
24
24
import re
25
25
26
- from typing import Optional
27
-
28
26
import yaml
29
27
30
28
from release_notes_generator .utils .constants import (
@@ -69,28 +67,28 @@ def get_github_repository() -> str:
69
67
"""
70
68
Get the GitHub repository from the action inputs.
71
69
"""
72
- return get_action_input (GITHUB_REPOSITORY )
70
+ return get_action_input (GITHUB_REPOSITORY ) or ""
73
71
74
72
@staticmethod
75
73
def get_github_token () -> str :
76
74
"""
77
75
Get the GitHub token from the action inputs.
78
76
"""
79
- return get_action_input (GITHUB_TOKEN )
77
+ return get_action_input (GITHUB_TOKEN ) or ""
80
78
81
79
@staticmethod
82
80
def get_tag_name () -> str :
83
81
"""
84
82
Get the tag name from the action inputs.
85
83
"""
86
- return get_action_input (TAG_NAME )
84
+ return get_action_input (TAG_NAME ) or ""
87
85
88
86
@staticmethod
89
87
def get_from_tag_name () -> str :
90
88
"""
91
89
Get the from-tag name from the action inputs.
92
90
"""
93
- return get_action_input (FROM_TAG_NAME , default = "" )
91
+ return get_action_input (FROM_TAG_NAME , default = "" ) # type: ignore[return-value] # string is returned as default
94
92
95
93
@staticmethod
96
94
def is_from_tag_name_defined () -> bool :
@@ -101,22 +99,23 @@ def is_from_tag_name_defined() -> bool:
101
99
return value .strip () != ""
102
100
103
101
@staticmethod
104
- def get_chapters () -> Optional [ list [dict [str , str ] ]]:
102
+ def get_chapters () -> list [dict [str , str ]]:
105
103
"""
106
104
Get list of the chapters from the action inputs. Each chapter is a dict.
107
105
"""
108
106
# Get the 'chapters' input from environment variables
109
- chapters_input : str = get_action_input (CHAPTERS , default = "" )
107
+ chapters_input : str = get_action_input (CHAPTERS , default = "" ) # type: ignore[assignment]
108
+ # mypy: string is returned as default
110
109
111
110
# Parse the received string back to YAML array input.
112
111
try :
113
112
chapters = yaml .safe_load (chapters_input )
114
113
if not isinstance (chapters , list ):
115
114
logger .error ("Error: 'chapters' input is not a valid YAML list." )
116
- return None
115
+ return []
117
116
except yaml .YAMLError as exc :
118
117
logger .error ("Error parsing 'chapters' input: {%s}" , exc )
119
- return None
118
+ return []
120
119
121
120
return chapters
122
121
@@ -125,7 +124,8 @@ def get_duplicity_scope() -> DuplicityScopeEnum:
125
124
"""
126
125
Get the duplicity scope parameter value from the action inputs.
127
126
"""
128
- duplicity_scope = get_action_input (DUPLICITY_SCOPE , "both" ).upper ()
127
+ duplicity_scope = get_action_input (DUPLICITY_SCOPE , "both" ).upper () # type: ignore[union-attr]
128
+ # mypy: string is returned as default
129
129
130
130
try :
131
131
return DuplicityScopeEnum (duplicity_scope )
@@ -138,17 +138,18 @@ def get_duplicity_icon() -> str:
138
138
"""
139
139
Get the duplicity icon from the action inputs.
140
140
"""
141
- return get_action_input (DUPLICITY_ICON , "🔔" )
141
+ return get_action_input (DUPLICITY_ICON , "🔔" ) # type: ignore[return-value] # string is returned as default
142
142
143
143
@staticmethod
144
144
def get_published_at () -> bool :
145
145
"""
146
146
Get the published at parameter value from the action inputs.
147
147
"""
148
- return get_action_input (PUBLISHED_AT , "false" ).lower () == "true"
148
+ return get_action_input (PUBLISHED_AT , "false" ).lower () == "true" # type: ignore[union-attr]
149
+ # mypy: string is returned as default
149
150
150
151
@staticmethod
151
- def get_skip_release_notes_labels () -> str :
152
+ def get_skip_release_notes_labels () -> list [ str ] :
152
153
"""
153
154
Get the skip release notes label from the action inputs.
154
155
"""
@@ -163,29 +164,36 @@ def get_verbose() -> bool:
163
164
"""
164
165
Get the verbose parameter value from the action inputs.
165
166
"""
166
- return os .getenv (RUNNER_DEBUG , "0" ) == "1" or get_action_input (VERBOSE ).lower () == "true"
167
+ return (
168
+ os .getenv (RUNNER_DEBUG , "0" ) == "1"
169
+ or get_action_input (VERBOSE ).lower () == "true" # type: ignore[union-attr]
170
+ )
171
+ # mypy: string is returned as default
167
172
168
173
@staticmethod
169
174
def get_release_notes_title () -> str :
170
175
"""
171
176
Get the release notes title from the action inputs.
172
177
"""
173
- return get_action_input (RELEASE_NOTES_TITLE , RELEASE_NOTE_TITLE_DEFAULT )
178
+ return get_action_input (RELEASE_NOTES_TITLE , RELEASE_NOTE_TITLE_DEFAULT ) # type: ignore[return-value]
179
+ # mypy: string is returned as default
174
180
175
181
# Features
176
182
@staticmethod
177
183
def get_warnings () -> bool :
178
184
"""
179
185
Get the warnings parameter value from the action inputs.
180
186
"""
181
- return get_action_input (WARNINGS , "true" ).lower () == "true"
187
+ return get_action_input (WARNINGS , "true" ).lower () == "true" # type: ignore[union-attr]
188
+ # mypy: string is returned as default
182
189
183
190
@staticmethod
184
191
def get_print_empty_chapters () -> bool :
185
192
"""
186
193
Get the print empty chapters parameter value from the action inputs.
187
194
"""
188
- return get_action_input (PRINT_EMPTY_CHAPTERS , "true" ).lower () == "true"
195
+ return get_action_input (PRINT_EMPTY_CHAPTERS , "true" ).lower () == "true" # type: ignore[union-attr]
196
+ # mypy: string is returned as default
189
197
190
198
@staticmethod
191
199
def validate_input (input_value , expected_type : type , error_message : str , error_buffer : list ) -> bool :
@@ -211,7 +219,11 @@ def get_row_format_issue() -> str:
211
219
"""
212
220
if ActionInputs ._row_format_issue is None :
213
221
ActionInputs ._row_format_issue = ActionInputs ._detect_row_format_invalid_keywords (
214
- get_action_input (ROW_FORMAT_ISSUE , "{number} _{title}_ in {pull-requests}" ).strip (), clean = True
222
+ get_action_input (
223
+ ROW_FORMAT_ISSUE , "{number} _{title}_ in {pull-requests}"
224
+ ).strip (), # type: ignore[union-attr]
225
+ clean = True ,
226
+ # mypy: string is returned as default
215
227
)
216
228
return ActionInputs ._row_format_issue
217
229
@@ -222,7 +234,9 @@ def get_row_format_pr() -> str:
222
234
"""
223
235
if ActionInputs ._row_format_pr is None :
224
236
ActionInputs ._row_format_pr = ActionInputs ._detect_row_format_invalid_keywords (
225
- get_action_input (ROW_FORMAT_PR , "{number} _{title}_" ).strip (), clean = True
237
+ get_action_input (ROW_FORMAT_PR , "{number} _{title}_" ).strip (), # type: ignore[union-attr]
238
+ clean = True ,
239
+ # mypy: string is returned as default
226
240
)
227
241
return ActionInputs ._row_format_pr
228
242
@@ -231,7 +245,8 @@ def get_row_format_link_pr() -> bool:
231
245
"""
232
246
Get the value controlling whether the row format should include a 'PR:' prefix when linking to PRs.
233
247
"""
234
- return get_action_input (ROW_FORMAT_LINK_PR , "true" ).lower () == "true"
248
+ return get_action_input (ROW_FORMAT_LINK_PR , "true" ).lower () == "true" # type: ignore[union-attr]
249
+ # mypy: string is returned as default
235
250
236
251
@staticmethod
237
252
def validate_inputs () -> None :
@@ -243,6 +258,9 @@ def validate_inputs() -> None:
243
258
errors = []
244
259
245
260
repository_id = ActionInputs .get_github_repository ()
261
+ if not isinstance (repository_id , str ) or not repository_id .strip ():
262
+ errors .append ("Repository ID must be a non-empty string." )
263
+
246
264
if "/" in repository_id :
247
265
owner , repo_name = ActionInputs .get_github_repository ().split ("/" )
248
266
else :
@@ -260,8 +278,8 @@ def validate_inputs() -> None:
260
278
errors .append ("From tag name must be a string." )
261
279
262
280
chapters = ActionInputs .get_chapters ()
263
- if chapters is None :
264
- errors .append ("Chapters must be a valid yaml array." )
281
+ if len ( chapters ) == 0 :
282
+ errors .append ("Chapters must be a valid yaml array and not empty ." )
265
283
266
284
duplicity_icon = ActionInputs .get_duplicity_icon ()
267
285
if not isinstance (duplicity_icon , str ) or not duplicity_icon .strip () or len (duplicity_icon ) != 1 :
0 commit comments