-
Notifications
You must be signed in to change notification settings - Fork 19
feat: add workspace governance resources (workspace states, workspace workflows, type governance) #66
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
sunder-ch
wants to merge
4
commits into
main
Choose a base branch
from
feat/workspace-governance
base: main
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
feat: add workspace governance resources (workspace states, workspace workflows, type governance) #66
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
77d581d
feat: add workspace governance resources (workspace states, workspace…
sunder-ch f033e33
fix: address review feedback on workspace governance resources
sunder-ch 7a7e165
refactor: restructure type governance as a package with sub-resources
sunder-ch a857baa
fix: validate the workflow-pick response with a typed model
sunder-ch 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
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,3 @@ | ||
| from .base import WorkItemTypeGovernance | ||
|
|
||
| __all__ = ["WorkItemTypeGovernance"] |
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,79 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from typing import Any | ||
|
|
||
| from ...models.work_item_type_governance import ( | ||
| GovernancePreview, | ||
| TypeGovernance, | ||
| TypeGovernancePreviewRequest, | ||
| UpdateTypeGovernance, | ||
| ) | ||
| from ..base_resource import BaseResource | ||
| from .pins import WorkItemTypeWorkflowPins | ||
| from .project_workflows import ProjectTypeWorkflows | ||
|
|
||
|
|
||
| class WorkItemTypeGovernance(BaseResource): | ||
| """API client for work item type governance (workspace governance only). | ||
|
|
||
| Governs which workflows a workspace-level work item type may use | ||
| (``any`` / ``constrained`` / ``required`` modes and allowlists). Per-project | ||
| pins live on ``.pins``; the project-side view of effective workflows and | ||
| picks lives on ``.project_workflows``. Every endpoint requires the workspace | ||
| to own states and workflows — otherwise the API responds 400 with code | ||
| ``workspace_not_managed``. | ||
| """ | ||
|
|
||
| def __init__(self, config: Any) -> None: | ||
| super().__init__(config, "/workspaces/") | ||
|
|
||
| # Initialize sub-resources | ||
| self.pins = WorkItemTypeWorkflowPins(config) | ||
| self.project_workflows = ProjectTypeWorkflows(config) | ||
|
|
||
| def retrieve(self, workspace_slug: str, type_id: str) -> TypeGovernance: | ||
| """Retrieve a type's governance settings (mode, required workflow, allowlist). | ||
|
|
||
| Args: | ||
| workspace_slug: The workspace slug identifier | ||
| type_id: UUID of the workspace work item type | ||
| """ | ||
| response = self._get(f"{workspace_slug}/work-item-types/{type_id}/governance/") | ||
| return TypeGovernance.model_validate(response) | ||
|
|
||
| def update( | ||
| self, workspace_slug: str, type_id: str, data: UpdateTypeGovernance | ||
| ) -> TypeGovernance: | ||
| """Update a type's governance mode / allowlist / required workflow. | ||
|
|
||
| Destructive changes (dropping in-use workflows, mandating one) require | ||
| ``data.acknowledge`` and may need a ``data.state_mapping`` for orphaned | ||
| work items. | ||
|
|
||
| Args: | ||
| workspace_slug: The workspace slug identifier | ||
| type_id: UUID of the workspace work item type | ||
| data: The governance change | ||
| """ | ||
| response = self._patch( | ||
| f"{workspace_slug}/work-item-types/{type_id}/governance/", | ||
| data.model_dump(exclude_none=True), | ||
| ) | ||
| return TypeGovernance.model_validate(response) | ||
|
|
||
| def preview( | ||
| self, workspace_slug: str, type_id: str, data: TypeGovernancePreviewRequest | ||
| ) -> GovernancePreview: | ||
| """Dry-run a governance change and report affected work items (no writes). | ||
|
|
||
| Args: | ||
| workspace_slug: The workspace slug identifier | ||
| type_id: UUID of the workspace work item type | ||
| data: The governance change to preview | ||
| """ | ||
| response = self._post( | ||
| f"{workspace_slug}/work-item-types/{type_id}/governance/preview/", | ||
| data.model_dump(exclude_none=True), | ||
| ) | ||
| payload = response.get("preview", response) if isinstance(response, dict) else response | ||
| return GovernancePreview.model_validate(payload) |
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.