diff --git a/appview/db/pulls.go b/appview/db/pulls.go index 10a7dd2d..56ff2258 100644 --- a/appview/db/pulls.go +++ b/appview/db/pulls.go @@ -128,6 +128,10 @@ func (p *Pull) IsSameRepoBranch() bool { return false } +func (p *Pull) IsPatch() bool { + return p.PullSource == nil +} + func (s PullSubmission) AsNiceDiff(targetBranch string) types.NiceDiff { patch := s.Patch diff --git a/appview/db/repos.go b/appview/db/repos.go index 73c39f69..23927ec2 100644 --- a/appview/db/repos.go +++ b/appview/db/repos.go @@ -190,6 +190,93 @@ func GetRepoSource(e Execer, repoAt syntax.ATURI) (string, error) { return nullableSource.String, nil } +func GetForksByDid(e Execer, did string) ([]Repo, error) { + var repos []Repo + + rows, err := e.Query( + `select did, name, knot, rkey, description, created, at_uri, source + from repos + where did = ? and source is not null and source != '' + order by created desc`, + did, + ) + if err != nil { + return nil, err + } + defer rows.Close() + + for rows.Next() { + var repo Repo + var createdAt string + var nullableDescription sql.NullString + var nullableSource sql.NullString + + err := rows.Scan(&repo.Did, &repo.Name, &repo.Knot, &repo.Rkey, &nullableDescription, &createdAt, &repo.AtUri, &nullableSource) + if err != nil { + return nil, err + } + + if nullableDescription.Valid { + repo.Description = nullableDescription.String + } + + if nullableSource.Valid { + repo.Source = nullableSource.String + } + + createdAtTime, err := time.Parse(time.RFC3339, createdAt) + if err != nil { + repo.Created = time.Now() + } else { + repo.Created = createdAtTime + } + + repos = append(repos, repo) + } + + if err := rows.Err(); err != nil { + return nil, err + } + + return repos, nil +} + +func GetForkByDid(e Execer, did string, name string) (*Repo, error) { + var repo Repo + var createdAt string + var nullableDescription sql.NullString + var nullableSource sql.NullString + + row := e.QueryRow( + `select did, name, knot, rkey, description, created, at_uri, source + from repos + where did = ? and name = ? and source is not null and source != ''`, + did, name, + ) + + err := row.Scan(&repo.Did, &repo.Name, &repo.Knot, &repo.Rkey, &nullableDescription, &createdAt, &repo.AtUri, &nullableSource) + if err != nil { + return nil, err + } + + if nullableDescription.Valid { + repo.Description = nullableDescription.String + } + + if nullableSource.Valid { + repo.Source = nullableSource.String + } + + createdAtTime, err := time.Parse(time.RFC3339, createdAt) + if err != nil { + repo.Created = time.Now() + } else { + repo.Created = createdAtTime + } + + return &repo, nil +} + func AddCollaborator(e Execer, collaborator, repoOwnerDid, repoName, repoKnot string) error { _, err := e.Exec( `insert into collaborators (did, repo) diff --git a/appview/pages/pages.go b/appview/pages/pages.go index 1a9e3b67..aa538f16 100644 --- a/appview/pages/pages.go +++ b/appview/pages/pages.go @@ -575,6 +575,7 @@ func (p *Pages) SingleIssueCommentFragment(w io.Writer, params SingleIssueCommen type RepoNewPullParams struct { LoggedInUser *auth.User RepoInfo RepoInfo + Forks []db.Repo Branches []types.Branch Active string } diff --git a/appview/pages/templates/fragments/pullActions.html b/appview/pages/templates/fragments/pullActions.html index 954bbe33..00783069 100644 --- a/appview/pages/templates/fragments/pullActions.html +++ b/appview/pages/templates/fragments/pullActions.html @@ -43,7 +43,7 @@ {{ $disabled = "disabled" }} {{ end }}
- +