diff --git a/scripts/check_changelog_format.py b/scripts/check_changelog_format.py index 3d7b76d1bab..153193cd006 100755 --- a/scripts/check_changelog_format.py +++ b/scripts/check_changelog_format.py @@ -57,46 +57,59 @@ def get_referenced_issues(pr_number): # The above returns {'data': {'repository': {'pullRequest': {'closingIssuesReferences': {'edges': [{'node': {'number': 4944}}]}}}}} - ref_edges = ref_result["data"]["repository"]["pullRequest"][ - "closingIssuesReferences" - ]["edges"] - - if not ref_edges: - return [] - - return [edge["node"]["number"] for edge in ref_edges if edge] - + with open(file_name, "r", encoding="utf-8") as file: + for line in file: + line = line.strip() + if not is_valid_line(line): + print(f'Invalid entry in change log: "{line}"') + sys.exit(1) -# Check if a line matches any of the specified patterns -def is_valid_line(line): - patterns = [r"^Fixes:\s*.*$", r"^Implements:\s*.*$", r"^Thanks:\s*.*$"] - for pattern in patterns: - if re.match(pattern, line): - return True - return False + # Handle specific error related to QUOTED_LITERAL token + if "Unexpected QUOTED_LITERAL token" in line: + print("Error: Unexpected QUOTED_LITERAL token in change log") + sys.exit(1) + # The referenced issue number should be valid. + for issue_number in re.findall("#([0-9]+)", line): + issue_number = int(issue_number) + try: + issue = repo.get_issue(number=issue_number) + except github.UnknownObjectException: + print( + f"The changelog entry references an invalid issue #{issue_number}:\n{line}" + ) + sys.exit(1) -def main(): - github_token = os.environ.get("GITHUB_TOKEN") + as_pr = None + try: + as_pr = issue.as_pull_request() + except github.UnknownObjectException: + # Not a pull request + pass - if not github_token: - print("Please populate the GITHUB_TOKEN environment variable.") - sys.exit(1) + # Accept references to PR itself. + if as_pr: + if issue_number != this_pr_number: + print( + f"The changelog for PR #{this_pr_number} references another PR #{issue_number}" + ) + sys.exit(1) + changelog_issues = pr_issues + else: + changelog_issues.add(issue_number) - github_obj = github.Github(github_token) - repo = github_obj.get_repo("timescale/timescaledb") - # Get the file name from the command line argument - if len(sys.argv) != 2: - print("Please provide a file name as a command-line argument.") + if changelog_issues != pr_issues: + print( + "Instead of " + + (f"the issues {pr_issues}" if pr_issues else "no issues") + + f" linked to the PR #{this_pr_number}, the changelog references " + + (f"the issues {changelog_issues}" if changelog_issues else "no issues") + ) sys.exit(1) - file_name = sys.argv[1] - this_pr_number = int(os.environ["PR_NUMBER"]) - pr_issues = set(get_referenced_issues(this_pr_number)) - # Read the file and check non-empty lines - changelog_issues = set() - with open(file_name, "r", encoding="utf-8") as file: +if __name__ == "__main__": + main() for line in file: line = line.strip() if not is_valid_line(line): diff --git a/scripts/cmake_format_all.sh b/scripts/cmake_format_all.sh index 7bfd828f706..50d060ac266 100755 --- a/scripts/cmake_format_all.sh +++ b/scripts/cmake_format_all.sh @@ -3,5 +3,5 @@ SCRIPTDIR=$(cd "$(dirname $0)" || exit; pwd) BASEDIR=$(dirname $SCRIPTDIR) -find $BASEDIR -name CMakeLists.txt -exec cmake-format -i {} + +find $BASEDIR -name CMakeLists.txt -exec cmake-format -i {} + || { echo 'Error: Failed to run cmake-format command'; exit 1; } find $BASEDIR/src $BASEDIR/test $BASEDIR/tsl -name '*.cmake' -exec cmake-format -i {} +