forked from refiito/pipes-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathintegration.go
53 lines (48 loc) · 1.38 KB
/
integration.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
package main
type (
Integration struct {
ID string `json:"id"`
Name string `json:"name"`
Link string `json:"link"`
Image string `json:"image"`
Pipes []*Pipe `json:"pipes"`
AuthURL string `json:"auth_url,omitempty"`
AuthType string `json:"auth_type,omitempty"`
Authorized bool `json:"authorized"`
}
)
func workspaceIntegrations(workspaceID int) ([]Integration, error) {
authorizations, err := loadAuthorizations(workspaceID)
if err != nil {
return nil, err
}
workspacePipes, err := loadPipes(workspaceID)
if err != nil {
return nil, err
}
pipeStatuses, err := loadPipeStatuses(workspaceID)
if err != nil {
return nil, err
}
var integrations []Integration
for j := range availableIntegrations {
var integration = *availableIntegrations[j]
integration.AuthURL = oAuth2URL(integration.ID)
integration.Authorized = authorizations[integration.ID]
var pipes []*Pipe
for i := range integration.Pipes {
var pipe = *integration.Pipes[i]
key := pipesKey(integration.ID, pipe.ID)
existingPipe := workspacePipes[key]
if existingPipe != nil {
pipe.Automatic = existingPipe.Automatic
pipe.Configured = existingPipe.Configured
}
pipe.PipeStatus = pipeStatuses[key]
pipes = append(pipes, &pipe)
}
integration.Pipes = pipes
integrations = append(integrations, integration)
}
return integrations, nil
}