diff --git a/assets/main.js b/assets/main.js index 3c90030..2861f2c 100644 --- a/assets/main.js +++ b/assets/main.js @@ -125,7 +125,7 @@ function sendPRData() { pd = document.getElementById("descr"); data = {}; data.Repo = pr.value; - data.Number = parseInt(pd.value, 10); + data.Number = parseInt(pn.value, 10); data.Description = pd.value; return [4 /*yield*/, postData('/pullrequests', data)]; case 1: @@ -152,3 +152,22 @@ function addIgnore(number, repo) { }); }); } +function addPR(number, repo, descr, url) { + return __awaiter(this, void 0, void 0, function () { + var data; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: + data = {}; + data.Number = number; + data.Repo = repo; + data.Description = descr; + data.Url = url; + return [4 /*yield*/, postData('/pullrequests', data)]; + case 1: + _a.sent(); + return [2 /*return*/]; + } + }); + }); +} diff --git a/assets/main.ts b/assets/main.ts index 4563e9c..18ca10d 100644 --- a/assets/main.ts +++ b/assets/main.ts @@ -12,6 +12,7 @@ interface PullRequest { CreatedAt: Date Number: number Repo: string + Url: string Description: string|null Commitid: string|null } @@ -87,7 +88,7 @@ async function sendPRData() { const pd = document.getElementById("descr") as HTMLInputElement; let data = {} as PullRequest; data.Repo = pr.value; - data.Number = parseInt(pd.value, 10); + data.Number = parseInt(pn.value, 10); data.Description = pd.value; await postData('/pullrequests', data); } @@ -98,3 +99,12 @@ async function addIgnore(number, repo: string) { data.Repo = repo; await postData('/prignores', data); } + +async function addPR(number, repo, descr, url: string) { + let data = {} as PullRequest; + data.Number = number; + data.Repo = repo; + data.Description = descr; + data.Url = url; + await postData('/pullrequests', data); +} diff --git a/data/models.go b/data/models.go index 5684157..7f4139a 100644 --- a/data/models.go +++ b/data/models.go @@ -40,6 +40,7 @@ type PullRequest struct { CreatedAt time.Time `json:"created_at"` Number int64 `json:"number"` Repo string `json:"repo"` + Url string `json:"url"` Description string `json:"description"` Commitid sql.NullString `json:"commitid"` } diff --git a/data/queries.sql.go b/data/queries.sql.go index 2b871ab..ce77414 100644 --- a/data/queries.sql.go +++ b/data/queries.sql.go @@ -88,8 +88,8 @@ func (q *Queries) AddOwner(ctx context.Context, arg AddOwnerParams) (Owner, erro } const addPullRequest = `-- name: AddPullRequest :one -insert into pull_requests (owner_id, number, repo, description) -values (?, ?, ?, ?) returning id, owner_id, created_at, number, repo, description, commitid +insert into pull_requests (owner_id, number, repo, description, url) +values (?, ?, ?, ?, ?) returning id, owner_id, created_at, number, repo, url, description, commitid ` type AddPullRequestParams struct { @@ -97,6 +97,7 @@ type AddPullRequestParams struct { Number int64 `json:"number"` Repo string `json:"repo"` Description string `json:"description"` + Url string `json:"url"` } func (q *Queries) AddPullRequest(ctx context.Context, arg AddPullRequestParams) (PullRequest, error) { @@ -105,6 +106,7 @@ func (q *Queries) AddPullRequest(ctx context.Context, arg AddPullRequestParams) arg.Number, arg.Repo, arg.Description, + arg.Url, ) var i PullRequest err := row.Scan( @@ -113,6 +115,7 @@ func (q *Queries) AddPullRequest(ctx context.Context, arg AddPullRequestParams) &i.CreatedAt, &i.Number, &i.Repo, + &i.Url, &i.Description, &i.Commitid, ) @@ -362,21 +365,13 @@ func (q *Queries) GetAllPullRequestIgnores(ctx context.Context, ownerID int64) ( } const getAllPullRequests = `-- name: GetAllPullRequests :many -select id, owner_id, created_at, number, repo, description, commitid +select id, owner_id, created_at, number, repo, url, description, commitid from pull_requests -where number not in (select number - from pull_request_ignores - where pull_request_ignores.owner_id = ?) - and pull_requests.owner_id = ? +where owner_id = ? ` -type GetAllPullRequestsParams struct { - OwnerID int64 `json:"owner_id"` - OwnerID_2 int64 `json:"owner_id_2"` -} - -func (q *Queries) GetAllPullRequests(ctx context.Context, arg GetAllPullRequestsParams) ([]PullRequest, error) { - rows, err := q.db.QueryContext(ctx, getAllPullRequests, arg.OwnerID, arg.OwnerID_2) +func (q *Queries) GetAllPullRequests(ctx context.Context, ownerID int64) ([]PullRequest, error) { + rows, err := q.db.QueryContext(ctx, getAllPullRequests, ownerID) if err != nil { return nil, err } @@ -390,6 +385,7 @@ func (q *Queries) GetAllPullRequests(ctx context.Context, arg GetAllPullRequests &i.CreatedAt, &i.Number, &i.Repo, + &i.Url, &i.Description, &i.Commitid, ); err != nil { diff --git a/handlers.go b/handlers.go index 492a21e..d93417a 100644 --- a/handlers.go +++ b/handlers.go @@ -160,10 +160,7 @@ func pullrequestsGET(w http.ResponseWriter, r *http.Request) { http.Error(w, http.StatusText(422), 422) return } - prs, err := app.queries.GetAllPullRequests(app.ctx, data.GetAllPullRequestsParams{ - OwnerID: ownerID, - OwnerID_2: ownerID, - }) + prs, err := app.queries.GetAllPullRequests(app.ctx, ownerID) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return @@ -301,10 +298,7 @@ func index(w http.ResponseWriter, r *http.Request) { return } - prs, err := app.queries.GetAllPullRequests(dbCtx, data.GetAllPullRequestsParams{ - OwnerID: ownerID, - OwnerID_2: ownerID, - }) + prs, err := app.queries.GetAllPullRequests(dbCtx, ownerID) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return diff --git a/queries.sql b/queries.sql index 00f58ba..ab8034b 100644 --- a/queries.sql +++ b/queries.sql @@ -65,14 +65,11 @@ update set data = excluded.data, content_type = excluded.content_type; -- name: GetAllPullRequests :many select * from pull_requests -where number not in (select number - from pull_request_ignores - where pull_request_ignores.owner_id = ?) - and pull_requests.owner_id = ?; +where owner_id = ?; -- name: AddPullRequest :one -insert into pull_requests (owner_id, number, repo, description) -values (?, ?, ?, ?) returning *; +insert into pull_requests (owner_id, number, repo, description, url) +values (?, ?, ?, ?, ?) returning *; -- name: DeletePullRequest :exec delete diff --git a/schema.sql b/schema.sql index c486072..d02f214 100644 --- a/schema.sql +++ b/schema.sql @@ -40,6 +40,7 @@ create table pull_requests created_at datetime default current_timestamp not null, number integer not null unique, repo text not null, + url text not null, description text not null, commitid text ); diff --git a/templates/main.html b/templates/main.html index 762a47d..c9a7977 100644 --- a/templates/main.html +++ b/templates/main.html @@ -64,7 +64,7 @@

Pull Requests

{{end}} @@ -82,7 +82,7 @@ {{.Node.Number}} :: - + :: {{.Node.Title}}