new css, ability to query any repo for watch items

This commit is contained in:
Aaron Bieber 2022-11-29 20:45:48 -07:00
parent c68076859a
commit 7a3cf08dcf
No known key found for this signature in database
8 changed files with 112 additions and 67 deletions

6
.idea/vcs.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

View File

@ -56,5 +56,6 @@ type WatchItem struct {
OwnerID int64 `json:"owner_id"` OwnerID int64 `json:"owner_id"`
CreatedAt time.Time `json:"created_at"` CreatedAt time.Time `json:"created_at"`
Name string `json:"name"` Name string `json:"name"`
Repo string `json:"repo"`
Descr sql.NullString `json:"descr"` Descr sql.NullString `json:"descr"`
} }

View File

@ -146,24 +146,31 @@ func (q *Queries) AddPullRequestIgnore(ctx context.Context, arg AddPullRequestIg
} }
const addWatchItem = `-- name: AddWatchItem :one const addWatchItem = `-- name: AddWatchItem :one
insert into watch_items (owner_id, name, descr) insert into watch_items (owner_id, name, repo, descr)
values (?, ?, ?) returning id, owner_id, created_at, name, descr values (?, ?, ?, ?) returning id, owner_id, created_at, name, repo, descr
` `
type AddWatchItemParams struct { type AddWatchItemParams struct {
OwnerID int64 `json:"owner_id"` OwnerID int64 `json:"owner_id"`
Name string `json:"name"` Name string `json:"name"`
Repo string `json:"repo"`
Descr sql.NullString `json:"descr"` Descr sql.NullString `json:"descr"`
} }
func (q *Queries) AddWatchItem(ctx context.Context, arg AddWatchItemParams) (WatchItem, error) { 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 var i WatchItem
err := row.Scan( err := row.Scan(
&i.ID, &i.ID,
&i.OwnerID, &i.OwnerID,
&i.CreatedAt, &i.CreatedAt,
&i.Name, &i.Name,
&i.Repo,
&i.Descr, &i.Descr,
) )
return i, err return i, err
@ -364,7 +371,7 @@ func (q *Queries) GetAllPullRequests(ctx context.Context, arg GetAllPullRequests
} }
const getAllWatchItems = `-- name: GetAllWatchItems :many 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 from watch_items
` `
@ -382,6 +389,7 @@ func (q *Queries) GetAllWatchItems(ctx context.Context) ([]WatchItem, error) {
&i.OwnerID, &i.OwnerID,
&i.CreatedAt, &i.CreatedAt,
&i.Name, &i.Name,
&i.Repo,
&i.Descr, &i.Descr,
); err != nil { ); err != nil {
return nil, err return nil, err
@ -398,7 +406,7 @@ func (q *Queries) GetAllWatchItems(ctx context.Context) ([]WatchItem, error) {
} }
const getAllWatchItemsByOwner = `-- name: GetAllWatchItemsByOwner :many 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 from watch_items
where owner_id = ? where owner_id = ?
` `
@ -417,6 +425,7 @@ func (q *Queries) GetAllWatchItemsByOwner(ctx context.Context, ownerID int64) ([
&i.OwnerID, &i.OwnerID,
&i.CreatedAt, &i.CreatedAt,
&i.Name, &i.Name,
&i.Repo,
&i.Descr, &i.Descr,
); err != nil { ); err != nil {
return nil, err return nil, err

View File

@ -18,7 +18,7 @@ const gqEndPoint = "https://api.github.com/graphql"
const graphQuery = ` const graphQuery = `
{ {
search( 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, type: ISSUE,
first: 20 first: 20
) { ) {
@ -144,7 +144,7 @@ func (w *WatchResults) Update(ghToken string) error {
} }
for _, watch := range watches { 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) wr, err := getData(qd, ghToken)
if err != nil { if err != nil {
return err 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 // TODO: cross ref the list of ignores and prune the wr accordingly
wr.OwnerID = watch.OwnerID wr.OwnerID = watch.OwnerID
wr.Name = watch.Name wr.Name = watch.Name
wr.Repo = watch.Repo
*w = append(*w, *wr) *w = append(*w, *wr)
} }
@ -163,6 +164,7 @@ type WatchResult struct {
Data Data `json:"data,omitempty"` Data Data `json:"data,omitempty"`
OwnerID int64 OwnerID int64
Name string Name string
Repo string
} }
type Repository struct { type Repository struct {
NameWithOwner string `json:"nameWithOwner,omitempty"` NameWithOwner string `json:"nameWithOwner,omitempty"`

View File

@ -17,8 +17,8 @@ from watch_items
where owner_id = ?; where owner_id = ?;
-- name: AddWatchItem :one -- name: AddWatchItem :one
insert into watch_items (owner_id, name, descr) insert into watch_items (owner_id, name, repo, descr)
values (?, ?, ?) returning *; values (?, ?, ?, ?) returning *;
-- name: DeleteWatchItem :exec -- name: DeleteWatchItem :exec
delete from watch_items where id = ? and owner_id = ?; delete from watch_items where id = ? and owner_id = ?;

View File

@ -7,45 +7,47 @@ create table owners
create table watch_items create table watch_items
( (
id integer primary key autoincrement, 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, created_at datetime default current_timestamp not null,
name text not null unique, name text not null,
descr text repo text not null,
descr text,
unique (name, repo)
); );
create table pull_request_ignores create table pull_request_ignores
( (
id integer primary key autoincrement, 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, created_at datetime default current_timestamp not null,
number integer not null, number integer not null,
repo text not null, repo text not null,
unique (number, repo) unique (number, repo)
); );
create table links create table links
( (
id integer primary key autoincrement, 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, created_at datetime default current_timestamp not null,
url text not null unique, url text not null unique,
name text not null, name text not null,
logo_url text logo_url text
); );
create table pull_requests create table pull_requests
( (
id integer primary key autoincrement, 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, created_at datetime default current_timestamp not null,
number integer not null unique, number integer not null unique,
repo text not null, repo text not null,
description text, description text,
commitid text commitid text
); );
create table icons create table icons
( (
id integer primary key autoincrement, 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, created_at datetime default current_timestamp not null,
url text not null unique, url text not null unique,
content_type text not null, content_type text not null,
data blob not null data blob not null
); );

View File

@ -1,6 +1,6 @@
<html lang="en"> <html lang="en">
<head> <head>
<!-- <link rel="stylesheet" href="assets/bolt.css">--> <!-- <link rel="stylesheet" href="assets/bolt.css">-->
<link rel="stylesheet" href="assets/pico.css"> <link rel="stylesheet" href="assets/pico.css">
<style> <style>
.icons li { .icons li {
@ -14,42 +14,59 @@
list-style-type: none; list-style-type: none;
text-align: center; text-align: center;
} }
.icons li img { .icons li img {
width: 50px; width: 50px;
hight: 50px; hight: 50px;
} }
dialog {
display: none;
}
</style> </style>
<title>{{.Title}}::{{.Node.ComputedName}}</title> <title>{{.Title}}::{{.Node.ComputedName}}</title>
</head> </head>
<body> <body>
<h1>{{.Title}} for {{.Node.ComputedName}}</h1> <header>
<h3>Pull Requests</h3> <h1>{{.Title}} for {{.Node.ComputedName}}</h1>
<ul> <input type="search" id="search" name="search" placeholder="Search">
{{range .PullRequests}} <ul class="icons">
<li>{{.Repo}} {{.Number}} ( {{.ID}} )</li> {{range .Links}}
{{end}} <li>{{.Name}}</li>
</ul> {{end}}
</ul>
<h3>Watch Items</h3> </header>
<ul class=""> <main>
{{range .Watches}} <h3>Pull Requests</h3>
<li>{{.Name}} <ul>
<ul> {{range .PullRequests}}
{{range .Data.Search.Edges}} <li>{{.Repo}} {{.Number}} ( {{.ID}} )</li>
<li>{{.Node.Title}} ({{.Node.CreatedAt}})</li> {{end}}
{{end}} </ul>
</ul> <h3>Watch Items</h3>
</li> <ul class="">
{{end}} {{range .Watches}}
</ul> <li><b>{{.Repo}} :: {{.Name}}</b>
<ul>
<h3>Links</h3> {{range .Data.Search.Edges}}
<ul class="icons"> <li>{{.Node.Title}}</li>
{{range .Links}} {{end}}
<li>{{.Name}}</li> </ul>
{{end}} </li>
</ul> {{end}}
</ul>
<foot>Remaining queries: {{.CurrentLimits.Remaining}}</foot> <dialog open>
<article>
<h3>Add Watch Item</h3>
<p>
<input type="text" />
</p>
<footer>
<a href="#cancel" role="button" class="secondary">Cancel</a>
<a href="#confirm" role="button">Add</a>
</footer>
</article>
</dialog>
</main>
<footer>Remaining queries: {{.CurrentLimits.Remaining}}</footer>
</body> </body>
</html> </html>

28
tmp.go
View File

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