|
4 | 4 |
|
5 | 5 | from pydantic import BaseModel, Field |
6 | 6 | from specfile import Specfile |
| 7 | +from specfile.utils import EVR |
7 | 8 |
|
8 | 9 | from beeai_framework.context import RunContext |
9 | 10 | from beeai_framework.emitter import Emitter |
@@ -77,3 +78,38 @@ async def _run( |
77 | 78 | except Exception as e: |
78 | 79 | return StringToolOutput(result=f"Failed to bump release: {e}") |
79 | 80 | return StringToolOutput() |
| 81 | + |
| 82 | + |
| 83 | +class SetZStreamReleaseToolInput(BaseModel): |
| 84 | + spec: Path = Field(description="Absolute path to a spec file") |
| 85 | + latest_ystream_evr: str = Field(description="EVR (Epoch-Version-Release) of the latest Y-Stream build") |
| 86 | + |
| 87 | + |
| 88 | +class SetZStreamReleaseTool(Tool[SetZStreamReleaseToolInput, ToolRunOptions, StringToolOutput]): |
| 89 | + name = "set_zstream_release" |
| 90 | + description = """ |
| 91 | + Sets the value of the `Release` field in the specified spec file to a Z-Stream release |
| 92 | + based on the release of the latest Y-Stream build. |
| 93 | + Returns error message on failure. |
| 94 | + """ |
| 95 | + input_schema = SetZStreamReleaseToolInput |
| 96 | + |
| 97 | + def _create_emitter(self) -> Emitter: |
| 98 | + return Emitter.root().child( |
| 99 | + namespace=["tool", "specfile", self.name], |
| 100 | + creator=self, |
| 101 | + ) |
| 102 | + |
| 103 | + async def _run( |
| 104 | + self, tool_input: SetZStreamReleaseToolInput, options: ToolRunOptions | None, context: RunContext |
| 105 | + ) -> StringToolOutput: |
| 106 | + try: |
| 107 | + with Specfile(tool_input.spec) as spec: |
| 108 | + if not spec.has_autorelease: |
| 109 | + return StringToolOutput(result="The specified spec file doesn't use %autorelease") |
| 110 | + base_release = EVR.from_string(tool_input.latest_ystream_evr).release |
| 111 | + base_raw_release = base_release.rsplit(".el", maxsplit=1)[0] |
| 112 | + spec.raw_release = base_raw_release + "%{?dist}.%{autorelease -n}" |
| 113 | + except Exception as e: |
| 114 | + return StringToolOutput(result=f"Failed to set Z-Stream release: {e}") |
| 115 | + return StringToolOutput() |
0 commit comments