(ctx context.Context, id uint, detailed bool)
| 339 | } |
| 340 | |
| 341 | func (s *sqlDatabase) GetGithubCredentials(ctx context.Context, id uint, detailed bool) (params.ForgeCredentials, error) { |
| 342 | var creds GithubCredentials |
| 343 | q := s.conn.Preload("Endpoint") |
| 344 | |
| 345 | if detailed { |
| 346 | q = q. |
| 347 | Preload("Repositories"). |
| 348 | Preload("Repositories.Credentials"). |
| 349 | Preload("Organizations"). |
| 350 | Preload("Organizations.Credentials"). |
| 351 | Preload("Enterprises"). |
| 352 | Preload("Enterprises.Credentials") |
| 353 | } |
| 354 | |
| 355 | if !auth.IsAdmin(ctx) { |
| 356 | userID, err := getUIDFromContext(ctx) |
| 357 | if err != nil { |
| 358 | return params.ForgeCredentials{}, fmt.Errorf("error fetching github credentials: %w", err) |
| 359 | } |
| 360 | q = q.Where("user_id = ?", userID) |
| 361 | } |
| 362 | |
| 363 | err := q.Where("id = ?", id).First(&creds).Error |
| 364 | if err != nil { |
| 365 | if errors.Is(err, gorm.ErrRecordNotFound) { |
| 366 | return params.ForgeCredentials{}, fmt.Errorf("github credentials not found: %w", runnerErrors.ErrNotFound) |
| 367 | } |
| 368 | return params.ForgeCredentials{}, fmt.Errorf("error fetching github credentials: %w", err) |
| 369 | } |
| 370 | |
| 371 | return s.sqlToCommonForgeCredentials(creds) |
| 372 | } |
| 373 | |
| 374 | func (s *sqlDatabase) ListGithubCredentials(ctx context.Context) ([]params.ForgeCredentials, error) { |
| 375 | q := s.conn.Preload("Endpoint") |
nothing calls this directly
no test coverage detected