-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcache.go
More file actions
84 lines (72 loc) · 2.1 KB
/
Copy pathcache.go
File metadata and controls
84 lines (72 loc) · 2.1 KB
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
84
//
// Copyright (c) 2019 Sony Mobile Communications Inc.
// SPDX-License-Identifier: MIT
//
package cmd
import (
"fmt"
"ghorgs/gnet"
"ghorgs/model"
"ghorgs/utils"
"log"
"net/http"
)
// Cache takes a list of entities represented with Entity interface,
// queries GitHub for the data for those entities and stores the
// result of the query in a Table (or returns an error).
func Cache(request []model.Entity) (map[string]*model.Table, error) {
result := make(map[string]*model.Table, len(request))
for _, entity := range request {
fmt.Printf("\nCaching %s...", entity.GetName())
t := entity.MakeTable()
req := entity.MakeQuery(gnet.Conf.Organization)
if utils.Debug.Verbose {
log.Print(req)
}
gitHubRequest := gnet.MakeGitHubV4Request(req.GetGraphQlJson(), gnet.Conf.Token)
resp, status := gitHubRequest.Execute()
if status.Code != http.StatusOK {
return result, fmt.Errorf("Error! HttpResponse: %s", status.Status)
}
if utils.Debug.Verbose {
log.Print(resp)
}
entity.FromJsonBuffer(resp)
entity.AppendTable(t)
counter := req.GetCount()
if utils.Debug.Verbose {
log.Print(entity)
} else {
if counter <= entity.GetTotal() {
fmt.Printf("\n%s: %d/%d", entity.GetName(), counter, entity.GetTotal())
} else {
fmt.Printf("\n%s: %d/%d", entity.GetName(), entity.GetTotal(), entity.GetTotal())
}
}
for entity.HasNext() {
req.GetNext(entity.GetNext())
gitHubRequest = gnet.MakeGitHubV4Request(req.GetGraphQlJson(), gnet.Conf.Token)
resp, status = gitHubRequest.Execute()
if status.Code != http.StatusOK {
return result, fmt.Errorf("Error! HttpResponse: %s", status.Status)
}
entity.FromJsonBuffer(resp)
entity.AppendTable(t)
if utils.Debug.Verbose {
log.Print(entity)
} else {
counter += req.GetCount()
if counter <= entity.GetTotal() {
fmt.Printf("\r%s: %d/%d", entity.GetName(), counter, entity.GetTotal())
} else {
fmt.Printf("\r%s: %d/%d", entity.GetName(), entity.GetTotal(), entity.GetTotal())
}
}
}
result[entity.GetName()] = t
if !utils.Debug.Verbose {
fmt.Printf("\n")
}
}
return result, nil
}