mirror of
https://pagure.io/fm-orchestrator.git
synced 2026-02-03 05:03:43 +08:00
Allow submitting optional parameters such as copr_owner and copr_project
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
"""Add optional columns for copr
|
||||
|
||||
Revision ID: 474697622859
|
||||
Revises: 0ef60c3ed440
|
||||
Create Date: 2017-02-21 11:18:22.304038
|
||||
|
||||
"""
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '474697622859'
|
||||
down_revision = '0ef60c3ed440'
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
def upgrade():
|
||||
op.add_column('module_builds', sa.Column('copr_owner', sa.String(), nullable=True))
|
||||
op.add_column('module_builds', sa.Column('copr_project', sa.String(), nullable=True))
|
||||
|
||||
|
||||
def downgrade():
|
||||
op.drop_column('module_builds', 'copr_owner')
|
||||
op.drop_column('module_builds', 'copr_project')
|
||||
@@ -101,6 +101,8 @@ class ModuleBuild(RidaBase):
|
||||
state_reason = db.Column(db.String)
|
||||
modulemd = db.Column(db.String, nullable=False)
|
||||
koji_tag = db.Column(db.String) # This gets set after 'wait'
|
||||
copr_owner = db.Column(db.String)
|
||||
copr_project = db.Column(db.String)
|
||||
scmurl = db.Column(db.String)
|
||||
owner = db.Column(db.String, nullable=False)
|
||||
time_submitted = db.Column(db.DateTime, nullable=False)
|
||||
@@ -155,7 +157,8 @@ class ModuleBuild(RidaBase):
|
||||
% type(event).__name__)
|
||||
|
||||
@classmethod
|
||||
def create(cls, session, conf, name, stream, version, modulemd, scmurl, username):
|
||||
def create(cls, session, conf, name, stream, version, modulemd, scmurl, username,
|
||||
copr_owner=None, copr_project=None):
|
||||
now = datetime.utcnow()
|
||||
module = cls(
|
||||
name=name,
|
||||
@@ -165,7 +168,9 @@ class ModuleBuild(RidaBase):
|
||||
modulemd=modulemd,
|
||||
scmurl=scmurl,
|
||||
owner=username,
|
||||
time_submitted=now
|
||||
time_submitted=now,
|
||||
copr_owner=copr_owner,
|
||||
copr_project=copr_project,
|
||||
)
|
||||
session.add(module)
|
||||
session.commit()
|
||||
|
||||
@@ -526,17 +526,17 @@ def record_component_builds(scm, mmd, module, initial_batch = 1):
|
||||
return batch
|
||||
|
||||
|
||||
def submit_module_build_from_yaml(username, yaml):
|
||||
def submit_module_build_from_yaml(username, yaml, optional_params={}):
|
||||
mmd = load_mmd(yaml)
|
||||
return submit_module_build(username, None, mmd, None, yaml)
|
||||
return submit_module_build(username, None, mmd, None, yaml, optional_params)
|
||||
|
||||
|
||||
def submit_module_build_from_scm(username, url, allow_local_url=False):
|
||||
def submit_module_build_from_scm(username, url, allow_local_url=False, optional_params={}):
|
||||
mmd, scm, yaml = _fetch_mmd(url, allow_local_url)
|
||||
return submit_module_build(username, url, mmd, scm, yaml)
|
||||
return submit_module_build(username, url, mmd, scm, yaml, optional_params)
|
||||
|
||||
|
||||
def submit_module_build(username, url, mmd, scm, yaml):
|
||||
def submit_module_build(username, url, mmd, scm, yaml, optional_params={}):
|
||||
# Import it here, because SCM uses utils methods
|
||||
# and fails to import them because of dep-chain.
|
||||
import module_build_service.scm
|
||||
@@ -569,7 +569,8 @@ def submit_module_build(username, url, mmd, scm, yaml):
|
||||
version=str(mmd.version),
|
||||
modulemd=yaml,
|
||||
scmurl=url,
|
||||
username=username
|
||||
username=username,
|
||||
**optional_params
|
||||
)
|
||||
|
||||
record_component_builds(scm, mmd, module)
|
||||
|
||||
@@ -124,18 +124,28 @@ class ModuleBuildAPI(MethodView):
|
||||
log.error("The submitted scmurl %r is not valid" % url)
|
||||
raise Unauthorized("The submitted scmurl %s is not valid" % url)
|
||||
|
||||
return submit_module_build_from_scm(username, url, allow_local_url=False)
|
||||
forbidden_params = [k for k in r if not hasattr(models.ModuleBuild, k)]
|
||||
if forbidden_params:
|
||||
raise ValidationError('The request contains unspecified parameters: {}'.format(", ".join(forbidden_params)))
|
||||
|
||||
optional_params = {k: v for k, v in r.items() if k != "scmurl"}
|
||||
return submit_module_build_from_scm(username, url, allow_local_url=False, optional_params=optional_params)
|
||||
|
||||
def post_file(self, username):
|
||||
if not conf.yaml_submit_allowed:
|
||||
raise Unauthorized("YAML submission is not enabled")
|
||||
|
||||
forbidden_params = [k for k in request.form if not hasattr(models.ModuleBuild, k)]
|
||||
if forbidden_params:
|
||||
raise ValidationError('The request contains unspecified parameters: {}'.format(", ".join(forbidden_params)))
|
||||
|
||||
try:
|
||||
r = request.files["yaml"]
|
||||
except:
|
||||
log.error('Invalid file submitted')
|
||||
raise ValidationError('Invalid file submitted')
|
||||
|
||||
return submit_module_build_from_yaml(username, r.read())
|
||||
return submit_module_build_from_yaml(username, r.read(), optional_params=dict(request.form.items()))
|
||||
|
||||
def patch(self, id):
|
||||
username, groups = module_build_service.auth.get_user(request)
|
||||
|
||||
Reference in New Issue
Block a user