Skip to content

Commit 17747f3

Browse files
authored
Fix bugs in validate-changelog-yaml.py (apache#4414)
1 parent 500fbe0 commit 17747f3

1 file changed

Lines changed: 32 additions & 5 deletions

File tree

.github/scripts/validate-changelog-yaml.py

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
- Contains required 'authors' field with at least one author
3030
- Each author has a 'name' field (non-empty string)
3131
- Contains either 'links' or 'issues' field (or both)
32-
- If 'issues' is present, it must be an integer not exceeding 17000
32+
- If 'issues' is present, it must be a list of integers not exceeding 17000
33+
- If 'links' is present, each entry must be a mapping with 'name' and 'url' fields (not a plain string)
3334
- Comment block is removed
3435
"""
3536

@@ -116,12 +117,38 @@ def validate_changelog_yaml(file_path):
116117

117118
# Validate 'issues' field if present
118119
if 'issues' in data:
119-
if not isinstance(data['issues'], int):
120-
print(f"::error file={file_path}::Field 'issues' must be an integer")
120+
if not isinstance(data['issues'], list):
121+
print(f"::error file={file_path}::Field 'issues' must be a list of integers")
121122
return False
122-
if data['issues'] > 17000:
123-
print(f"::error file={file_path}::Field 'issues' value {data['issues']} points to a non-existing github PR. Did you intend to reference a JIRA issue, please use 'links'.")
123+
for i, issue in enumerate(data['issues']):
124+
if not isinstance(issue, int):
125+
print(f"::error file={file_path}::Field 'issues' entry {i} must be an integer")
126+
return False
127+
if issue > 17000:
128+
print(f"::error file={file_path}::Field 'issues' value {issue} points to a non-existing github PR. Did you intend to reference a JIRA issue, please use 'links'.")
129+
return False
130+
131+
# Validate 'links' field if present
132+
if 'links' in data:
133+
if not isinstance(data['links'], list):
134+
print(f"::error file={file_path}::Field 'links' must be a list")
124135
return False
136+
for i, link in enumerate(data['links']):
137+
if not isinstance(link, dict):
138+
print(f"::error file={file_path}::Link {i} must be a mapping with 'name' and 'url' fields, not a plain string")
139+
return False
140+
if 'name' not in link or not link['name']:
141+
print(f"::error file={file_path}::Link {i} missing or empty 'name' field")
142+
return False
143+
if not isinstance(link['name'], str) or not link['name'].strip():
144+
print(f"::error file={file_path}::Link {i} 'name' must be a non-empty string")
145+
return False
146+
if 'url' not in link or not link['url']:
147+
print(f"::error file={file_path}::Link {i} missing or empty 'url' field")
148+
return False
149+
if not isinstance(link['url'], str) or not link['url'].strip():
150+
print(f"::error file={file_path}::Link {i} 'url' must be a non-empty string")
151+
return False
125152

126153
# Validate that comments are removed
127154
for not_allowed in not_allowed_text:

0 commit comments

Comments
 (0)