Skip to content

Commit a0bb550

Browse files
committed
Process dist-git onboarding requests
Signed-off-by: Nikola Forró <nforro@redhat.com>
1 parent 6246652 commit a0bb550

File tree

8 files changed

+261
-0
lines changed

8 files changed

+261
-0
lines changed

packit_service/constants.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,3 +341,66 @@ 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+
DG_ONBOARDING_TITLE = "Add initial Packit configuration"
346+
DG_ONBOARDING_DESCRIPTION = """
347+
Hello,
348+
349+
thank you for introducing a new package to Fedora!
350+
351+
Let us present you [Packit](https://packit.dev/), an automation for Fedora releases.
352+
We are sending a configuration file with a basic setup.
353+
The automation will be enabled by merging this pull-request into the `rawhide` branch.
354+
355+
If you have any question or concern, ask here or on `#packit:fedora.im` Matrix channel
356+
and Packit team will help.
357+
358+
If you look at the configuration file, you can see that Packit is configured to do 3 jobs for you:
359+
* [`pull_from_upstream`](https://packit.dev/docs/configuration/downstream/pull_from_upstream):
360+
Create a new set of pull-requests when there is a new upstream release.
361+
(The specfile-changes and sources are taken care of. Packit is notified about new release from
362+
[Release Monitoring](https://release-monitoring.org/) service. Check if your project is there.)
363+
* [`koji_build`](https://packit.dev/docs/configuration/downstream/koji_build):
364+
Submit a Koji build as reaction to a merged pull request.
365+
* [`bodhi_update`](https://packit.dev/docs/configuration/downstream/bodhi_update):
366+
Create a Bodhi update as a reaction to a succesful Koji build.
367+
368+
These jobs are independent so you can pick just those that are relevant to you.
369+
For each, you can also configure Fedora/EPEL versions other than Rawhide that the jobs
370+
should be run for.
371+
372+
You can also further tweak the process. A few handy options are prepared for you
373+
in the confguration file to uncomment. Rest can be found in
374+
[the documentation](https://packit.dev/docs/fedora-releases-guide/dist-git-onboarding).
375+
In case you have a group of dependent packages, you might want to take a look at
376+
[how to configure multi-package updates]
377+
(https://packit.dev/docs/fedora-releases-guide/releasing-multiple-packages).
378+
379+
380+
Things you still need to be aware of:
381+
382+
* The package maintenance is still your responsibility -- Packit is just a handy tool that can
383+
save you some time.
384+
* When Packit introduces new releases in form of the pull-request, it's your responsibility
385+
to check the pull-request including the newly-introduced source. This is the place where human
386+
intervention is required.
387+
* Be aware that there are other packages and packagers and that you might break someone else's work
388+
by using Packit in a wrong way. (E.g. be careful about dependent packages since there is
389+
no automatic check for these in place.)
390+
* Check [Fedora updates policy](https://docs.fedoraproject.org/en-US/fesco/Updates_Policy/).
391+
* Check [Fedora Packaging guidelines](https://docs.fedoraproject.org/en-US/packaging-guidelines/)
392+
including the specifics for your package type.
393+
* Consult the approach with other maintainers of this package and care about the Packit results
394+
so you don't introduce spam and extra work for others.
395+
* Speaking of notifications -- you might want to setup a rule on
396+
[Fedora Notifications](https://notifications.fedoraproject.org/) so you won't miss
397+
anything important, since `packit` FAS account will be the actor of the jobs.
398+
399+
400+
In case you don't want to receive these pull-requests in the future, you can use
401+
the `--onboard-packit no` option when running `fedpkg request-repo`.
402+
403+
404+
I hope you will be happy with the automation!
405+
*[Packit team](https://packit.dev/#contact)*
406+
"""
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Copyright Contributors to the Packit project.
2+
# SPDX-License-Identifier: MIT
3+
4+
from typing import Optional
5+
6+
from packit.config import PackageConfig
7+
8+
from .abstract.base import ForgeIndependent
9+
10+
11+
class Request(ForgeIndependent):
12+
@classmethod
13+
def event_type(cls) -> str:
14+
return "onboarding.Request"
15+
16+
def __init__(
17+
self,
18+
package: str,
19+
open_pr: bool = True,
20+
):
21+
super().__init__(project_url=f"https://src.fedoraproject.org/rpms/{package}")
22+
self.open_pr = open_pr
23+
24+
def get_packages_config(self) -> Optional[PackageConfig]:
25+
return None
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Copyright Contributors to the Packit project.
2+
# SPDX-License-Identifier: MIT
3+
4+
import logging
5+
6+
from packit.constants import CONFIG_FILE_NAMES
7+
8+
from packit_service.worker.checker.abstract import Checker
9+
10+
logger = logging.getLogger(__name__)
11+
12+
13+
class ProjectIsNotOnboarded(Checker):
14+
def pre_check(self) -> bool:
15+
if any(f for f in self.project.get_files(ref="rawhide") if f in CONFIG_FILE_NAMES):
16+
logger.info(f"Package {self.project.repo} is already onboarded")
17+
return False
18+
return True

