Skip to content

Commit

Permalink
Add a table to keep the firefox-nightly version
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielBusta committed May 9, 2024
1 parent c0edcfb commit a131661
Show file tree
Hide file tree
Showing 3 changed files with 164 additions and 1 deletion.
31 changes: 30 additions & 1 deletion api/src/shipit_api/admin/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
rendered_hook_payload,
)
from shipit_api.common.config import HG_PREFIX, PROJECT_NAME, PULSE_ROUTE_REBUILD_PRODUCT_DETAILS, SCOPE_PREFIX
from shipit_api.common.models import DisabledProduct, Phase, Release, Signoff, XPIRelease
from shipit_api.common.models import DisabledProduct, Phase, Release, Signoff, Version, XPIRelease
from shipit_api.public.api import get_disabled_products, list_releases

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -375,3 +375,32 @@ def get_signoff_emails(phases):
additional_shipit_emails.update({signoff.completed_by for signoff in _phase.signoffs if signoff.completed_by is not None})

return list(additional_shipit_emails)


def get_product_version(product):
version = Version.query.filter_by(product_name=product).first()
if version:
return version.current_version
else:
return {"error": "Product version not found."}, 404


def update_product_version(product, body):
version = Version.query.filter_by(product_name=product).first()
if version:
version.current_version = body["version"]
current_app.db.session.commit()
return {"message": "Product version updated successfully.", "version": version.current_version, "product": version.product_name}, 200
else:
return {"error": "Product not found"}, 404


def create_product_version(product, body):
existing_product = Version.query.filter_by(product_name=product).first()
if existing_product:
return {"error": "Product already exists"}, 409
else:
new_version = Version(product_name=product, current_version=body["version"])
current_app.db.session.add(new_version)
current_app.db.session.commit()
return {"message": "Product version created successfully.", "version": new_version.current_version, "product": new_version.product_name}, 201
127 changes: 127 additions & 0 deletions api/src/shipit_api/admin/api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,133 @@ paths:
"409":
description: Already submitted
content: {}
/versions/{product}:
get:
summary: Get the current version for the given product
operationId: shipit_api.admin.api.get_product_version
parameters:
- name: product
in: path
description: product name
required: true
schema:
type: string
responses:
"200":
description: The current version for the given product
content:
text/plain:
schema:
type: string
example: "127.0a1"
"404":
description: Product version not found
content:
application/json:
schema:
type: object
properties:
error:
type: string
example: "Product version not found."
post:
summary: Create a new product version
operationId: shipit_api.admin.api.create_product_version
parameters:
- name: product
in: path
description: The product name for which the version is to be updated
required: true
schema:
type: string
requestBody:
description: Initial version for a new product
content:
application/json:
schema:
type: object
properties:
version:
type: string
example: "128.0a1"
required: true
responses:
"201":
description: Product version created successfully
content:
application/json:
schema:
type: object
properties:
message:
type: string
example: "Product version created successfully."
version:
type: string
example: "128.0a1"
product:
type: string
example: "firefox-nightly"
"409":
description: Product version already exists
content:
application/json:
schema:
type: object
properties:
error:
type: string
example: "Product version already exists."
put:
summary: Update an existing product's version
operationId: shipit_api.admin.api.update_product_version
parameters:
- name: product
in: path
description: The product name for which the version is to be updated
required: true
schema:
type: string
requestBody:
description: A valid version for the product
content:
application/json:
schema:
type: object
properties:
version:
type: string
example: "129.0a1"
required: true
responses:
"200":
description: Product version updated successfully
content:
application/json:
schema:
type: object
properties:
message:
type: string
example: "Product version updated successfully."
version:
type: string
example: "128.0a1"
product:
type: string
example: "firefox-nightly"
"404":
description: Product version not found
content:
application/json:
schema:
type: object
properties:
error:
type: string
example: "Product version not found."


components:
schemas:
ReleaseInput:
Expand Down
7 changes: 7 additions & 0 deletions api/src/shipit_api/common/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,3 +264,10 @@ def json(self):
"completed": self.completed or "",
"phases": [p.json for p in self.phases],
}


class Version(db.Model):
__tablename__ = "shipit_api_versions"
id = sa.Column(sa.Integer, primary_key=True)
product_name = sa.Column(sa.String, unique=True, nullable=False)
current_version = sa.Column(sa.String, nullable=False)

0 comments on commit a131661

Please sign in to comment.