mirror of
https://github.com/johndoe6345789/goodpackagerepo.git
synced 2026-04-24 13:54:59 +00:00
Fix code review issues: use Boolean types, add error handling, remove unused imports
Co-authored-by: johndoe6345789 <224850594+johndoe6345789@users.noreply.github.com>
This commit is contained in:
@@ -26,8 +26,12 @@ CORS(app)
|
|||||||
|
|
||||||
# Load schema.json for reference
|
# Load schema.json for reference
|
||||||
SCHEMA_PATH = Path(__file__).parent.parent / "schema.json"
|
SCHEMA_PATH = Path(__file__).parent.parent / "schema.json"
|
||||||
with open(SCHEMA_PATH) as f:
|
try:
|
||||||
SCHEMA = json.load(f)
|
with open(SCHEMA_PATH) as f:
|
||||||
|
SCHEMA = json.load(f)
|
||||||
|
except (FileNotFoundError, json.JSONDecodeError) as e:
|
||||||
|
print(f"Error loading schema.json: {e}")
|
||||||
|
SCHEMA = {"ops": {"limits": {"max_request_body_bytes": 2147483648}}} # Default fallback
|
||||||
|
|
||||||
# Configuration is now loaded from database using SQLAlchemy
|
# Configuration is now loaded from database using SQLAlchemy
|
||||||
# schema.json is only used once during initial database setup
|
# schema.json is only used once during initial database setup
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ def load_schema_to_db(schema_path: Path):
|
|||||||
entity_id=entity.id,
|
entity_id=entity.id,
|
||||||
name=field_name,
|
name=field_name,
|
||||||
type=field_data['type'],
|
type=field_data['type'],
|
||||||
optional=1 if field_data.get('optional', False) else 0,
|
optional=field_data.get('optional', False),
|
||||||
normalizations=json.dumps(field_data.get('normalize', []))
|
normalizations=json.dumps(field_data.get('normalize', []))
|
||||||
)
|
)
|
||||||
session.add(field)
|
session.add(field)
|
||||||
@@ -82,7 +82,7 @@ def load_schema_to_db(schema_path: Path):
|
|||||||
entity_id=entity.id,
|
entity_id=entity.id,
|
||||||
field=constraint['field'],
|
field=constraint['field'],
|
||||||
regex=constraint['regex'],
|
regex=constraint['regex'],
|
||||||
when_present=1 if constraint.get('when_present', False) else 0
|
when_present=constraint.get('when_present', False)
|
||||||
)
|
)
|
||||||
session.add(constraint_obj)
|
session.add(constraint_obj)
|
||||||
|
|
||||||
|
|||||||
@@ -6,8 +6,7 @@ This module defines the database schema using SQLAlchemy ORM.
|
|||||||
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from sqlalchemy import (
|
from sqlalchemy import (
|
||||||
create_engine, Column, Integer, String, Text, Boolean, ForeignKey,
|
create_engine, Column, Integer, String, Text, Boolean, ForeignKey
|
||||||
Table, MetaData
|
|
||||||
)
|
)
|
||||||
from sqlalchemy.ext.declarative import declarative_base
|
from sqlalchemy.ext.declarative import declarative_base
|
||||||
from sqlalchemy.orm import relationship, sessionmaker
|
from sqlalchemy.orm import relationship, sessionmaker
|
||||||
@@ -111,7 +110,7 @@ class EntityField(ConfigBase):
|
|||||||
entity_id = Column(Integer, ForeignKey('entities.id', ondelete='CASCADE'), nullable=False)
|
entity_id = Column(Integer, ForeignKey('entities.id', ondelete='CASCADE'), nullable=False)
|
||||||
name = Column(String(255), nullable=False)
|
name = Column(String(255), nullable=False)
|
||||||
type = Column(String(64), nullable=False)
|
type = Column(String(64), nullable=False)
|
||||||
optional = Column(Integer, default=0)
|
optional = Column(Boolean, default=False)
|
||||||
normalizations = Column(Text) # JSON
|
normalizations = Column(Text) # JSON
|
||||||
|
|
||||||
entity = relationship("Entity", back_populates="fields")
|
entity = relationship("Entity", back_populates="fields")
|
||||||
@@ -125,7 +124,7 @@ class EntityConstraint(ConfigBase):
|
|||||||
entity_id = Column(Integer, ForeignKey('entities.id', ondelete='CASCADE'), nullable=False)
|
entity_id = Column(Integer, ForeignKey('entities.id', ondelete='CASCADE'), nullable=False)
|
||||||
field = Column(String(255), nullable=False)
|
field = Column(String(255), nullable=False)
|
||||||
regex = Column(Text, nullable=False)
|
regex = Column(Text, nullable=False)
|
||||||
when_present = Column(Integer, default=0)
|
when_present = Column(Boolean, default=False)
|
||||||
|
|
||||||
entity = relationship("Entity", back_populates="constraints")
|
entity = relationship("Entity", back_populates="constraints")
|
||||||
|
|
||||||
|
|||||||
@@ -53,8 +53,12 @@ def publish_package(token: str, package: Dict[str, Any]) -> None:
|
|||||||
response = requests.put(url, headers=headers, data=content)
|
response = requests.put(url, headers=headers, data=content)
|
||||||
|
|
||||||
if response.status_code == 201:
|
if response.status_code == 201:
|
||||||
data = response.json()
|
try:
|
||||||
print(f"✅ Published {namespace}/{name}:{version}@{variant} (digest: {data['digest'][:16]}...)")
|
data = response.json()
|
||||||
|
digest = data.get('digest', 'unknown')
|
||||||
|
print(f"✅ Published {namespace}/{name}:{version}@{variant} (digest: {digest[:16]}...)")
|
||||||
|
except (ValueError, KeyError):
|
||||||
|
print(f"✅ Published {namespace}/{name}:{version}@{variant}")
|
||||||
elif response.status_code == 409:
|
elif response.status_code == 409:
|
||||||
print(f"⚠️ Package {namespace}/{name}:{version}@{variant} already exists, skipping")
|
print(f"⚠️ Package {namespace}/{name}:{version}@{variant} already exists, skipping")
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user