-
Notifications
You must be signed in to change notification settings - Fork 4
[INFRA-395] feat: add Workflows and ProjectTemplates API resources #45
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
mguptahub
wants to merge
2
commits into
main
Choose a base branch
from
infra-395/node-sdk-project-level-apis
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
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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,52 @@ | ||
| import { BaseResource } from "../BaseResource"; | ||
| import { Configuration } from "../../Configuration"; | ||
| import { CreatePageTemplate, PageTemplate, UpdatePageTemplate } from "../../models/ProjectTemplate"; | ||
|
|
||
| /** | ||
| * ProjectPageTemplates sub-resource | ||
| * Manages page templates within a project | ||
| */ | ||
| export class Pages extends BaseResource { | ||
| constructor(config: Configuration) { | ||
| super(config); | ||
| } | ||
|
|
||
| /** | ||
| * List all page templates for a project | ||
| */ | ||
| async list(workspaceSlug: string, projectId: string): Promise<PageTemplate[]> { | ||
| const data = await this.get<PageTemplate[] | { results: PageTemplate[] }>( | ||
| `/workspaces/${workspaceSlug}/projects/${projectId}/pages/templates/` | ||
| ); | ||
| return Array.isArray(data) ? data : data.results; | ||
| } | ||
|
|
||
| /** | ||
| * Create a new page template for a project | ||
| */ | ||
| async create(workspaceSlug: string, projectId: string, data: CreatePageTemplate): Promise<PageTemplate> { | ||
| return this.post<PageTemplate>(`/workspaces/${workspaceSlug}/projects/${projectId}/pages/templates/`, data); | ||
| } | ||
|
|
||
| /** | ||
| * Update a page template by ID | ||
| */ | ||
| async update( | ||
| workspaceSlug: string, | ||
| projectId: string, | ||
| templateId: string, | ||
| data: UpdatePageTemplate | ||
| ): Promise<PageTemplate> { | ||
| return this.patch<PageTemplate>( | ||
| `/workspaces/${workspaceSlug}/projects/${projectId}/pages/templates/${templateId}/`, | ||
| data | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Delete a page template by ID | ||
| */ | ||
| async del(workspaceSlug: string, projectId: string, templateId: string): Promise<void> { | ||
| return this.httpDelete(`/workspaces/${workspaceSlug}/projects/${projectId}/pages/templates/${templateId}/`); | ||
| } | ||
| } |
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,52 @@ | ||
| import { BaseResource } from "../BaseResource"; | ||
| import { Configuration } from "../../Configuration"; | ||
| import { CreateWorkItemTemplate, UpdateWorkItemTemplate, WorkItemTemplate } from "../../models/ProjectTemplate"; | ||
|
|
||
| /** | ||
| * ProjectWorkItemTemplates sub-resource | ||
| * Manages work item templates within a project | ||
| */ | ||
| export class WorkItems extends BaseResource { | ||
| constructor(config: Configuration) { | ||
| super(config); | ||
| } | ||
|
|
||
| /** | ||
| * List all work item templates for a project | ||
| */ | ||
| async list(workspaceSlug: string, projectId: string): Promise<WorkItemTemplate[]> { | ||
| const data = await this.get<WorkItemTemplate[] | { results: WorkItemTemplate[] }>( | ||
| `/workspaces/${workspaceSlug}/projects/${projectId}/workitems/templates/` | ||
| ); | ||
| return Array.isArray(data) ? data : data.results; | ||
| } | ||
|
|
||
| /** | ||
| * Create a new work item template for a project | ||
| */ | ||
| async create(workspaceSlug: string, projectId: string, data: CreateWorkItemTemplate): Promise<WorkItemTemplate> { | ||
| return this.post<WorkItemTemplate>(`/workspaces/${workspaceSlug}/projects/${projectId}/workitems/templates/`, data); | ||
| } | ||
|
|
||
| /** | ||
| * Update a work item template by ID | ||
| */ | ||
| async update( | ||
| workspaceSlug: string, | ||
| projectId: string, | ||
| templateId: string, | ||
| data: UpdateWorkItemTemplate | ||
| ): Promise<WorkItemTemplate> { | ||
| return this.patch<WorkItemTemplate>( | ||
| `/workspaces/${workspaceSlug}/projects/${projectId}/workitems/templates/${templateId}/`, | ||
| data | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Delete a work item template by ID | ||
| */ | ||
| async del(workspaceSlug: string, projectId: string, templateId: string): Promise<void> { | ||
| return this.httpDelete(`/workspaces/${workspaceSlug}/projects/${projectId}/workitems/templates/${templateId}/`); | ||
| } | ||
| } |
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,19 @@ | ||
| import { BaseResource } from "../BaseResource"; | ||
| import { Configuration } from "../../Configuration"; | ||
| import { WorkItems } from "./WorkItems"; | ||
| import { Pages } from "./Pages"; | ||
|
|
||
| /** | ||
| * ProjectTemplates API resource | ||
| * Container for work item and page template sub-resources | ||
| */ | ||
| export class ProjectTemplates extends BaseResource { | ||
| public workItems: WorkItems; | ||
| public pages: Pages; | ||
|
|
||
| constructor(config: Configuration) { | ||
| super(config); | ||
| this.workItems = new WorkItems(config); | ||
| this.pages = new Pages(config); | ||
| } | ||
| } |
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,34 @@ | ||
| import { BaseResource } from "../BaseResource"; | ||
| import { Configuration } from "../../Configuration"; | ||
| import { AttachWorkflowStates } from "../../models/Workflow"; | ||
|
|
||
| /** | ||
| * WorkflowStates sub-resource | ||
| * Manages state attachments on a workflow | ||
| */ | ||
| export class States extends BaseResource { | ||
| constructor(config: Configuration) { | ||
| super(config); | ||
| } | ||
|
|
||
| /** | ||
| * Attach states to a workflow | ||
| */ | ||
| async attach( | ||
| workspaceSlug: string, | ||
| projectId: string, | ||
| workflowId: string, | ||
| data: AttachWorkflowStates | ||
| ): Promise<void> { | ||
| return this.post<void>(`/workspaces/${workspaceSlug}/projects/${projectId}/workflows/${workflowId}/states/`, data); | ||
| } | ||
|
|
||
| /** | ||
| * Detach a state from a workflow | ||
| */ | ||
| async detach(workspaceSlug: string, projectId: string, workflowId: string, stateId: string): Promise<void> { | ||
| return this.httpDelete( | ||
| `/workspaces/${workspaceSlug}/projects/${projectId}/workflows/${workflowId}/states/${stateId}/` | ||
| ); | ||
| } | ||
| } |
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,84 @@ | ||
| import { BaseResource } from "../BaseResource"; | ||
| import { Configuration } from "../../Configuration"; | ||
| import { HttpError } from "../../errors"; | ||
| import { CreateWorkflowTransition, UpdateWorkflowTransition, WorkflowTransition } from "../../models/Workflow"; | ||
|
|
||
| /** | ||
| * WorkflowTransitions sub-resource | ||
| * Manages state transitions within a workflow | ||
| */ | ||
| export class Transitions extends BaseResource { | ||
| constructor(config: Configuration) { | ||
| super(config); | ||
| } | ||
|
|
||
| /** | ||
| * List all state transitions for a workflow | ||
| */ | ||
| async list(workspaceSlug: string, projectId: string, workflowId: string): Promise<WorkflowTransition[]> { | ||
| const data = await this.get<WorkflowTransition[] | { results: WorkflowTransition[] }>( | ||
| `/workspaces/${workspaceSlug}/projects/${projectId}/workflows/${workflowId}/state-transitions/` | ||
| ); | ||
| return Array.isArray(data) ? data : data.results; | ||
| } | ||
|
|
||
| /** | ||
| * Create a state transition for a workflow. | ||
| * Returns null if the transition already exists (HTTP 400 "already exists"). | ||
| */ | ||
| async create( | ||
| workspaceSlug: string, | ||
| projectId: string, | ||
| workflowId: string, | ||
| data: CreateWorkflowTransition | ||
| ): Promise<WorkflowTransition | null> { | ||
| try { | ||
| return await this.post<WorkflowTransition>( | ||
| `/workspaces/${workspaceSlug}/projects/${projectId}/workflows/${workflowId}/state-transitions/`, | ||
| data | ||
| ); | ||
| } catch (error) { | ||
| if (error instanceof HttpError && error.statusCode === 400) { | ||
| const response = error.response as unknown; | ||
| const body = | ||
| typeof response === "string" | ||
| ? response.toLowerCase() | ||
| : typeof response === "object" && | ||
| response !== null && | ||
| "detail" in response && | ||
| typeof (response as { detail: unknown }).detail === "string" | ||
| ? (response as { detail: string }).detail.toLowerCase() | ||
| : ""; | ||
| if (body.includes("already exists")) { | ||
| return null; | ||
| } | ||
| } | ||
| throw error; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Update a workflow state transition | ||
| */ | ||
| async update( | ||
| workspaceSlug: string, | ||
| projectId: string, | ||
| workflowId: string, | ||
| transitionId: string, | ||
| data: UpdateWorkflowTransition | ||
| ): Promise<WorkflowTransition> { | ||
| return this.patch<WorkflowTransition>( | ||
| `/workspaces/${workspaceSlug}/projects/${projectId}/workflows/${workflowId}/state-transitions/${transitionId}/`, | ||
| data | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Delete a workflow state transition | ||
| */ | ||
| async del(workspaceSlug: string, projectId: string, workflowId: string, transitionId: string): Promise<void> { | ||
| return this.httpDelete( | ||
| `/workspaces/${workspaceSlug}/projects/${projectId}/workflows/${workflowId}/state-transitions/${transitionId}/` | ||
| ); | ||
| } | ||
| } | ||
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,44 @@ | ||
| import { BaseResource } from "../BaseResource"; | ||
| import { Configuration } from "../../Configuration"; | ||
| import { CreateWorkflow, UpdateWorkflow, Workflow } from "../../models/Workflow"; | ||
| import { States } from "./States"; | ||
| import { Transitions } from "./Transitions"; | ||
|
|
||
| /** | ||
| * Workflows API resource | ||
| * Handles project workflow operations and exposes states/transitions sub-resources | ||
| */ | ||
| export class Workflows extends BaseResource { | ||
| public states: States; | ||
| public transitions: Transitions; | ||
|
|
||
| constructor(config: Configuration) { | ||
| super(config); | ||
| this.states = new States(config); | ||
| this.transitions = new Transitions(config); | ||
| } | ||
|
|
||
| /** | ||
| * List all workflows for a project | ||
| */ | ||
| async list(workspaceSlug: string, projectId: string): Promise<Workflow[]> { | ||
| const data = await this.get<Workflow[] | { results: Workflow[] }>( | ||
| `/workspaces/${workspaceSlug}/projects/${projectId}/workflows/` | ||
| ); | ||
| return Array.isArray(data) ? data : data.results; | ||
| } | ||
|
|
||
| /** | ||
| * Create a new workflow for a project | ||
| */ | ||
| async create(workspaceSlug: string, projectId: string, data: CreateWorkflow): Promise<Workflow> { | ||
| return this.post<Workflow>(`/workspaces/${workspaceSlug}/projects/${projectId}/workflows/`, data); | ||
| } | ||
|
|
||
| /** | ||
| * Update a workflow by ID | ||
| */ | ||
| async update(workspaceSlug: string, projectId: string, workflowId: string, data: UpdateWorkflow): Promise<Workflow> { | ||
| return this.patch<Workflow>(`/workspaces/${workspaceSlug}/projects/${projectId}/workflows/${workflowId}/`, data); | ||
| } | ||
| } |
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,30 @@ | ||
| import { BaseModel } from "./common"; | ||
|
|
||
| /** | ||
| * Project template model interfaces | ||
| */ | ||
| export interface WorkItemTemplate extends BaseModel { | ||
| name: string; | ||
| short_description?: string; | ||
| template_data?: Record<string, unknown>; | ||
| template_type?: string; | ||
| project: string; | ||
| workspace: string; | ||
| } | ||
|
|
||
| export type CreateWorkItemTemplate = Pick<WorkItemTemplate, "name" | "short_description" | "template_data">; | ||
|
|
||
| export type UpdateWorkItemTemplate = Partial<CreateWorkItemTemplate>; | ||
|
|
||
| export interface PageTemplate extends BaseModel { | ||
| name: string; | ||
| short_description?: string; | ||
| template_data?: Record<string, unknown>; | ||
| template_type?: string; | ||
| project: string; | ||
| workspace: string; | ||
| } | ||
|
|
||
| export type CreatePageTemplate = Pick<PageTemplate, "name" | "short_description" | "template_data">; | ||
|
|
||
| export type UpdatePageTemplate = Partial<CreatePageTemplate>; |
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.