Skip to content

Commit fb71994

Browse files
Post a comment per dist-git PR about transition (#3012)
Post a comment per dist-git PR about transition Fixes #3008 Should look like: Reviewed-by: gemini-code-assist[bot] Reviewed-by: Maja Massarini Reviewed-by: Nikola Forró Reviewed-by: František Lachman <flachman@redhat.com>
2 parents c1b2dfb + 8f6d0c2 commit fb71994

File tree

4 files changed

+92
-1
lines changed

4 files changed

+92
-1
lines changed

packit_service/constants.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,3 +341,23 @@ def from_number(number: int):
341341

342342
# Default URL of the logdetective-packit interface server for sending the Log Detective requests.
343343
LOGDETECTIVE_PACKIT_SERVER_URL = "https://logdetective01.fedorainfracloud.org"
344+
345+
# CI Transition comment for Fedora dist-git PRs
346+
# TODO: Remove this after March 2026
347+
# https://github.com/packit/packit-service/issues/3008
348+
FEDORA_CI_TRANSITION_COMMENT = (
349+
"**:information_source: Fedora CI Transition Notice**\n\n"
350+
"Packit is now the default CI system for Fedora dist-git. "
351+
"For more information, see:\n"
352+
"- [Fedora Discussion: Packit as Fedora dist-git CI - Final Phase]"
353+
"(https://discussion.fedoraproject.org/t/packit-as-fedora-dist-git-ci-final-phase/180160)\n"
354+
"- [Packit Fedora CI Documentation](https://packit.dev/fedora-ci)\n\n"
355+
"**Retriggering jobs:**\n"
356+
"- Scratch build: `/packit-ci scratch-build`\n"
357+
"- Tests: `/packit-ci test`\n\n"
358+
"- See more in the "
359+
"[retriggering documentation](https://packit.dev/fedora-ci/retriggering).\n\n"
360+
"Questions? Reach us at [#packit:fedora.im](https://matrix.to/#/#packit:fedora.im)\n\n"
361+
"---\n"
362+
"*This notice is posted during the introduction period (until the end of March 2026).*"
363+
)

packit_service/worker/jobs.py

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,20 @@
1414

1515
import celery
1616
from ogr.exceptions import GithubAppNotInstalledError
17-
from packit.config import JobConfig, JobConfigTriggerType, JobConfigView, JobType, PackageConfig
17+
from packit.config import (
18+
Deployment,
19+
JobConfig,
20+
JobConfigTriggerType,
21+
JobConfigView,
22+
JobType,
23+
PackageConfig,
24+
)
1825
from packit.utils import nested_get
1926

2027
from packit_service.config import ServiceConfig
2128
from packit_service.constants import (
2229
COMMENT_REACTION,
30+
FEDORA_CI_TRANSITION_COMMENT,
2331
HELP_COMMENT_DESCRIPTION,
2432
HELP_COMMENT_EPILOG,
2533
HELP_COMMENT_PROG,
@@ -88,6 +96,8 @@
8896
from packit_service.worker.monitoring import Pushgateway
8997
from packit_service.worker.parser import Parser
9098
from packit_service.worker.reporting import BaseCommitStatus
99+
from packit_service.worker.reporting.enums import DuplicateCheckMode
100+
from packit_service.worker.reporting.utils import has_identical_comment_in_comments
91101
from packit_service.worker.result import TaskResults
92102

93103
logger = logging.getLogger(__name__)
@@ -484,6 +494,44 @@ def report_task_accepted(
484494

485495
self.push_copr_metrics(handler_kls, number_of_build_targets)
486496

497+
def _post_fedora_ci_transition_comment(self) -> None:
498+
"""
499+
Post a one-time CI introduction comment on the dist-git PR.
500+
501+
Only posts if the comment doesn't already exist.
502+
503+
TODO: Remove this method after March 2026 (end of introduction period).
504+
https://github.com/packit/packit-service/issues/3008
505+
"""
506+
# Check if event is a PR-related event (has pr_id and pull_request_object)
507+
if not (
508+
isinstance(self.event, (pagure.pr.Action, pagure.pr.Comment))
509+
and (pr := self.event.pull_request_object)
510+
):
511+
return
512+
513+
try:
514+
comments = pr.get_comments()
515+
516+
# Check if we already posted this comment
517+
packit_user = (
518+
"packit" if self.service_config.deployment == Deployment.prod else "packit-stg"
519+
)
520+
if has_identical_comment_in_comments(
521+
body=FEDORA_CI_TRANSITION_COMMENT,
522+
comments=comments,
523+
packit_user=packit_user,
524+
mode=DuplicateCheckMode.check_all_comments,
525+
):
526+
logger.debug("CI transition comment already exists on PR.")
527+
return
528+
529+
pr.comment(FEDORA_CI_TRANSITION_COMMENT)
530+
logger.info(f"Posted CI transition comment on dist-git PR #{self.event.pr_id}")
531+
except Exception as ex:
532+
# Don't fail the job if we can't post the comment
533+
logger.warning(f"Failed to post CI transition comment: {ex}")
534+
487535
def report_task_accepted_for_fedora_ci(self, handler_kls: type[FedoraCIJobHandler]):
488536
"""
489537
For CI-related dist-git PR comment events report the initial status
@@ -639,6 +687,8 @@ def process_fedora_ci_jobs(self) -> list[TaskResults]:
639687

640688
# TODO: add allowlist checks here
641689

690+
self._post_fedora_ci_transition_comment()
691+
642692
processing_results: list[TaskResults] = []
643693

644694
for handler_kls in matching_handlers:

tests/integration/test_dg_pr.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,15 @@ def test_downstream_koji_scratch_build(distgit_pr_event, target_branch, uid, che
7373
.should_receive("set_flag")
7474
.with_args(username=check_name, comment=str, url=str, status=CommitStatus, uid=uid)
7575
.mock()
76+
# Mock for CI transition comment
77+
.should_receive("get_comments")
78+
.and_return([])
79+
.once()
80+
.mock()
81+
.should_receive("comment")
82+
.with_args(str)
83+
.once()
84+
.mock()
7685
)
7786
if eln:
7887
check_name = "Packit - scratch build - rawhide [889f07a]"

tests/integration/test_pr_comment.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2500,6 +2500,15 @@ def test_downstream_koji_scratch_build_retrigger_via_dist_git_pr_comment(
25002500
)
25012501
.once()
25022502
.mock()
2503+
# Mock for CI transition comment
2504+
.should_receive("get_comments")
2505+
.and_return([])
2506+
.once()
2507+
.mock()
2508+
.should_receive("comment")
2509+
.with_args(str)
2510+
.once()
2511+
.mock()
25032512
)
25042513
dg_project = (
25052514
flexmock(
@@ -3328,6 +3337,9 @@ def _test_downstream_tf_retrigger_common(
33283337
status=CommitStatus,
33293338
uid=uid,
33303339
)
3340+
# Mock for CI transition comment
3341+
pr_object.should_receive("get_comments").and_return([]).once()
3342+
pr_object.should_receive("comment").with_args(str).once()
33313343

33323344
dg_project = (
33333345
flexmock(

0 commit comments

Comments
 (0)