-
Notifications
You must be signed in to change notification settings - Fork 10
Add TaskStage API support with models, resource, tests and examples #148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
TanyaSingh369-svg
wants to merge
9
commits into
next-1.0.0
Choose a base branch
from
feature/task-stage-api
base: next-1.0.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
5fd26cb
Add TaskStage API support with models, resource, tests and examples
TanyaSingh369-svg 35ef47c
fixed lint issue
TanyaSingh369-svg 8b2ecfb
Merge branch 'next-1.0.0' into feature/task-stage-api
TanyaSingh369-svg 09d33c7
fix: clean task stage model and update example to follow SDK patterns
TanyaSingh369-svg 68a29e1
fix: map task stage relationships in parser
TanyaSingh369-svg 63e6574
fix: resolve lint issues in task stage api
TanyaSingh369-svg da684e0
fix: resolve task stage relationship parsing
TanyaSingh369-svg 640e476
fix: improve task stage relationship modeling
TanyaSingh369-svg 24e69f9
refactor: simplify task stage relationship handling
TanyaSingh369-svg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| """ | ||
| Example usage of TaskStages API | ||
|
|
||
| Demonstrates: | ||
| - Read a task stage | ||
| - List task stages for a run | ||
| - Override a task stage | ||
| """ | ||
|
|
||
| import os | ||
| import sys | ||
|
|
||
| sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "src")) | ||
|
|
||
| from pytfe import TFEClient, TFEConfig | ||
|
|
||
|
|
||
| def main(): | ||
| client = TFEClient(TFEConfig.from_env()) | ||
|
|
||
| task_stage_id = os.getenv("TFE_TASK_STAGE_ID") | ||
| run_id = os.getenv("TFE_RUN_ID") | ||
|
|
||
| if not task_stage_id or not run_id: | ||
| print("Please set TFE_TASK_STAGE_ID and TFE_RUN_ID") | ||
| return | ||
|
|
||
| print("=== TaskStages Example ===") | ||
|
|
||
| # READ | ||
| print("\nReading task stage...") | ||
| try: | ||
| stage = client.task_stages.read(task_stage_id) | ||
| print(f"ID: {stage.id}") | ||
| print(f"Stage: {stage.stage}") | ||
| print(f"Status: {stage.status}") | ||
| print(f"Run: {stage.run.id if stage.run else None}") | ||
| except Exception as e: | ||
| print(f"Read failed: {e}") | ||
|
|
||
| # LIST | ||
| print("\nListing task stages...") | ||
| try: | ||
| stages = list(client.task_stages.list(run_id)) | ||
| for s in stages: | ||
| print(f"{s.id} - {s.status}") | ||
| except Exception as e: | ||
| print(f"List failed: {e}") | ||
|
|
||
| # OVERRIDE | ||
| print("\nOverriding task stage...") | ||
| try: | ||
| client.task_stages.override(task_stage_id, comment="Approved") | ||
| print("Override successful") | ||
| except Exception as e: | ||
| print(f"Override failed: {e}") | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| # Copyright IBM Corp. 2025, 2026 | ||
| # SPDX-License-Identifier: MPL-2.0 | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from datetime import datetime | ||
| from enum import Enum | ||
| from typing import TYPE_CHECKING, Any | ||
|
|
||
| from pydantic import BaseModel, ConfigDict, Field | ||
|
|
||
| if TYPE_CHECKING: | ||
| from pytfe.models.task_stage import TaskStage | ||
|
|
||
|
|
||
| class TaskResultStatus(str, Enum): | ||
| passed = "passed" | ||
| failed = "failed" | ||
| pending = "pending" | ||
| running = "running" | ||
| unreachable = "unreachable" | ||
| errored = "errored" | ||
|
|
||
|
|
||
| class TaskEnforcementLevel(str, Enum): | ||
| advisory = "advisory" | ||
| mandatory = "mandatory" | ||
|
|
||
|
|
||
| class TaskResultStatusTimestamps(BaseModel): | ||
| model_config = ConfigDict(populate_by_name=True, validate_by_name=True) | ||
|
|
||
| errored_at: datetime | None = Field(None, alias="errored-at") | ||
| running_at: datetime | None = Field(None, alias="running-at") | ||
| canceled_at: datetime | None = Field(None, alias="canceled-at") | ||
| failed_at: datetime | None = Field(None, alias="failed-at") | ||
| passed_at: datetime | None = Field(None, alias="passed-at") | ||
|
|
||
|
|
||
| class TaskResult(BaseModel): | ||
| model_config = ConfigDict(populate_by_name=True, validate_by_name=True) | ||
|
|
||
| id: str | ||
| status: TaskResultStatus | None = Field(None, alias="status") | ||
| message: str | None = Field(None, alias="message") | ||
|
|
||
| status_timestamps: TaskResultStatusTimestamps | None = Field( | ||
| None, alias="status-timestamps" | ||
| ) | ||
|
|
||
| url: str | None = Field(None, alias="url") | ||
|
|
||
| created_at: datetime | None = Field(None, alias="created-at") | ||
| updated_at: datetime | None = Field(None, alias="updated-at") | ||
|
|
||
| task_id: str | None = Field(None, alias="task-id") | ||
| task_name: str | None = Field(None, alias="task-name") | ||
| task_url: str | None = Field(None, alias="task-url") | ||
|
|
||
| workspace_task_id: str | None = Field(None, alias="workspace-task-id") | ||
| workspace_task_enforcement_level: TaskEnforcementLevel | None = Field( | ||
| None, alias="workspace-task-enforcement-level" | ||
| ) | ||
|
|
||
| agent_pool_id: str | None = Field(None, alias="agent-pool-id") | ||
| task_stage: TaskStage | None = Field(None, alias="task-stage") | ||
|
|
||
| @classmethod | ||
| def model_validate(cls, *args: Any, **kwargs: Any) -> TaskResult: | ||
| if not getattr(cls, "__pydantic_complete__", True): | ||
| _rebuild_task_result_model() | ||
| return super().model_validate(*args, **kwargs) | ||
|
|
||
|
|
||
| def _rebuild_task_result_model() -> None: | ||
| try: | ||
| from pytfe.models.task_stage import TaskStage | ||
|
|
||
| TaskResult.model_rebuild( | ||
| raise_errors=False, | ||
| _types_namespace={"TaskStage": TaskStage}, | ||
| ) | ||
| except Exception: | ||
| pass | ||
|
|
||
|
|
||
| _rebuild_task_result_model() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.