(_ context.Context, tx *gorm.DB, id string, preload ...string)
| 280 | } |
| 281 | |
| 282 | func (s *sqlDatabase) getRepoByID(_ context.Context, tx *gorm.DB, id string, preload ...string) (Repository, error) { |
| 283 | u, err := uuid.Parse(id) |
| 284 | if err != nil { |
| 285 | return Repository{}, runnerErrors.NewBadRequestError("error parsing id: %s", err) |
| 286 | } |
| 287 | var repo Repository |
| 288 | |
| 289 | q := tx |
| 290 | if len(preload) > 0 { |
| 291 | for _, field := range preload { |
| 292 | q = q.Preload(field) |
| 293 | } |
| 294 | } |
| 295 | q = q.Where("id = ?", u).First(&repo) |
| 296 | |
| 297 | if q.Error != nil { |
| 298 | if errors.Is(q.Error, gorm.ErrRecordNotFound) { |
| 299 | return Repository{}, runnerErrors.ErrNotFound |
| 300 | } |
| 301 | return Repository{}, fmt.Errorf("error fetching repository from database: %w", q.Error) |
| 302 | } |
| 303 | return repo, nil |
| 304 | } |
no outgoing calls
no test coverage detected