-
Notifications
You must be signed in to change notification settings - Fork 7
feat: add workspace governance resources (states, workflows, type governance) + workflow parity #54
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
Merged
Merged
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| import { BaseResource } from "../BaseResource"; | ||
| import { Configuration } from "../../Configuration"; | ||
| import { CreateWorkItemTypeWorkflowPins, WorkItemTypeWorkflowPin } from "../../models/WorkItemTypeGovernance"; | ||
|
|
||
| /** | ||
| * WorkItemTypeGovernance.pins sub-resource | ||
| * | ||
| * A pin forces one project to resolve a type to a specific workflow, | ||
| * overriding the workspace default and the constrained allowlist. | ||
| */ | ||
| export class Pins extends BaseResource { | ||
| constructor(config: Configuration) { | ||
| super(config); | ||
| } | ||
|
|
||
| /** | ||
| * List a type's project-to-workflow pins | ||
| */ | ||
| async list(workspaceSlug: string, typeId: string): Promise<WorkItemTypeWorkflowPin[]> { | ||
| const data = await this.get<WorkItemTypeWorkflowPin[] | { results: WorkItemTypeWorkflowPin[] }>( | ||
| `/workspaces/${workspaceSlug}/work-item-types/${typeId}/governance/pins/` | ||
| ); | ||
| return Array.isArray(data) ? data : data.results; | ||
| } | ||
|
|
||
| /** | ||
| * Pin a workflow for this type across one or more projects. | ||
| * Returns the type's pins after the change. | ||
| */ | ||
| async create( | ||
| workspaceSlug: string, | ||
| typeId: string, | ||
| data: CreateWorkItemTypeWorkflowPins | ||
| ): Promise<WorkItemTypeWorkflowPin[]> { | ||
| const response = await this.post<WorkItemTypeWorkflowPin[] | { results: WorkItemTypeWorkflowPin[] }>( | ||
| `/workspaces/${workspaceSlug}/work-item-types/${typeId}/governance/pins/`, | ||
| data | ||
| ); | ||
| return Array.isArray(response) ? response : response.results; | ||
| } | ||
|
|
||
| /** | ||
| * Remove a pin | ||
| */ | ||
| async delete(workspaceSlug: string, typeId: string, pinId: string): Promise<void> { | ||
| return this.httpDelete(`/workspaces/${workspaceSlug}/work-item-types/${typeId}/governance/pins/${pinId}/`); | ||
|
akhil-vamshi-konam marked this conversation as resolved.
|
||
| } | ||
| } | ||
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,89 @@ | ||
| import { BaseResource } from "../BaseResource"; | ||
| import { Configuration } from "../../Configuration"; | ||
| import { | ||
| GovernancePreview, | ||
| ProjectTypeWorkflow, | ||
| ProjectWorkflowPickResult, | ||
| SetProjectWorkflowPick, | ||
| WorkflowFallbackPreviewRequest, | ||
| } from "../../models/WorkItemTypeGovernance"; | ||
|
|
||
| type GovernancePreviewResponse = { preview?: GovernancePreview } | GovernancePreview; | ||
|
|
||
| function unwrapPreview(response: GovernancePreviewResponse): GovernancePreview { | ||
| return "preview" in response && response.preview ? response.preview : (response as GovernancePreview); | ||
| } | ||
|
|
||
| /** | ||
| * WorkItemTypeGovernance.projectWorkflows sub-resource | ||
| * | ||
| * Reports each active type's governance mode and the workflow it effectively | ||
| * resolves to within a project, and manages the project's own workflow pick | ||
| * for a type. | ||
| */ | ||
| export class ProjectWorkflows extends BaseResource { | ||
| constructor(config: Configuration) { | ||
| super(config); | ||
| } | ||
|
|
||
| /** | ||
| * List every active type's governance mode, effective workflow, and | ||
| * pickable options for a project | ||
| */ | ||
| async list(workspaceSlug: string, projectId: string): Promise<ProjectTypeWorkflow[]> { | ||
| const data = await this.get<ProjectTypeWorkflow[] | { results: ProjectTypeWorkflow[] }>( | ||
| `/workspaces/${workspaceSlug}/projects/${projectId}/work-item-types/workflows/` | ||
| ); | ||
| return Array.isArray(data) ? data : data.results; | ||
| } | ||
|
|
||
| /** | ||
| * Retrieve one type's governance mode and effective workflow in a project | ||
| */ | ||
| async retrieve(workspaceSlug: string, projectId: string, typeId: string): Promise<ProjectTypeWorkflow> { | ||
| return this.get<ProjectTypeWorkflow>( | ||
| `/workspaces/${workspaceSlug}/projects/${projectId}/work-item-types/${typeId}/workflows/` | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Retrieve the project's current workflow pick context for a type | ||
| */ | ||
| async retrievePick(workspaceSlug: string, projectId: string, typeId: string): Promise<ProjectTypeWorkflow> { | ||
| return this.get<ProjectTypeWorkflow>( | ||
| `/workspaces/${workspaceSlug}/projects/${projectId}/work-item-types/${typeId}/workflow/` | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Set the project's workflow pick for a type. | ||
| * Runs the workflow fallback for stranded work items; every orphan must be | ||
| * covered by `data.state_mapping` (400 with an orphan report otherwise). | ||
| */ | ||
| async updatePick( | ||
| workspaceSlug: string, | ||
| projectId: string, | ||
| typeId: string, | ||
| data: SetProjectWorkflowPick | ||
| ): Promise<ProjectWorkflowPickResult> { | ||
| return this.put<ProjectWorkflowPickResult>( | ||
| `/workspaces/${workspaceSlug}/projects/${projectId}/work-item-types/${typeId}/workflow/`, | ||
| data | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Dry-run the project's workflow fallback (re-type / switch dialogs) | ||
| */ | ||
| async previewFallback( | ||
| workspaceSlug: string, | ||
| projectId: string, | ||
| data: WorkflowFallbackPreviewRequest | ||
| ): Promise<GovernancePreview> { | ||
| const response = await this.post<GovernancePreviewResponse>( | ||
| `/workspaces/${workspaceSlug}/projects/${projectId}/workflow-fallback-preview/`, | ||
| data | ||
| ); | ||
| return unwrapPreview(response); | ||
| } | ||
| } |
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,65 @@ | ||
| import { BaseResource } from "../BaseResource"; | ||
| import { Configuration } from "../../Configuration"; | ||
| import { | ||
| GovernancePreview, | ||
| TypeGovernance, | ||
| TypeGovernancePreviewRequest, | ||
| UpdateTypeGovernance, | ||
| } from "../../models/WorkItemTypeGovernance"; | ||
| import { Pins } from "./Pins"; | ||
| import { ProjectWorkflows } from "./ProjectWorkflows"; | ||
|
|
||
| type GovernancePreviewResponse = { preview?: GovernancePreview } | GovernancePreview; | ||
|
|
||
| function unwrapPreview(response: GovernancePreviewResponse): GovernancePreview { | ||
| return "preview" in response && response.preview ? response.preview : (response as GovernancePreview); | ||
| } | ||
|
|
||
| /** | ||
| * WorkItemTypeGovernance API resource (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 `.projectWorkflows`. Every endpoint requires the workspace to own | ||
| * states and workflows — otherwise the API responds 400 with code | ||
| * `workspace_not_managed`. | ||
| */ | ||
| export class WorkItemTypeGovernance extends BaseResource { | ||
| public pins: Pins; | ||
| public projectWorkflows: ProjectWorkflows; | ||
|
|
||
| constructor(config: Configuration) { | ||
| super(config); | ||
| this.pins = new Pins(config); | ||
| this.projectWorkflows = new ProjectWorkflows(config); | ||
| } | ||
|
|
||
| /** | ||
| * Retrieve a type's governance settings (mode, required workflow, allowlist) | ||
| */ | ||
| async retrieve(workspaceSlug: string, typeId: string): Promise<TypeGovernance> { | ||
| return this.get<TypeGovernance>(`/workspaces/${workspaceSlug}/work-item-types/${typeId}/governance/`); | ||
| } | ||
|
|
||
| /** | ||
| * 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. | ||
| */ | ||
| async update(workspaceSlug: string, typeId: string, data: UpdateTypeGovernance): Promise<TypeGovernance> { | ||
| return this.patch<TypeGovernance>(`/workspaces/${workspaceSlug}/work-item-types/${typeId}/governance/`, data); | ||
| } | ||
|
|
||
| /** | ||
| * Dry-run a governance change and report affected work items (no writes) | ||
| */ | ||
| async preview(workspaceSlug: string, typeId: string, data: TypeGovernancePreviewRequest): Promise<GovernancePreview> { | ||
| const response = await this.post<GovernancePreviewResponse>( | ||
| `/workspaces/${workspaceSlug}/work-item-types/${typeId}/governance/preview/`, | ||
| data | ||
| ); | ||
| return unwrapPreview(response); | ||
| } | ||
| } |
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,102 @@ | ||
| import { BaseResource } from "../BaseResource"; | ||
|
akhil-vamshi-konam marked this conversation as resolved.
|
||
| import { Configuration } from "../../Configuration"; | ||
| import { | ||
| CreateWorkflowTransitionHook, | ||
| UpdateWorkflowTransitionHook, | ||
| WorkflowTransitionHook, | ||
| } from "../../models/Workflow"; | ||
|
|
||
| /** | ||
| * WorkflowTransitionHooks sub-resource | ||
| * Manages hooks attached to project workflow transitions | ||
| */ | ||
| export class Hooks extends BaseResource { | ||
| constructor(config: Configuration) { | ||
| super(config); | ||
| } | ||
|
|
||
| private basePath(workspaceSlug: string, projectId: string, workflowId: string, transitionId: string): string { | ||
| return ( | ||
| `/workspaces/${workspaceSlug}/projects/${projectId}/workflows/${workflowId}` + | ||
| `/state-transitions/${transitionId}/hooks` | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * List hooks on a workflow transition | ||
| */ | ||
| async list( | ||
| workspaceSlug: string, | ||
| projectId: string, | ||
| workflowId: string, | ||
| transitionId: string | ||
| ): Promise<WorkflowTransitionHook[]> { | ||
| const data = await this.get<WorkflowTransitionHook[] | { results: WorkflowTransitionHook[] }>( | ||
| `${this.basePath(workspaceSlug, projectId, workflowId, transitionId)}/` | ||
| ); | ||
| return Array.isArray(data) ? data : data.results; | ||
| } | ||
|
|
||
| /** | ||
| * Create a hook on a workflow transition. | ||
| * For send_webhook handlers the one-shot `secret_plaintext` is included in | ||
| * the response of this call only. | ||
| */ | ||
| async create( | ||
| workspaceSlug: string, | ||
| projectId: string, | ||
| workflowId: string, | ||
| transitionId: string, | ||
| data: CreateWorkflowTransitionHook | ||
| ): Promise<WorkflowTransitionHook> { | ||
| return this.post<WorkflowTransitionHook>( | ||
| `${this.basePath(workspaceSlug, projectId, workflowId, transitionId)}/`, | ||
| data | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Retrieve a hook by ID | ||
| */ | ||
| async retrieve( | ||
| workspaceSlug: string, | ||
| projectId: string, | ||
| workflowId: string, | ||
| transitionId: string, | ||
| hookId: string | ||
| ): Promise<WorkflowTransitionHook> { | ||
| return this.get<WorkflowTransitionHook>( | ||
| `${this.basePath(workspaceSlug, projectId, workflowId, transitionId)}/${hookId}/` | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Update a hook (`phase` and `handler_name` are immutable) | ||
| */ | ||
| async update( | ||
| workspaceSlug: string, | ||
| projectId: string, | ||
| workflowId: string, | ||
| transitionId: string, | ||
| hookId: string, | ||
| data: UpdateWorkflowTransitionHook | ||
| ): Promise<WorkflowTransitionHook> { | ||
| return this.patch<WorkflowTransitionHook>( | ||
| `${this.basePath(workspaceSlug, projectId, workflowId, transitionId)}/${hookId}/`, | ||
| data | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Delete a hook | ||
| */ | ||
| async del( | ||
| workspaceSlug: string, | ||
| projectId: string, | ||
| workflowId: string, | ||
| transitionId: string, | ||
| hookId: string | ||
| ): Promise<void> { | ||
| return this.httpDelete(`${this.basePath(workspaceSlug, projectId, workflowId, transitionId)}/${hookId}/`); | ||
| } | ||
| } | ||
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.