packit_service/worker/handlers/abstract.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ class TaskName(str, enum.Enum):
265265
tag_into_sidetag = "task.tag_into_sidetag"
266266
openscanhub_task_finished = "task.openscanhub_task_finished"
267267
openscanhub_task_started = "task.openscanhub_task_started"
268+
onboarding_request = "task.run_onboarding_request_handler"
268269
downstream_koji_scratch_build = "task.run_downstream_koji_scratch_build_handler"
269270
downstream_koji_scratch_build_report = "task.run_downstream_koji_scratch_build_report_handler"
270271
downstream_koji_eln_scratch_build = "task.run_downstream_koji_eln_scratch_build_handler"
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# Copyright Contributors to the Packit project.
2+
# SPDX-License-Identifier: MIT
3+
4+
"""
5+
This file defines classes for job handlers specific to onboarding tasks
6+
"""
7+
8+
import logging
9+
10+
from packit.cli.dist_git_init import (
11+
COMMIT_MESSAGE,
12+
CONFIG_FILE_NAME,
13+
ONBOARD_BRANCH_NAME,
14+
DistGitInitializer,
15+
)
16+
from packit.config.config import Config
17+
from packit.config.package_config import PackageConfig
18+
19+
from packit_service.constants import DG_ONBOARDING_DESCRIPTION, DG_ONBOARDING_TITLE
20+
from packit_service.events import (
21+
onboarding,
22+
)
23+
from packit_service.worker.checker.abstract import Checker
24+
from packit_service.worker.checker.onboarding import ProjectIsNotOnboarded
25+
from packit_service.worker.handlers.abstract import (
26+
JobHandler,
27+
TaskName,
28+
reacts_to,
29+
)
30+
from packit_service.worker.mixin import ConfigFromEventMixin, PackitAPIWithDownstreamMixin
31+
from packit_service.worker.result import TaskResults
32+
33+
logger = logging.getLogger(__name__)
34+
35+
36+
@reacts_to(event=onboarding.Request)
37+
class OnboardingRequestHandler(
38+
JobHandler,
39+
ConfigFromEventMixin,
40+
PackitAPIWithDownstreamMixin,
41+
):
42+
task_name = TaskName.onboarding_request
43+
44+
@staticmethod
45+
def get_checkers() -> tuple[type[Checker], ...]:
46+
return (ProjectIsNotOnboarded,)
47+
48+
def _run(self) -> TaskResults:
49+
package = self.project.repo
50+
logger.debug(f"Running onboarding for {package}")
51+
52+
# generate and load config
53+
initializer = DistGitInitializer(
54+
config=Config(),
55+
path_or_url="",
56+
upstream_git_url=None,
57+
)
58+
self.package_config = self.job_config = PackageConfig.get_from_dict(
59+
initializer.package_config_dict | {"downstream_package_name": package},
60+
)
61+
62+
self.perform_onboarding(
63+
config=initializer.package_config_content,
64+
open_pr=self.data.event_dict.get("open_pr", True),
65+
)
66+
67+
return TaskResults(success=True, details={})
68+
69+
def perform_onboarding(self, config: str, open_pr: bool) -> None:
70+
# clone the repo and fetch rawhide
71+
self.packit_api.dg.create_branch(
72+
"rawhide",
73+
base="remotes/origin/rawhide",
74+
setup_tracking=True,
75+
)
76+
self.packit_api.dg.update_branch("rawhide")
77+
self.packit_api.dg.switch_branch("rawhide", force=True)
78+
79+
if open_pr:
80+
self.packit_api.dg.create_branch(ONBOARD_BRANCH_NAME)
81+
self.packit_api.dg.switch_branch(ONBOARD_BRANCH_NAME, force=True)
82+
self.packit_api.dg.reset_workdir()
83+
84+
working_dir = self.packit_api.dg.local_project.working_dir
85+
86+
# create config file
87+
(working_dir / CONFIG_FILE_NAME).write_text(config)
88+
89+
# create or update .gitignore
90+
with (working_dir / ".gitignore").open("a") as f:
91+
print("prepare_sources_result*/", file=f)
92+
93+
self.packit_api.dg.commit(
94+
title=COMMIT_MESSAGE,
95+
msg="",
96+
prefix="",
97+
)
98+
99+
if open_pr:
100+
self.packit_api.push_and_create_pr(
101+
pr_title=DG_ONBOARDING_TITLE,
102+
pr_description=DG_ONBOARDING_DESCRIPTION,
103+
git_branch="rawhide",
104+
repo=self.packit_api.dg,
105+
)
106+
else:
107+
self.packit_api.dg.push(refspec="HEAD:rawhide")

