forked from refiito/pipes-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
export.go
83 lines (75 loc) · 1.95 KB
/
export.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package main
import (
"strconv"
"time"
"github.com/bugsnag/bugsnag-go"
)
func fetchTimeEntries(p *Pipe) error {
return nil
}
func postTimeEntries(p *Pipe) error {
var err error
var entriesCon *Connection
var usersCon, tasksCon, projectsCon *ReversedConnection
service, err := p.Service()
if err != nil {
return err
}
if usersCon, err = loadConnectionRev(service, "users"); err != nil {
return err
}
if tasksCon, err = loadConnectionRev(service, "tasks"); err != nil {
return err
}
if projectsCon, err = loadConnectionRev(service, "projects"); err != nil {
return err
}
if entriesCon, err = loadConnection(service, "time_entries"); err != nil {
return err
}
if p.lastSync == nil {
currentTime := time.Now()
p.lastSync = ¤tTime
}
timeEntries, err := getTogglTimeEntries(
p.authorization.WorkspaceToken, *p.lastSync,
usersCon.getKeys(), projectsCon.getKeys(),
)
if err != nil {
return err
}
for _, entry := range timeEntries {
entry.foreignID = entriesCon.Data[strconv.Itoa(entry.ID)]
entry.foreignTaskID = tasksCon.getInt(entry.TaskID)
entry.foreignUserID = usersCon.getInt(entry.UserID)
entry.foreignProjectID = projectsCon.getInt(entry.ProjectID)
entryID, err := service.ExportTimeEntry(&entry)
if err != nil {
bugsnag.Notify(err, bugsnag.MetaData{
"Workspace": {
"ID": service.WorkspaceID(),
},
"Entry": {
"ID": entry.ID,
"TaskID": entry.TaskID,
"UserID": entry.UserID,
"ProjectID": entry.ProjectID,
},
"Foreign Entry": {
"foreignID": entry.foreignID,
"foreignTaskID": entry.foreignTaskID,
"foreignUserID": entry.foreignUserID,
"foreignProjectID": entry.foreignProjectID,
},
})
p.PipeStatus.addError(err)
} else {
entriesCon.Data[strconv.Itoa(entry.ID)] = entryID
}
}
if err := entriesCon.save(); err != nil {
return err
}
p.PipeStatus.complete("timeentries", []string{}, len(timeEntries))
return nil
}