|
14 | 14 |
|
15 | 15 | import celery |
16 | 16 | 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 | +) |
18 | 25 | from packit.utils import nested_get |
19 | 26 |
|
20 | 27 | from packit_service.config import ServiceConfig |
21 | 28 | from packit_service.constants import ( |
22 | 29 | COMMENT_REACTION, |
| 30 | + FEDORA_CI_TRANSITION_COMMENT, |
23 | 31 | HELP_COMMENT_DESCRIPTION, |
24 | 32 | HELP_COMMENT_EPILOG, |
25 | 33 | HELP_COMMENT_PROG, |
|
88 | 96 | from packit_service.worker.monitoring import Pushgateway |
89 | 97 | from packit_service.worker.parser import Parser |
90 | 98 | 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 |
91 | 101 | from packit_service.worker.result import TaskResults |
92 | 102 |
|
93 | 103 | logger = logging.getLogger(__name__) |
@@ -484,6 +494,44 @@ def report_task_accepted( |
484 | 494 |
|
485 | 495 | self.push_copr_metrics(handler_kls, number_of_build_targets) |
486 | 496 |
|
| 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 | + |
487 | 535 | def report_task_accepted_for_fedora_ci(self, handler_kls: type[FedoraCIJobHandler]): |
488 | 536 | """ |
489 | 537 | For CI-related dist-git PR comment events report the initial status |
@@ -639,6 +687,8 @@ def process_fedora_ci_jobs(self) -> list[TaskResults]: |
639 | 687 |
|
640 | 688 | # TODO: add allowlist checks here |
641 | 689 |
|
| 690 | + self._post_fedora_ci_transition_comment() |
| 691 | + |
642 | 692 | processing_results: list[TaskResults] = [] |
643 | 693 |
|
644 | 694 | for handler_kls in matching_handlers: |
|
0 commit comments