Skip to content

Commit

Permalink
Store target in Koji build tag event (#2489)
Browse files Browse the repository at this point in the history
Store target in Koji build tag event

This should make trigger links in the dashboard work for jobs triggered by Koji tagging events.
Related to #2379.

Reviewed-by: Laura Barcziová
  • Loading branch information
2 parents 567ccab + c55d2b0 commit 54858a7
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""Store target in Koji build tag event
Revision ID: 2fdbdcd581f5
Revises: 64a51b961c28
Create Date: 2024-08-01 15:00:55.879659
"""

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = "2fdbdcd581f5"
down_revision = "64a51b961c28"
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column("koji_build_tags", sa.Column("target", sa.String(), nullable=True))
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column("koji_build_tags", "target")
# ### end Alembic commands ###
11 changes: 10 additions & 1 deletion packit_service/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,8 @@ def get_branch_name(self) -> Optional[str]:
project_event_object = self.get_project_event_object()
if isinstance(project_event_object, GitBranchModel):
return project_event_object.name
if isinstance(project_event_object, KojiBuildTagModel):
return project_event_object.target
return None

def get_release_tag(self) -> Optional[str]:
Expand Down Expand Up @@ -1259,6 +1261,7 @@ class KojiBuildTagModel(BuildsAndTestsConnector, Base):
id = Column(Integer, primary_key=True) # our database PK
task_id = Column(String, index=True)
koji_tag_name = Column(String, index=True)
target = Column(String)
project_id = Column(Integer, ForeignKey("git_projects.id"), index=True)
project = relationship("GitProjectModel", back_populates="koji_build_tags")

Expand All @@ -1270,6 +1273,7 @@ def get_or_create(
cls,
task_id: str,
koji_tag_name: str,
target: Optional[str],
namespace: str,
repo_name: str,
project_url: str,
Expand All @@ -1289,6 +1293,7 @@ def get_or_create(
koji_build_tag = KojiBuildTagModel()
koji_build_tag.task_id = task_id
koji_build_tag.koji_tag_name = koji_tag_name
koji_build_tag.target = target
koji_build_tag.project_id = project.id
session.add(koji_build_tag)
return koji_build_tag
Expand All @@ -1301,7 +1306,7 @@ def get_by_id(cls, id_: int) -> Optional["KojiBuildTagModel"]:
def __repr__(self):
return (
f"KojiBuildTagModel(task_id={self.task_id}, koji_tag_name={self.koji_tag_name}, "
f"project={self.project})"
f"target={self.target}, project={self.project})"
)


Expand Down Expand Up @@ -1447,9 +1452,13 @@ def add_koji_build_tag_event(
repo_name: str,
project_url: str,
) -> Tuple[KojiBuildTagModel, "ProjectEventModel"]:
target = None
if sidetag := SidetagModel.get_by_koji_name(koji_tag_name):
target = sidetag.target
koji_build_tag = KojiBuildTagModel.get_or_create(
task_id=task_id,
koji_tag_name=koji_tag_name,
target=target,
namespace=namespace,
repo_name=repo_name,
project_url=project_url,
Expand Down
1 change: 1 addition & 0 deletions tests/integration/test_bodhi_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -986,6 +986,7 @@ def test_bodhi_update_from_sidetag(koji_build_tagged, missing_dependency):
flexmock(KojiBuildTagModel).should_receive("get_or_create").with_args(
task_id=str(task_id),
koji_tag_name=sidetag_name,
target="f40",
namespace="rpms",
repo_name="python-specfile",
project_url="https://src.fedoraproject.org/rpms/python-specfile",
Expand Down

0 comments on commit 54858a7

Please sign in to comment.