Skip to content
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

Add Custom Task Type Support #50

Merged
merged 5 commits into from
Jan 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,8 @@ If you are new to pull requests, checkout Collaborating on projects using issues
- [x] Update Webhook
- [x] Delete Webhook
- [x] Get Webhooks
- [x] Custom Task Types
- [x] Get Custom Task Types

## License
This project is released under the terms of the [MIT license](http://en.wikipedia.org/wiki/MIT_License).
2 changes: 2 additions & 0 deletions clickup/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type Client struct {
Checklists *ChecklistsService
Comments *CommentsService
CustomFields *CustomFieldsService
CustomTaskTypes *CustomTaskTypesService
Dependencies *DependenciesService
Goals *GoalsService
Tasks *TasksService
Expand Down Expand Up @@ -131,6 +132,7 @@ func NewClient(httpClient *http.Client, APIKey string) *Client {
c.Checklists = (*ChecklistsService)(&c.common)
c.Comments = (*CommentsService)(&c.common)
c.CustomFields = (*CustomFieldsService)(&c.common)
c.CustomTaskTypes = (*CustomTaskTypesService)(&c.common)
c.Dependencies = (*DependenciesService)(&c.common)
c.Goals = (*GoalsService)(&c.common)
c.Tasks = (*TasksService)(&c.common)
Expand Down
47 changes: 47 additions & 0 deletions clickup/custom_task_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package clickup

import (
"context"
"fmt"
)

type CustomTaskTypesService service

// See https://clickup.com/api/clickupreference/operation/GetCustomItems/
type GetCustomTaskTypesResponse struct {
CustomItems []CustomItem `json:"custom_items,omitempty"` // Array of custom task types.
}

// See https://clickup.com/api/clickupreference/operation/GetCustomItems/
type CustomItem struct {
Id int32 `json:"id,omitempty"` // Custom task type ID.
Name string `json:"name,omitempty"` // Custom task type name.
NamePlural string `json:"name_plural,omitempty"` // Custom task type plural name.
Description string `json:"description,omitempty"` // Custom task type description.

// Not documented in API explorer
Avatar CustomItemAvatar `json:"avatar,omitempty"` // Custom task icon data.
}

// Not documented in API explorer. Comments are observations.
type CustomItemAvatar struct {
Source string `json:"source,omitempty"` // null (ClickUp Milestone Glyph), fas (Font Awesome Solid), fab (Font Awesome Brands).
Value string `json:"value,omitempty"` // null is for ClickUp Glyphs, e.g., Task and Milestone.
}

// See https://clickup.com/api/clickupreference/operation/GetCustomItems/
func (s *CustomTaskTypesService) GetCustomTaskTypes(ctx context.Context, teamId string) ([]CustomItem, *Response, error) {
u := fmt.Sprintf("team/%s/custom_item", teamId)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}

gcttr := new(GetCustomTaskTypesResponse)
resp, err := s.client.Do(ctx, req, gcttr)
if err != nil {
return nil, resp, err
}

return gcttr.CustomItems, resp, nil
}
33 changes: 33 additions & 0 deletions clickup/custom_task_types_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package clickup

import (
"context"
"fmt"
"net/http"
"testing"

"github.com/google/go-cmp/cmp"
)

func TestCustomTaskTypesService_GetCustomTaskTypes(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()

mux.HandleFunc(("/team/1234/custom_item"), func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprint(w, `{"custom_items": [{"id": 1300, "name": "Bug", "name_plural": "Bugs", "description": "Custom item type for bugs.", "avatar": { "source": "fas", "value": "bug" }}]}`)
})

ctx := context.Background()
customTaskTypes, _, err := client.CustomTaskTypes.GetCustomTaskTypes(ctx, "1234")
if err != nil {
t.Errorf("CustomTaskTypes.GetCustomTaskTypes returned error: %v", err)
}

want := []CustomItem{
{Id: 1300, Name: "Bug", NamePlural: "Bugs", Description: "Custom item type for bugs.", Avatar: CustomItemAvatar{Source: "fas", Value: "bug"}},
}
if !cmp.Equal(customTaskTypes, want) {
t.Errorf("CustomTaskTypes.GetCustomTaskTypes returned %+v, want %+v", customTaskTypes, want)
}
}
3 changes: 3 additions & 0 deletions clickup/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type GetTasksResponse struct {

type GetBulkTasksTimeInStatusResponse map[string]TasksInStatus

// See https://clickup.com/api/clickupreference/operation/CreateTask/
type TaskRequest struct {
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
Expand All @@ -33,6 +34,7 @@ type TaskRequest struct {
LinksTo string `json:"links_to,omitempty"`
CheckRequiredCustomFields bool `json:"check_required_custom_fields,omitempty"`
CustomFields []CustomFieldInTaskRequest `json:"custom_fields,omitempty"`
CustomItemId int `json:"custom_item_id,omitempty"` // To create a task that doesn't use a custom task type, either don't include this field in the request body, or send 'null'. To create this task as a Milestone, send a value of 1. To use a custom task type, send the custom task type ID as defined in your Workspace, such as 2.
}

type CustomFieldInTaskRequest struct {
Expand All @@ -43,6 +45,7 @@ type CustomFieldInTaskRequest struct {
type Task struct {
ID string `json:"id"`
CustomID string `json:"custom_id"`
CustomItemId int `json:"custom_item_id"` // A null value means this item is a task. A value of 1 is a Milestone. Any other number is a custom task type.
Name string `json:"name"`
TextContent string `json:"text_content"`
Description string `json:"description"`
Expand Down
10 changes: 6 additions & 4 deletions clickup/tasks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func TestTasksService_GetTask(t *testing.T) {
`{
"id": "9hx",
"custom_id":null,
"custom_item_id": null,
"name": "Task Name",
"text_content": "New Task Description",
"description": "New Task Description",
Expand Down Expand Up @@ -80,10 +81,11 @@ func TestTasksService_GetTask(t *testing.T) {
}

want := &Task{
ID: "9hx",
Name: "Task Name",
TextContent: "New Task Description",
Description: "New Task Description",
ID: "9hx",
CustomItemId: 0,
Name: "Task Name",
TextContent: "New Task Description",
Description: "New Task Description",
Status: TaskStatus{
Status: "in progress",
Color: "#d3d3d3",
Expand Down
Loading