packit_service/worker/jobs.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
github,
3333
koji,
3434
logdetective,
35+
onboarding,
3536
pagure,
3637
testing_farm,
3738
)
@@ -75,6 +76,7 @@
7576
RetriggerDownstreamKojiBuildHandler,
7677
TagIntoSidetagHandler,
7778
)
79+
from packit_service.worker.handlers.onboarding import OnboardingRequestHandler
7880
from packit_service.worker.helpers.build import (
7981
BaseBuildJobHelper,
8082
CoprBuildJobHelper,
@@ -348,6 +350,16 @@ def process(self) -> list[TaskResults]:
348350
).apply_async()
349351
# should we comment about not processing if the comment is not
350352
# on the issue created by us or not in packit/notifications?
353+
elif isinstance(self.event, onboarding.Request):
354+
if OnboardingRequestHandler.pre_check(
355+
package_config=None,
356+
job_config=None,
357+
event=self.event.get_dict(),
358+
):
359+
OnboardingRequestHandler.get_signature(
360+
event=self.event,
361+
job=None,
362+
).apply_async()
351363
else:
352364
if (
353365
isinstance(

packit_service/worker/parser.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
gitlab,
3131
koji,
3232
logdetective,
33+
onboarding,
3334
openscanhub,
3435
pagure,
3536
testing_farm,
@@ -134,6 +135,7 @@ def parse_event(
134135
koji.result.Task,
135136
openscanhub.task.Finished,
136137
openscanhub.task.Started,
138+
onboarding.Request,
137139
pagure.pr.Comment,
138140
pagure.pr.Flag,
139141
pagure.pr.Action,
@@ -189,6 +191,7 @@ def parse_event(
189191
Parser.parse_anitya_version_update_event,
190192
Parser.parse_openscanhub_task_finished_event,
191193
Parser.parse_openscanhub_task_started_event,
194+
Parser.parse_onboarding_request_event,
192195
Parser.parse_commit_comment_event,
193196
Parser.parse_pagure_pull_request_event,
194197
Parser.parse_logdetective_analysis_event,
@@ -1560,6 +1563,23 @@ def parse_koji_build_tag_event(event) -> Optional[koji.tag.Build]:
15601563
owner=owner,
15611564
)
15621565

1566+
@staticmethod
1567+
def parse_onboarding_request_event(
1568+
event: dict,
1569+
) -> Optional[onboarding.Request]:
1570+
if event.get("source") != "onboarding" or not event.get("package"):
1571+
return None
1572+
1573+
package: str = event["package"]
1574+
logger.info(f"dist-git onboarding request event for package {package}")
1575+
1576+
open_pr = bool(event.get("open_pr", True))
1577+
1578+
return onboarding.Request(
1579+
package=package,
1580+
open_pr=open_pr,
1581+
)
1582+
15631583
@staticmethod
15641584
def parse_pipeline_event(event) -> Optional[gitlab.pipeline.Pipeline]:
15651585
"""

packit_service/worker/tasks.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
KojiBuildTagHandler,
9090
KojiTaskReportDownstreamHandler,
9191
)
92+
from packit_service.worker.handlers.onboarding import OnboardingRequestHandler
9293
from packit_service.worker.handlers.usage import check_onboarded_projects
9394
from packit_service.worker.helpers.build.babysit import (
9495
check_copr_build,
@@ -812,6 +813,20 @@ def run_downstream_log_detective_results_handler(
812813
return get_handlers_task_results(handler.run_job(), event)
813814

814815

816+
@celery_app.task(name=TaskName.onboarding_request, base=TaskWithRetry)
817+
def run_onboarding_request_handler(
818+
event: dict,
819+
package_config: dict,
820+
job_config: dict,
821+
):
822+
handler = OnboardingRequestHandler(
823+
package_config=load_package_config(package_config),
824+
job_config=load_job_config(job_config),
825+
event=event,
826+
)
827+
return get_handlers_task_results(handler.run_job(), event)
828+
829+
815830
def get_handlers_task_results(results: dict, event: dict) -> dict:
816831
# include original event to provide more info
817832
return {"job": results, "event": event}

0 commit comments

Comments
 (0)