this repo has no description

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

Signed-off-by: dusk <y.bera003.06@protonmail.com>

authored by dusk and committed by Tangled f5917160 b3ce5aec

Changed files
+22 -3
appview
+22 -3
appview/db/pulls.go
··· 310 return pullId - 1, err 311 } 312 313 - func GetPulls(e Execer, filters ...filter) ([]*Pull, error) { 314 pulls := make(map[int]*Pull) 315 316 var conditions []string ··· 323 whereClause := "" 324 if conditions != nil { 325 whereClause = " where " + strings.Join(conditions, " and ") 326 } 327 328 query := fmt.Sprintf(` ··· 344 from 345 pulls 346 %s 347 - `, whereClause) 348 349 rows, err := e.Query(query, args...) 350 if err != nil { ··· 412 inClause := strings.TrimSuffix(strings.Repeat("?, ", len(pulls)), ", ") 413 submissionsQuery := fmt.Sprintf(` 414 select 415 - id, pull_id, round_number, patch, source_rev 416 from 417 pull_submissions 418 where ··· 438 for submissionsRows.Next() { 439 var s PullSubmission 440 var sourceRev sql.NullString 441 err := submissionsRows.Scan( 442 &s.ID, 443 &s.PullId, 444 &s.RoundNumber, 445 &s.Patch, 446 &sourceRev, 447 ) 448 if err != nil { 449 return nil, err 450 } 451 452 if sourceRev.Valid { 453 s.SourceRev = sourceRev.String ··· 511 }) 512 513 return orderedByPullId, nil 514 } 515 516 func GetPull(e Execer, repoAt syntax.ATURI, pullId int) (*Pull, error) {
··· 310 return pullId - 1, err 311 } 312 313 + func GetPullsWithLimit(e Execer, limit int, filters ...filter) ([]*Pull, error) { 314 pulls := make(map[int]*Pull) 315 316 var conditions []string ··· 323 whereClause := "" 324 if conditions != nil { 325 whereClause = " where " + strings.Join(conditions, " and ") 326 + } 327 + limitClause := "" 328 + if limit != 0 { 329 + limitClause = fmt.Sprintf(" limit %d ", limit) 330 } 331 332 query := fmt.Sprintf(` ··· 348 from 349 pulls 350 %s 351 + order by 352 + created desc 353 + %s 354 + `, whereClause, limitClause) 355 356 rows, err := e.Query(query, args...) 357 if err != nil { ··· 419 inClause := strings.TrimSuffix(strings.Repeat("?, ", len(pulls)), ", ") 420 submissionsQuery := fmt.Sprintf(` 421 select 422 + id, pull_id, round_number, patch, created, source_rev 423 from 424 pull_submissions 425 where ··· 445 for submissionsRows.Next() { 446 var s PullSubmission 447 var sourceRev sql.NullString 448 + var createdAt string 449 err := submissionsRows.Scan( 450 &s.ID, 451 &s.PullId, 452 &s.RoundNumber, 453 &s.Patch, 454 + &createdAt, 455 &sourceRev, 456 ) 457 if err != nil { 458 return nil, err 459 } 460 + 461 + createdTime, err := time.Parse(time.RFC3339, createdAt) 462 + if err != nil { 463 + return nil, err 464 + } 465 + s.Created = createdTime 466 467 if sourceRev.Valid { 468 s.SourceRev = sourceRev.String ··· 526 }) 527 528 return orderedByPullId, nil 529 + } 530 + 531 + func GetPulls(e Execer, filters ...filter) ([]*Pull, error) { 532 + return GetPullsWithLimit(e, 0, filters...) 533 } 534 535 func GetPull(e Execer, repoAt syntax.ATURI, pullId int) (*Pull, error) {