From 7a3cf08dcfe47f78fcfa04a87b083a420759bc7b Mon Sep 17 00:00:00 2001 From: Aaron Bieber Date: Tue, 29 Nov 2022 20:45:48 -0700 Subject: [PATCH] new css, ability to query any repo for watch items --- .idea/vcs.xml | 6 ++++ data/models.go | 1 + data/queries.sql.go | 19 ++++++++--- page.go | 6 ++-- queries.sql | 4 +-- schema.sql | 38 +++++++++++----------- templates/main.html | 77 +++++++++++++++++++++++++++------------------ tmp.go | 28 +++++++++++------ 8 files changed, 112 insertions(+), 67 deletions(-) create mode 100644 .idea/vcs.xml diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/data/models.go b/data/models.go index fdf264a..b2f7b65 100644 --- a/data/models.go +++ b/data/models.go @@ -56,5 +56,6 @@ type WatchItem struct { OwnerID int64 `json:"owner_id"` CreatedAt time.Time `json:"created_at"` Name string `json:"name"` + Repo string `json:"repo"` Descr sql.NullString `json:"descr"` } diff --git a/data/queries.sql.go b/data/queries.sql.go index b76b7ab..f904e75 100644 --- a/data/queries.sql.go +++ b/data/queries.sql.go @@ -146,24 +146,31 @@ func (q *Queries) AddPullRequestIgnore(ctx context.Context, arg AddPullRequestIg } const addWatchItem = `-- name: AddWatchItem :one -insert into watch_items (owner_id, name, descr) -values (?, ?, ?) returning id, owner_id, created_at, name, descr +insert into watch_items (owner_id, name, repo, descr) +values (?, ?, ?, ?) returning id, owner_id, created_at, name, repo, descr ` type AddWatchItemParams struct { OwnerID int64 `json:"owner_id"` Name string `json:"name"` + Repo string `json:"repo"` Descr sql.NullString `json:"descr"` } func (q *Queries) AddWatchItem(ctx context.Context, arg AddWatchItemParams) (WatchItem, error) { - row := q.db.QueryRowContext(ctx, addWatchItem, arg.OwnerID, arg.Name, arg.Descr) + row := q.db.QueryRowContext(ctx, addWatchItem, + arg.OwnerID, + arg.Name, + arg.Repo, + arg.Descr, + ) var i WatchItem err := row.Scan( &i.ID, &i.OwnerID, &i.CreatedAt, &i.Name, + &i.Repo, &i.Descr, ) return i, err @@ -364,7 +371,7 @@ func (q *Queries) GetAllPullRequests(ctx context.Context, arg GetAllPullRequests } const getAllWatchItems = `-- name: GetAllWatchItems :many -select id, owner_id, created_at, name, descr +select id, owner_id, created_at, name, repo, descr from watch_items ` @@ -382,6 +389,7 @@ func (q *Queries) GetAllWatchItems(ctx context.Context) ([]WatchItem, error) { &i.OwnerID, &i.CreatedAt, &i.Name, + &i.Repo, &i.Descr, ); err != nil { return nil, err @@ -398,7 +406,7 @@ func (q *Queries) GetAllWatchItems(ctx context.Context) ([]WatchItem, error) { } const getAllWatchItemsByOwner = `-- name: GetAllWatchItemsByOwner :many -select id, owner_id, created_at, name, descr +select id, owner_id, created_at, name, repo, descr from watch_items where owner_id = ? ` @@ -417,6 +425,7 @@ func (q *Queries) GetAllWatchItemsByOwner(ctx context.Context, ownerID int64) ([ &i.OwnerID, &i.CreatedAt, &i.Name, + &i.Repo, &i.Descr, ); err != nil { return nil, err diff --git a/page.go b/page.go index f5fcdfc..a31653b 100644 --- a/page.go +++ b/page.go @@ -18,7 +18,7 @@ const gqEndPoint = "https://api.github.com/graphql" const graphQuery = ` { search( - query: "is:open is:public archived:false repo:nixos/nixpkgs in:title %s", + query: "is:open is:public archived:false repo:%s in:title %s", type: ISSUE, first: 20 ) { @@ -144,7 +144,7 @@ func (w *WatchResults) Update(ghToken string) error { } for _, watch := range watches { - qd := GQLQuery{Query: fmt.Sprintf(graphQuery, watch.Name)} + qd := GQLQuery{Query: fmt.Sprintf(graphQuery, watch.Repo, watch.Name)} wr, err := getData(qd, ghToken) if err != nil { return err @@ -153,6 +153,7 @@ func (w *WatchResults) Update(ghToken string) error { // 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) } @@ -163,6 +164,7 @@ type WatchResult struct { Data Data `json:"data,omitempty"` OwnerID int64 Name string + Repo string } type Repository struct { NameWithOwner string `json:"nameWithOwner,omitempty"` diff --git a/queries.sql b/queries.sql index fbc67e0..a6c3c8b 100644 --- a/queries.sql +++ b/queries.sql @@ -17,8 +17,8 @@ from watch_items where owner_id = ?; -- name: AddWatchItem :one -insert into watch_items (owner_id, name, descr) -values (?, ?, ?) returning *; +insert into watch_items (owner_id, name, repo, descr) +values (?, ?, ?, ?) returning *; -- name: DeleteWatchItem :exec delete from watch_items where id = ? and owner_id = ?; diff --git a/schema.sql b/schema.sql index 56a2a2b..2a93fc9 100644 --- a/schema.sql +++ b/schema.sql @@ -7,45 +7,47 @@ create table owners create table watch_items ( id integer primary key autoincrement, - owner_id INTEGER REFERENCES owners (id) not null, + owner_id INTEGER REFERENCES owners (id) not null, created_at datetime default current_timestamp not null, - name text not null unique, - descr text + name text not null, + repo text not null, + descr text, + unique (name, repo) ); create table pull_request_ignores ( id integer primary key autoincrement, - owner_id INTEGER REFERENCES owners (id) not null, + owner_id INTEGER REFERENCES owners (id) not null, created_at datetime default current_timestamp not null, - number integer not null, - repo text not null, + number integer not null, + repo text not null, unique (number, repo) ); create table links ( - id integer primary key autoincrement, - owner_id INTEGER REFERENCES owners (id) not null, + id integer primary key autoincrement, + owner_id INTEGER REFERENCES owners (id) not null, created_at datetime default current_timestamp not null, - url text not null unique, - name text not null, + url text not null unique, + name text not null, logo_url text ); create table pull_requests ( id integer primary key autoincrement, - owner_id INTEGER REFERENCES owners (id) not null, + owner_id INTEGER REFERENCES owners (id) not null, created_at datetime default current_timestamp not null, - number integer not null unique, - repo text not null, + number integer not null unique, + repo text not null, description text, commitid text ); create table icons ( - id integer primary key autoincrement, - owner_id INTEGER REFERENCES owners (id) not null, + id integer primary key autoincrement, + owner_id INTEGER REFERENCES owners (id) not null, created_at datetime default current_timestamp not null, - url text not null unique, - content_type text not null, - data blob not null + url text not null unique, + content_type text not null, + data blob not null ); diff --git a/templates/main.html b/templates/main.html index 6e43c6c..86eb2d0 100644 --- a/templates/main.html +++ b/templates/main.html @@ -1,6 +1,6 @@ - + {{.Title}}::{{.Node.ComputedName}} -

{{.Title}} for {{.Node.ComputedName}}

-

Pull Requests

- - -

Watch Items

- - -

Links

- - -Remaining queries: {{.CurrentLimits.Remaining}} +
+

{{.Title}} for {{.Node.ComputedName}}

+ + +
+
+

Pull Requests

+ +

Watch Items

+ + +
+

Add Watch Item

+

+ +

+ +
+
+
+ diff --git a/tmp.go b/tmp.go index d162296..440ab73 100644 --- a/tmp.go +++ b/tmp.go @@ -15,12 +15,13 @@ func tmpDBPopulate(db *sql.DB) { ownerID := int64(57395170551826799) - a, err := app.queries.AddOwner(app.ctx, data.AddOwnerParams{ + _, err := app.queries.AddOwner(app.ctx, data.AddOwnerParams{ ID: 57395170551826799, Name: "europa.humpback-trout.ts.net.", }) - log.Println(a, err) - + if err != nil { + log.Fatal(err) + } b, err := app.queries.AddLink(app.ctx, data.AddLinkParams{ OwnerID: ownerID, Url: "https://tapenet.org", @@ -28,23 +29,30 @@ func tmpDBPopulate(db *sql.DB) { }) log.Println(b, err) - c, err := app.queries.AddPullRequest(app.ctx, data.AddPullRequestParams{ + _, err = app.queries.AddPullRequest(app.ctx, data.AddPullRequestParams{ OwnerID: ownerID, Number: 1234, Repo: "NixOS/nixpkgs", Description: sql.NullString{String: "who knows"}, }) - log.Println(c, err) - - d, err := app.queries.AddWatchItem(app.ctx, data.AddWatchItemParams{ + if err != nil { + log.Fatal(err) + } + _, err = app.queries.AddWatchItem(app.ctx, data.AddWatchItemParams{ Name: "tailscale", + Repo: "NixOS/nixpkgs", OwnerID: ownerID, }) - log.Println(d, err) + if err != nil { + log.Fatal(err) + } - e, err := app.queries.AddWatchItem(app.ctx, data.AddWatchItemParams{ + _, err = app.queries.AddWatchItem(app.ctx, data.AddWatchItemParams{ Name: "openssh", OwnerID: ownerID, + Repo: "NixOS/nixpkgs", }) - log.Println(e, err) + if err != nil { + log.Fatal(err) + } }