Add URL to pull_requests (which is now sorta misnamed since it can house issues too..)

This commit is contained in:
Aaron Bieber 2022-12-05 09:14:30 -07:00
parent 0eebffc039
commit 7adab5a3db
No known key found for this signature in database
8 changed files with 50 additions and 32 deletions

View File

@ -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*/];
}
});
});
}

View File

@ -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);
}

View File

@ -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"`
}

View File

@ -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 {

View File

@ -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

View File

@ -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

View File

@ -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
);

View File

@ -64,7 +64,7 @@
<h3>Pull Requests</h3>
<ul>
{{range .PullRequests}}
<li>{{.Repo}} {{.Number}} ( {{.ID}} )</li>
<li><b><a href="{{.Url}}">{{.Repo}} {{.Number}}</a></b> :: {{.Description}}</li>
{{end}}
</ul>
{{end}}
@ -82,7 +82,7 @@
<b>
<a href="{{.Node.URL}}">{{.Node.Number}}</a>
</b> ::
<span></span>
<span onclick="addPR({{.Node.Number}}, '{{.Node.Repository.NameWithOwner}}', '{{.Node.Title}}', '{{.Node.URL}}')"></span>
<span onclick="addIgnore({{.Node.Number}}, '{{.Node.Repository.NameWithOwner}}')"></span> ::
{{.Node.Title}}
</li>