appview: db: pulls: add method for getting any pulls on a repo #475

merged
opened by ptr.pet targeting master from [deleted fork]: repo-feed
Changed files
+54
appview
+54
appview/db/pulls.go
··· 723 723 return &pull, nil 724 724 } 725 725 726 + func GetAnyPulls(e Execer, repoAt syntax.ATURI, count int) ([]Pull, error) { 727 + pulls := make([]Pull, 0, count) 728 + 729 + rows, err := e.Query(` 730 + select 731 + p.owner_did, 732 + p.repo_at, 733 + p.pull_id, 734 + p.created, 735 + p.title, 736 + p.state 737 + from 738 + pulls p 739 + where 740 + p.repo_at = ? 741 + order by 742 + p.created desc`, 743 + repoAt) 744 + if err != nil { 745 + return nil, err 746 + } 747 + defer rows.Close() 748 + 749 + for rows.Next() { 750 + var pull Pull 751 + var pullCreatedAt string 752 + err := rows.Scan( 753 + &pull.OwnerDid, 754 + &pull.RepoAt, 755 + &pull.PullId, 756 + &pullCreatedAt, 757 + &pull.Title, 758 + &pull.State, 759 + ) 760 + if err != nil { 761 + return nil, err 762 + } 763 + 764 + pullCreatedTime, err := time.Parse(time.RFC3339, pullCreatedAt) 765 + if err != nil { 766 + return nil, err 767 + } 768 + pull.Created = pullCreatedTime 769 + 770 + pulls = append(pulls, pull) 771 + } 772 + 773 + if err := rows.Err(); err != nil { 774 + return nil, err 775 + } 776 + 777 + return pulls, nil 778 + } 779 + 726 780 // timeframe here is directly passed into the sql query filter, and any 727 781 // timeframe in the past should be negative; e.g.: "-3 months" 728 782 func GetPullsByOwnerDid(e Execer, did, timeframe string) ([]Pull, error) {