Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

frontend: add relationship between actions and projects/builds #2805

Merged
merged 1 commit into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""
Connect Copr to Actions

Revision ID: 08dd42f4c304
Create Date: 2023-08-03 15:45:53.527538
"""

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '08dd42f4c304'
down_revision = 'daa62cd0743d'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated this.

branch_labels = None
depends_on = None


def upgrade():
op.add_column('action', sa.Column('copr_id', sa.Integer(), nullable=True))
op.create_index(op.f('ix_action_copr_id'), 'action', ['copr_id'], unique=False)
op.create_foreign_key(None, 'action', 'copr', ['copr_id'], ['id'])


def downgrade():
op.drop_constraint(None, 'action', type_='foreignkey')
op.drop_index(op.f('ix_action_copr_id'), table_name='action')
op.drop_column('action', 'copr_id')
2 changes: 1 addition & 1 deletion frontend/coprs_frontend/commands/rawhide_to_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def rawhide_to_release_function(rawhide_chroot, dest_chroot, retry_forked):
))

if len(data["builds"]):
actions_logic.ActionsLogic.send_rawhide_to_release(data)
actions_logic.ActionsLogic.send_rawhide_to_release(copr, data)

db.session.commit()

Expand Down
22 changes: 16 additions & 6 deletions frontend/coprs_frontend/coprs/logic/actions_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ def send_createrepo(cls, copr, dirnames=None, chroots=None, devel=None,
object_id=0,
data=json.dumps(data_dict),
created_on=int(time.time()),
copr_id=copr.id,
)
if priority is not None:
action.priority = priority
Expand All @@ -148,7 +149,8 @@ def send_delete_copr(cls, copr):
object_type="copr",
object_id=copr.id,
data=json.dumps(data_dict),
created_on=int(time.time()))
created_on=int(time.time()),
copr_id=copr.id)
db.session.add(action)
return action

Expand Down Expand Up @@ -200,7 +202,8 @@ def send_delete_build(cls, build):
object_type="build",
object_id=build.id,
data=json.dumps(cls.get_build_delete_data(build)),
created_on=int(time.time())
created_on=int(time.time()),
copr_id=build.copr.id
)
db.session.add(action)
return action
Expand Down Expand Up @@ -246,7 +249,8 @@ def send_delete_multiple_builds(cls, builds):
action_type=ActionTypeEnum("delete"),
object_type="builds",
data=json.dumps(data),
created_on=int(time.time())
created_on=int(time.time()),
copr_id=builds[0].copr.id,
)
db.session.add(action)
return action
Expand Down Expand Up @@ -286,7 +290,8 @@ def send_update_comps(cls, chroot):
action_type=ActionTypeEnum("update_comps"),
object_type="copr_chroot",
data=json.dumps(data_dict),
created_on=int(time.time())
created_on=int(time.time()),
copr_id=chroot.copr.id,
)
db.session.add(action)
return action
Expand All @@ -308,17 +313,19 @@ def send_create_gpg_key(cls, copr):
object_type="copr",
data=json.dumps(data_dict),
created_on=int(time.time()),
copr_id=copr.id,
)
db.session.add(action)
return action

@classmethod
def send_rawhide_to_release(cls, data):
def send_rawhide_to_release(cls, copr, data):
action = models.Action(
action_type=ActionTypeEnum("rawhide_to_release"),
object_type="None",
data=json.dumps(data),
created_on=int(time.time()),
copr_id=copr.id,
)
db.session.add(action)
return action
Expand All @@ -338,6 +345,7 @@ def send_fork_copr(cls, src, dst, builds_map):
new_value="{0}".format(dst.full_name),
data=json.dumps({"user": dst.owner_name, "copr": dst.name, "builds_map": builds_map}),
created_on=int(time.time()),
copr_id=dst.id,
)
db.session.add(action)
return action
Expand All @@ -364,6 +372,7 @@ def send_build_module(cls, copr, module):
new_value="",
data=json.dumps(data),
created_on=int(time.time()),
copr_id=copr.id,
)
db.session.add(action)
return action
Expand All @@ -386,7 +395,8 @@ def send_delete_chroot(cls, copr_chroot):
object_type="chroot",
object_id=None,
data=json.dumps(data_dict),
created_on=int(time.time())
created_on=int(time.time()),
copr_id=copr_chroot.copr.id,
)
db.session.add(action)
return action
Expand Down
17 changes: 9 additions & 8 deletions frontend/coprs_frontend/coprs/logic/coprs_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -840,8 +840,8 @@ def send_delete_dirs_action(cls):
"""
copr_ids = cls.get_copr_ids_with_pr_dirs().all()

remove_dirs = []
for copr_id in copr_ids:
remove_dirs = []
copr_id = copr_id[0]
all_dirs = cls.get_all_with_latest_submitted_build(copr_id)
for copr_dir in all_dirs:
Expand All @@ -857,13 +857,14 @@ def send_delete_dirs_action(cls):
cls.delete_with_builds(dir_object)
remove_dirs.append(dirname)

action = models.Action(
action_type=ActionTypeEnum("remove_dirs"),
object_type="copr",
data=json.dumps(remove_dirs),
created_on=int(time.time()))

db.session.add(action)
action = models.Action(
action_type=ActionTypeEnum("remove_dirs"),
object_type="copr",
data=json.dumps(remove_dirs),
created_on=int(time.time()),
copr_id=copr_id,
)
db.session.add(action)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is weird, is the indent change intentional?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes. The send_delete_dirs_action works with multiple copr ids and I was thinking whether to create some new attribute copr_ids (array) but then I realised the object_type is "copr" so it confused me a bit and I was wondering if creating action for each copr_id will solve this

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, this sounds good, thanks!


@classmethod
def copr_name_from_dirname(cls, dirname):
Expand Down
3 changes: 3 additions & 0 deletions frontend/coprs_frontend/coprs/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2150,6 +2150,9 @@ class Action(db.Model, helpers.Serializer):
# time ended as returned by int(time.time())
ended_on = db.Column(db.Integer, index=True)

copr_id = db.Column(db.Integer, db.ForeignKey("copr.id"), nullable=True, index=True)
copr = db.relationship("Copr", backref=db.backref("actions"))

def __str__(self):
return self.__unicode__()

Expand Down