mirror of
https://github.com/aljazceru/turso.git
synced 2025-12-17 08:34:19 +01:00
uv run ruff format && uv run ruff check --fix
This commit is contained in:
@@ -17,8 +17,7 @@ cur_init = con_init.cursor()
|
||||
|
||||
tbl_len = cur_init.execute("SELECT count FROM tables").fetchone()[0]
|
||||
selected_tbl = get_random() % tbl_len
|
||||
tbl_schema = json.loads(cur_init.execute(
|
||||
f"SELECT schema FROM schemas WHERE tbl = {selected_tbl}").fetchone()[0])
|
||||
tbl_schema = json.loads(cur_init.execute(f"SELECT schema FROM schemas WHERE tbl = {selected_tbl}").fetchone()[0])
|
||||
|
||||
tbl_name = f"tbl_{selected_tbl}"
|
||||
|
||||
@@ -29,8 +28,7 @@ except Exception as e:
|
||||
exit(0)
|
||||
|
||||
cur = con.cursor()
|
||||
cur.execute(
|
||||
"SELECT sql FROM sqlite_schema WHERE type = 'table' AND name = '" + tbl_name + "'")
|
||||
cur.execute("SELECT sql FROM sqlite_schema WHERE type = 'table' AND name = '" + tbl_name + "'")
|
||||
|
||||
result = cur.fetchone()
|
||||
|
||||
@@ -47,10 +45,8 @@ cur.execute("ALTER TABLE " + tbl_name + " RENAME TO " + tbl_name + "_old")
|
||||
con.rollback()
|
||||
|
||||
cur = con.cursor()
|
||||
cur.execute(
|
||||
"SELECT sql FROM sqlite_schema WHERE type = 'table' AND name = '" + tbl_name + "'")
|
||||
cur.execute("SELECT sql FROM sqlite_schema WHERE type = 'table' AND name = '" + tbl_name + "'")
|
||||
|
||||
schema_after = cur.fetchone()[0]
|
||||
|
||||
always(schema_before == schema_after,
|
||||
"schema should be the same after rollback", {})
|
||||
always(schema_before == schema_after, "schema should be the same after rollback", {})
|
||||
|
||||
@@ -45,4 +45,3 @@ def main() -> None:
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
|
||||
@@ -52,4 +52,3 @@ def main() -> None:
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
|
||||
@@ -1,96 +1,100 @@
|
||||
#!/usr/bin/env python3
|
||||
import subprocess
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
from collections import defaultdict
|
||||
|
||||
|
||||
def get_git_merges(prev_version):
|
||||
"""Get merge commits since the previous version tag."""
|
||||
try:
|
||||
command = f"git log {prev_version}..HEAD | grep 'Merge '"
|
||||
result = subprocess.run(command, shell=True, check=True, text=True, capture_output=True)
|
||||
|
||||
|
||||
merge_lines = []
|
||||
for line in result.stdout.strip().split('\n'):
|
||||
for line in result.stdout.strip().split("\n"):
|
||||
if not line.strip() or "Merge:" in line:
|
||||
continue
|
||||
|
||||
|
||||
# Extract the commit message and author
|
||||
match = re.search(r"Merge '([^']+)' from ([^(]+)", line)
|
||||
if match:
|
||||
message = match.group(1).strip()
|
||||
author = match.group(2).strip()
|
||||
merge_lines.append((message, author))
|
||||
|
||||
|
||||
return merge_lines
|
||||
except subprocess.CalledProcessError as e:
|
||||
print(f"Error: Failed to get git merge logs: {e}")
|
||||
return []
|
||||
|
||||
|
||||
def categorize_commits(merge_lines):
|
||||
"""Categorize commits into Added, Updated, Fixed."""
|
||||
categories = defaultdict(list)
|
||||
|
||||
|
||||
for message, author in merge_lines:
|
||||
# Format the line for our output
|
||||
formatted_line = f"* {message} ({author})"
|
||||
|
||||
|
||||
# Categorize based on keywords in the commit message
|
||||
message_lower = message.lower()
|
||||
if re.search(r'add|new|implement|support|initial|introduce', message_lower):
|
||||
categories['Added'].append(formatted_line)
|
||||
elif re.search(r'fix|bug|issue|error|crash|resolve|typo', message_lower):
|
||||
categories['Fixed'].append(formatted_line)
|
||||
if re.search(r"add|new|implement|support|initial|introduce", message_lower):
|
||||
categories["Added"].append(formatted_line)
|
||||
elif re.search(r"fix|bug|issue|error|crash|resolve|typo", message_lower):
|
||||
categories["Fixed"].append(formatted_line)
|
||||
else:
|
||||
categories['Updated'].append(formatted_line)
|
||||
|
||||
categories["Updated"].append(formatted_line)
|
||||
|
||||
return categories
|
||||
|
||||
|
||||
def format_changelog(categories):
|
||||
"""Format the categorized commits into a changelog."""
|
||||
changelog = "## Unreleased\n"
|
||||
|
||||
for category in ['Added', 'Updated', 'Fixed']:
|
||||
|
||||
for category in ["Added", "Updated", "Fixed"]:
|
||||
changelog += f"### {category}\n"
|
||||
|
||||
|
||||
if not categories[category]:
|
||||
changelog += "\n"
|
||||
continue
|
||||
|
||||
|
||||
for commit_message in categories[category]:
|
||||
changelog += f"{commit_message}\n"
|
||||
|
||||
|
||||
changelog += "\n"
|
||||
|
||||
|
||||
return changelog
|
||||
|
||||
|
||||
def main():
|
||||
if len(sys.argv) != 2:
|
||||
print("Usage: python changelog_generator.py <previous_version_tag>")
|
||||
print("Example: python changelog_generator.py v0.0.17")
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
prev_version = sys.argv[1]
|
||||
|
||||
|
||||
# Get merge commits since previous version
|
||||
merge_lines = get_git_merges(prev_version)
|
||||
|
||||
|
||||
if not merge_lines:
|
||||
print(f"No merge commits found since {prev_version}")
|
||||
return
|
||||
|
||||
|
||||
# Categorize commits
|
||||
categories = categorize_commits(merge_lines)
|
||||
|
||||
|
||||
# Format changelog
|
||||
changelog = format_changelog(categories)
|
||||
|
||||
|
||||
# Output changelog
|
||||
print(changelog)
|
||||
|
||||
|
||||
# Optionally write to file
|
||||
write_to_file = input("Write to CHANGELOG.md? (y/n): ")
|
||||
if write_to_file.lower() == 'y':
|
||||
if write_to_file.lower() == "y":
|
||||
try:
|
||||
with open("CHANGELOG.md", "r") as f:
|
||||
content = f.read()
|
||||
@@ -102,5 +106,6 @@ def main():
|
||||
f.write(changelog)
|
||||
print("Created new CHANGELOG.md file")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
@@ -135,9 +135,9 @@ INSERT INTO t VALUES (zeroblob(1024 - 1), zeroblob(1024 - 2), zeroblob(1024 - 3)
|
||||
def run_test(self, name: str, sql: str, expected: str) -> None:
|
||||
console.test(f"Running test: {name}", _stack_offset=2)
|
||||
actual = self.shell.execute(sql)
|
||||
assert actual == expected, (
|
||||
f"Test failed: {name}\nSQL: {sql}\nExpected:\n{repr(expected)}\nActual:\n{repr(actual)}"
|
||||
)
|
||||
assert (
|
||||
actual == expected
|
||||
), f"Test failed: {name}\nSQL: {sql}\nExpected:\n{repr(expected)}\nActual:\n{repr(actual)}"
|
||||
|
||||
def run_debug(self, sql: str):
|
||||
console.debug(f"debugging: {sql}", _stack_offset=2)
|
||||
|
||||
Reference in New Issue
Block a user