cleanup api a bit, load assets live
This commit is contained in:
parent
ab35fe1ea1
commit
be40114e72
@ -329,14 +329,7 @@ func linkDELETE(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var templateFuncs = template.FuncMap{
|
var templateFuncs = template.FuncMap{
|
||||||
"includeWatch": func(repo string, number int, ignoreList []data.PullRequestIgnore) bool {
|
"includeWatch": includeWatch,
|
||||||
for _, pri := range ignoreList {
|
|
||||||
if pri.Repo == repo && pri.Number == int64(number) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
},
|
|
||||||
"remaining": func(d time.Time) string {
|
"remaining": func(d time.Time) string {
|
||||||
ct := time.Now()
|
ct := time.Now()
|
||||||
left := d.Sub(ct)
|
left := d.Sub(ct)
|
||||||
|
7
main.go
7
main.go
@ -104,16 +104,13 @@ func main() {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
fileServer := http.FileServer(http.FS(assets))
|
liveServer := http.FileServer(http.Dir("./assets"))
|
||||||
r := chi.NewRouter()
|
r := chi.NewRouter()
|
||||||
|
|
||||||
r.Use(middleware.Logger)
|
r.Use(middleware.Logger)
|
||||||
r.Use(OwnerCtx)
|
r.Use(OwnerCtx)
|
||||||
|
|
||||||
r.Mount("/assets", fileServer)
|
r.Mount("/", liveServer)
|
||||||
r.Route("/", func(r chi.Router) {
|
|
||||||
r.Get("/", index)
|
|
||||||
})
|
|
||||||
r.Route("/pullrequests", func(r chi.Router) {
|
r.Route("/pullrequests", func(r chi.Router) {
|
||||||
r.Use(render.SetContentType(render.ContentTypeJSON))
|
r.Use(render.SetContentType(render.ContentTypeJSON))
|
||||||
r.Get("/", pullrequestsGET)
|
r.Get("/", pullrequestsGET)
|
||||||
|
22
src/Data.elm
22
src/Data.elm
@ -1,4 +1,22 @@
|
|||||||
module Data exposing (Node, RepoInfo, Watch)
|
module Data exposing (Link, Links, Node, RepoInfo, Watch, Watches)
|
||||||
|
|
||||||
|
|
||||||
|
type alias Watches =
|
||||||
|
List Watch
|
||||||
|
|
||||||
|
|
||||||
|
type alias Links =
|
||||||
|
List Link
|
||||||
|
|
||||||
|
|
||||||
|
type alias Link =
|
||||||
|
{ id : Int
|
||||||
|
, createdAt : String
|
||||||
|
, url : String
|
||||||
|
, name : String
|
||||||
|
, logoURL : String
|
||||||
|
, shared : Bool
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
type alias Watch =
|
type alias Watch =
|
||||||
@ -6,7 +24,7 @@ type alias Watch =
|
|||||||
, name : String
|
, name : String
|
||||||
, repo : String
|
, repo : String
|
||||||
, resultCount : Int
|
, resultCount : Int
|
||||||
, results : Maybe (List Node)
|
, results : List Node
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
36
watches.go
36
watches.go
@ -9,6 +9,8 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"sort"
|
"sort"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"suah.dev/gostart/data"
|
||||||
)
|
)
|
||||||
|
|
||||||
const gqEndPoint = "https://api.github.com/graphql"
|
const gqEndPoint = "https://api.github.com/graphql"
|
||||||
@ -57,16 +59,47 @@ type GQLQuery struct {
|
|||||||
|
|
||||||
type WatchResults []WatchResult
|
type WatchResults []WatchResult
|
||||||
|
|
||||||
|
func includeWatch(repo string, number int, ignoreList []data.PullRequestIgnore) bool {
|
||||||
|
for _, pri := range ignoreList {
|
||||||
|
if pri.Repo == repo && pri.Number == int64(number) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
func (w *WatchResults) forID(ownerID int64) *WatchResults {
|
func (w *WatchResults) forID(ownerID int64) *WatchResults {
|
||||||
newResults := WatchResults{}
|
newResults := WatchResults{}
|
||||||
|
tmpResults := WatchResults{}
|
||||||
|
ctx := context.Background()
|
||||||
|
ignores, _ := app.queries.GetAllPullRequestIgnores(ctx, ownerID)
|
||||||
|
|
||||||
for _, r := range *w {
|
for _, r := range *w {
|
||||||
if r.OwnerID == ownerID {
|
if r.OwnerID == ownerID {
|
||||||
newResults = append(newResults, r)
|
if r.Results == nil {
|
||||||
|
r.Results = make([]Node, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
tmpResults = append(tmpResults, r)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sort.Slice(newResults, func(i, j int) bool {
|
sort.Slice(newResults, func(i, j int) bool {
|
||||||
return newResults[i].Name < newResults[j].Name
|
return newResults[i].Name < newResults[j].Name
|
||||||
})
|
})
|
||||||
|
|
||||||
|
for _, r := range tmpResults {
|
||||||
|
tmpResultList := []Node{}
|
||||||
|
for _, entry := range r.Results {
|
||||||
|
if includeWatch(entry.Repository.NameWithOwner, entry.Number, ignores) {
|
||||||
|
tmpResultList = append(tmpResultList, entry)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
r.Results = tmpResultList
|
||||||
|
r.ResultCount = len(tmpResultList)
|
||||||
|
newResults = append(newResults, r)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
return &newResults
|
return &newResults
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,7 +133,6 @@ func UpdateWatches(ghToken string) (*WatchResults, error) {
|
|||||||
wr.OwnerID = watch.OwnerID
|
wr.OwnerID = watch.OwnerID
|
||||||
wr.Name = watch.Name
|
wr.Name = watch.Name
|
||||||
wr.Repo = watch.Repo
|
wr.Repo = watch.Repo
|
||||||
wr.ResultCount = wr.Data.Search.IssueCount
|
|
||||||
for _, dr := range wr.Data.Search.Edges {
|
for _, dr := range wr.Data.Search.Edges {
|
||||||
wr.Results = append(wr.Results, dr.Node)
|
wr.Results = append(wr.Results, dr.Node)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user