fix fetching of watch items
This commit is contained in:
parent
706275cc71
commit
cb1dd3f69c
@ -53,6 +53,16 @@ type PullRequestIgnore struct {
|
||||
Repo string `json:"repo"`
|
||||
}
|
||||
|
||||
type Todo struct {
|
||||
OwnerID int64 `json:"owner_id"`
|
||||
LinkID int64 `json:"link_id"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
CompletedAt sql.NullTime `json:"completed_at"`
|
||||
Completed bool `json:"completed"`
|
||||
Title string `json:"title"`
|
||||
Body string `json:"body"`
|
||||
}
|
||||
|
||||
type WatchItem struct {
|
||||
ID int64 `json:"id"`
|
||||
OwnerID int64 `json:"owner_id"`
|
||||
|
13
main.go
13
main.go
@ -57,7 +57,6 @@ func main() {
|
||||
if err != nil {
|
||||
log.Fatal("can't get ts local client: ", err)
|
||||
}
|
||||
app.watches = &WatchResults{}
|
||||
|
||||
if *dbFile == ":memory:" {
|
||||
tmpDBPopulate(db)
|
||||
@ -138,11 +137,15 @@ func main() {
|
||||
}
|
||||
|
||||
go func() {
|
||||
err := app.watches.Update(ghToken)
|
||||
if err != nil {
|
||||
log.Fatal("can't update watches: ", err)
|
||||
for {
|
||||
var err error
|
||||
app.watches, err = UpdateWatches(ghToken)
|
||||
if err != nil {
|
||||
log.Fatal("can't update watches: ", err)
|
||||
}
|
||||
time.Sleep(5 * time.Minute)
|
||||
}
|
||||
time.Sleep(5 * time.Minute)
|
||||
|
||||
}()
|
||||
|
||||
go func() {
|
||||
|
38
page.go
38
page.go
@ -100,9 +100,9 @@ type Page struct {
|
||||
PullRequests []data.PullRequest
|
||||
Links []data.Link
|
||||
Node tailcfg.Node
|
||||
Watches WatchResults
|
||||
CurrentLimits *RateLimit
|
||||
Ignores []data.PullRequestIgnore
|
||||
Watches *WatchResults
|
||||
}
|
||||
|
||||
func (p *Page) Sort() {
|
||||
@ -112,27 +112,21 @@ func (p *Page) Sort() {
|
||||
sort.Slice(p.PullRequests, func(i, j int) bool {
|
||||
return p.PullRequests[i].Number > p.PullRequests[j].Number
|
||||
})
|
||||
sort.Slice(p.Watches, func(i, j int) bool {
|
||||
return p.Watches[i].Name < p.Watches[j].Name
|
||||
})
|
||||
for _, w := range p.Watches {
|
||||
sort.Slice(w.Data.Search.Edges, func(i, j int) bool {
|
||||
return w.Data.Search.Edges[i].Node.CreatedAt.After(w.Data.Search.Edges[j].Node.CreatedAt)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
type WatchResults []WatchResult
|
||||
|
||||
func (w *WatchResults) forID(ownerID int64) WatchResults {
|
||||
func (w *WatchResults) forID(ownerID int64) *WatchResults {
|
||||
newResults := WatchResults{}
|
||||
for _, r := range *w {
|
||||
if r.OwnerID == ownerID {
|
||||
newResults = append(newResults, r)
|
||||
}
|
||||
}
|
||||
|
||||
return newResults
|
||||
sort.Slice(newResults, func(i, j int) bool {
|
||||
return newResults[i].Name < newResults[j].Name
|
||||
})
|
||||
return &newResults
|
||||
}
|
||||
|
||||
func (w WatchResults) GetLimits() *RateLimit {
|
||||
@ -146,28 +140,36 @@ func (w WatchResults) GetLimits() *RateLimit {
|
||||
return rl
|
||||
}
|
||||
|
||||
func (w *WatchResults) Update(ghToken string) error {
|
||||
func UpdateWatches(ghToken string) (*WatchResults, error) {
|
||||
ctx := context.Background()
|
||||
w := WatchResults{}
|
||||
|
||||
watches, err := app.queries.GetAllWatchItems(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, watch := range watches {
|
||||
qd := GQLQuery{Query: fmt.Sprintf(graphQuery, watch.Repo, watch.Name)}
|
||||
wr, err := getData(qd, ghToken)
|
||||
if err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// TODO: cross ref the list of ignores and prune the wr accordingly
|
||||
wr.OwnerID = watch.OwnerID
|
||||
wr.Name = watch.Name
|
||||
wr.Repo = watch.Repo
|
||||
*w = append(*w, *wr)
|
||||
sort.Slice(wr.Data.Search.Edges, func(i, j int) bool {
|
||||
return wr.Data.Search.Edges[i].Node.CreatedAt.After(wr.Data.Search.Edges[j].Node.CreatedAt)
|
||||
})
|
||||
w = append(w, *wr)
|
||||
}
|
||||
|
||||
return nil
|
||||
sort.Slice(w, func(i, j int) bool {
|
||||
return w[i].Name < w[j].Name
|
||||
})
|
||||
|
||||
return &w, nil
|
||||
}
|
||||
|
||||
type WatchResult struct {
|
||||
|
Loading…
Reference in New Issue
Block a user