Skip to content
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
79 changes: 42 additions & 37 deletions models/compat/wakatime/v1/heartbeat.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package v1

import (
"github.com/duke-git/lancet/v2/stream"
"net/http"
"strconv"
"time"

"github.com/duke-git/lancet/v2/stream"

"github.com/muety/wakapi/models"
)

Expand Down Expand Up @@ -59,49 +60,53 @@ type HeartbeatResponseData struct {
// that is actually required for the import

type HeartbeatEntry struct {
Id string `json:"id"`
Branch string `json:"branch"`
Category string `json:"category"`
Entity string `json:"entity"`
IsWrite bool `json:"is_write"`
Language string `json:"language"`
Project string `json:"project"`
Time float64 `json:"time"`
Type string `json:"type"`
UserId string `json:"user_id"`
MachineNameId string `json:"machine_name_id"`
UserAgentId string `json:"user_agent_id"`
Lines int `json:"lines"`
LineNo int `json:"lineno"`
CursorPos int `json:"cursorpos"`
LineDeletions int `json:"line_deletions"`
LineAdditions int `json:"line_additions"`
CreatedAt time.Time `json:"created_at"`
Id string `json:"id"`
Branch string `json:"branch"`
Category string `json:"category"`
Entity string `json:"entity"`
IsWrite bool `json:"is_write"`
Language string `json:"language"`
Project string `json:"project"`
Time float64 `json:"time"`
Type string `json:"type"`
UserId string `json:"user_id"`
MachineNameId string `json:"machine_name_id"`
UserAgentId string `json:"user_agent_id"`
Lines int `json:"lines"`
LineNo int `json:"lineno"`
CursorPos int `json:"cursorpos"`
LineDeletions int `json:"line_deletions"`
LineAdditions int `json:"line_additions"`
CreatedAt time.Time `json:"created_at"`
AILineChanges int `json:"ai_line_changes,omitempty" hash:"ignore"`
HumanLineChanges int `json:"human_line_changes,omitempty" hash:"ignore"`
}

func HeartbeatsToCompat(entries []*models.Heartbeat) []*HeartbeatEntry {
out := make([]*HeartbeatEntry, len(entries))
for i := 0; i < len(entries); i++ {
entry := entries[i]
out[i] = &HeartbeatEntry{
Id: strconv.FormatUint(entry.ID, 10),
Branch: entry.Branch,
Category: entry.Category,
Entity: entry.Entity,
IsWrite: entry.IsWrite,
Language: entry.Language,
Project: entry.Project,
Time: float64(entry.Time.T().Unix()),
Type: entry.Type,
UserId: entry.UserID,
MachineNameId: entry.Machine,
UserAgentId: entry.UserAgent,
Lines: entry.Lines,
LineNo: entry.LineNo,
LineAdditions: entry.LineAdditions,
LineDeletions: entry.LineDeletions,
CursorPos: entry.CursorPos,
CreatedAt: entry.CreatedAt.T(),
Id: strconv.FormatUint(entry.ID, 10),
Branch: entry.Branch,
Category: entry.Category,
Entity: entry.Entity,
IsWrite: entry.IsWrite,
Language: entry.Language,
Project: entry.Project,
Time: float64(entry.Time.T().Unix()),
Type: entry.Type,
UserId: entry.UserID,
MachineNameId: entry.Machine,
UserAgentId: entry.UserAgent,
Lines: entry.Lines,
LineNo: entry.LineNo,
LineAdditions: entry.LineAdditions,
LineDeletions: entry.LineDeletions,
CursorPos: entry.CursorPos,
CreatedAt: entry.CreatedAt.T(),
AILineChanges: entry.AILineChanges,
HumanLineChanges: entry.HumanLineChanges,
}
}
return out
Expand Down
2 changes: 2 additions & 0 deletions models/heartbeat.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ type Heartbeat struct {
LineDeletions int `json:"line_deletions,omitempty" hash:"ignore"`
LineAdditions int `json:"line_additions,omitempty" hash:"ignore"`
ProjectRootCount int `json:"project_root_count,omitempty" hash:"ignore"`
AILineChanges int `json:"ai_line_changes,omitempty" hash:"ignore"`
HumanLineChanges int `json:"human_line_changes,omitempty" hash:"ignore"`
}

func (h *Heartbeat) Valid() bool {
Expand Down
8 changes: 8 additions & 0 deletions static/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ definitions:
type: integer
line_deletions:
type: integer
ai_line_changes:
type: integer
human_line_changes:
type: integer
lineno:
type: integer
lines:
Expand Down Expand Up @@ -198,6 +202,10 @@ definitions:
type: integer
line_deletions:
type: integer
ai_line_changes:
type: integer
human_line_changes:
type: integer
lineno:
type: integer
lines:
Expand Down