-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #58 from jonathanschmittcs/main
Update comment ID type and Time Tracking 2.0
- Loading branch information
Showing
8 changed files
with
248 additions
and
12 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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,110 @@ | ||
package clickup | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
) | ||
|
||
type TimeTrackingsService service | ||
|
||
type GetTimeTrackingResponse struct { | ||
Data TimeTrackingData `json:"data"` | ||
} | ||
|
||
type CreateTimeTrackingResponse struct { | ||
Data TimeTrackingData `json:"data"` | ||
} | ||
|
||
// See https://clickup.com/api/clickupreference/operation/Createatimeentry/ | ||
type TimeTrackingRequest struct { | ||
Description string `json:"description,omitempty"` | ||
Tags []TimeTrackingTag `json:"tags,omitempty"` | ||
Start int64 `json:"start"` | ||
End int64 `json:"end,omitempty"` | ||
Stop int64 `json:"stop,omitempty"` | ||
Billable bool `json:"billable,omitempty"` | ||
Duration int32 `json:"duration"` | ||
Assignee int `json:"assignee,omitempty"` | ||
Tid string `json:"tid,omitempty"` | ||
} | ||
|
||
type TimeTrackingTag struct { | ||
Name string `json:"name"` | ||
TagBg string `json:"tag_bg"` | ||
TagFg string `json:"tag_fg"` | ||
Creator int `json:"creator"` | ||
} | ||
|
||
type TimeTrackingData struct { | ||
ID string `json:"id"` | ||
Wid string `json:"wid"` | ||
User User `json:"user"` | ||
Billable bool `json:"billable"` | ||
Start int `json:"start"` | ||
End string `json:"end"` | ||
Duration int `json:"duration"` | ||
Description string `json:"description"` | ||
Source string `json:"source"` | ||
At int `json:"at"` | ||
IsLocked bool `json:"is_locked"` | ||
TaskLocation TaskLocation `json:"task_location"` | ||
Task Task `json:"task"` | ||
Tags []TimeTrackingTag `json:"tags"` | ||
TaskURL string `json:"task_url"` | ||
} | ||
|
||
type TaskLocation struct { | ||
ListID int `json:"list_id"` | ||
FolderID int `json:"folder_id"` | ||
SpaceID int `json:"space_id"` | ||
ListName string `json:"list_name"` | ||
FolderName string `json:"folder_name"` | ||
SpaceName string `json:"space_name"` | ||
} | ||
|
||
type CreateTimeTrackingOptions struct { | ||
CustomTaskIDs bool `url:"custom_task_ids,omitempty"` | ||
TeamID int `url:"team_id,omitempty"` | ||
} | ||
|
||
func (s *TimeTrackingsService) CreateTimeTracking(ctx context.Context, teamID string, opts *CreateTimeTrackingOptions, ttr *TimeTrackingRequest) (*CreateTimeTrackingResponse, *Response, error) { | ||
u := fmt.Sprintf("team/%s/time_entries", teamID) | ||
u, err := addOptions(u, opts) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
req, err := s.client.NewRequest("POST", u, ttr) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
timeTracking := new(CreateTimeTrackingResponse) | ||
resp, err := s.client.Do(ctx, req, timeTracking) | ||
if err != nil { | ||
return nil, resp, err | ||
} | ||
|
||
return timeTracking, resp, nil | ||
} | ||
|
||
func (s *TimeTrackingsService) GetTimeTracking(ctx context.Context, teamID string, timerID string, opts *CreateTimeTrackingOptions, ttr *TimeTrackingRequest) (*GetTimeTrackingResponse, *Response, error) { | ||
u := fmt.Sprintf("team/%s/time_entries/%s", teamID, timerID) | ||
u, err := addOptions(u, opts) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
req, err := s.client.NewRequest("GET", u, ttr) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
getTimeTrackingResponse := new(GetTimeTrackingResponse) | ||
resp, err := s.client.Do(ctx, req, getTimeTrackingResponse) | ||
if err != nil { | ||
return nil, resp, err | ||
} | ||
|
||
return getTimeTrackingResponse, resp, nil | ||
} |
This file contains 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,98 @@ | ||
package clickup | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"net/http" | ||
"testing" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
) | ||
|
||
func TestTimeTrackingService_CreateTimeTracking(t *testing.T) { | ||
client, mux, _, teardown := setup() | ||
defer teardown() | ||
|
||
input := &TimeTrackingRequest{ | ||
Description: "description", | ||
Start: 1719595398, | ||
Duration: 120000, | ||
Assignee: 99999999, | ||
Tid: "9hz", | ||
Billable: true, | ||
} | ||
|
||
mux.HandleFunc("/team/123/time_entries", func(w http.ResponseWriter, r *http.Request) { | ||
v := new(TimeTrackingRequest) | ||
json.NewDecoder(r.Body).Decode(v) | ||
|
||
testMethod(t, r, "POST") | ||
if !cmp.Equal(v, input) { | ||
t.Errorf("Request body = %+v, want %+v", v, input) | ||
} | ||
|
||
fmt.Fprint(w, | ||
`{ | ||
"data": { | ||
"id": "4090130922962924695", | ||
"task": { | ||
"id": "9hz", | ||
"name": "Test", | ||
"status": { | ||
"status": "in progress", | ||
"id": "p99999999999_99asdhAS", | ||
"color": "#5f55ee", | ||
"type": "custom", | ||
"orderindex": 1 | ||
} | ||
}, | ||
"wid": "9999999999", | ||
"user": { | ||
"id": 99999999, | ||
"username": "John", | ||
"email": "john@mail.com", | ||
"color": "#afb42b", | ||
"initials": "J", | ||
"profilePicture": "https://attachments.clickup.com/profilePictures/99999999_tX9.jpg" | ||
}, | ||
"billable": true, | ||
"start": 1719595398, | ||
"end": "1719715398", | ||
"duration": 120000, | ||
"description": "description", | ||
"tags": [], | ||
"at": 1719586940375, | ||
"is_locked": false, | ||
"task_location": {} | ||
} | ||
}`, | ||
) | ||
}) | ||
|
||
ctx := context.Background() | ||
artifacts, _, err := client.TimeTrackings.CreateTimeTracking(ctx, "123", nil, input) | ||
if err != nil { | ||
t.Errorf("Actions.ListArtifacts returned error: %v", err) | ||
} | ||
|
||
want := &CreateTimeTrackingResponse{Data: TimeTrackingData{ | ||
ID: "4090130922962924695", | ||
Wid: "9999999999", | ||
User: User{ID: 99999999, Username: "John", Email: "john@mail.com", Color: "#afb42b", Initials: "J", ProfilePicture: "https://attachments.clickup.com/profilePictures/99999999_tX9.jpg"}, | ||
Billable: true, | ||
Start: 1719595398, | ||
End: "1719715398", | ||
Duration: 120000, | ||
Description: "description", | ||
Tags: []TimeTrackingTag{}, | ||
At: 1719586940375, | ||
IsLocked: false, | ||
TaskLocation: TaskLocation{}, | ||
Task: Task{ID: "9hz", Name: "Test", Status: TaskStatus{ID: "p99999999999_99asdhAS", Status: "in progress", Color: "#5f55ee", Type: "custom", Orderindex: json.Number("1")}}, | ||
}} | ||
if !cmp.Equal(artifacts, want) { | ||
t.Errorf("Actions.ListArtifacts returned %+v, want %+v", artifacts, want) | ||
} | ||
|
||
} |
This file contains 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 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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
module github.com/raksul/go-clickup | ||
|
||
go 1.21.1 | ||
go 1.22.3 | ||
|
||
require ( | ||
github.com/google/go-cmp v0.5.8 | ||
|