(ctx context.Context, tx *gorm.DB, name string, detailed bool)
| 300 | } |
| 301 | |
| 302 | func (s *sqlDatabase) getGithubCredentialsByName(ctx context.Context, tx *gorm.DB, name string, detailed bool) (GithubCredentials, error) { |
| 303 | var creds GithubCredentials |
| 304 | q := tx.Preload("Endpoint") |
| 305 | |
| 306 | if detailed { |
| 307 | q = q. |
| 308 | Preload("Repositories"). |
| 309 | Preload("Repositories.Credentials"). |
| 310 | Preload("Organizations"). |
| 311 | Preload("Organizations.Credentials"). |
| 312 | Preload("Enterprises"). |
| 313 | Preload("Enterprises.Credentials") |
| 314 | } |
| 315 | |
| 316 | userID, err := getUIDFromContext(ctx) |
| 317 | if err != nil { |
| 318 | return GithubCredentials{}, fmt.Errorf("error fetching github credentials: %w", err) |
| 319 | } |
| 320 | q = q.Where("user_id = ?", userID) |
| 321 | |
| 322 | err = q.Where("name = ?", name).First(&creds).Error |
| 323 | if err != nil { |
| 324 | if errors.Is(err, gorm.ErrRecordNotFound) { |
| 325 | return GithubCredentials{}, fmt.Errorf("github credentials not found: %w", runnerErrors.ErrNotFound) |
| 326 | } |
| 327 | return GithubCredentials{}, fmt.Errorf("error fetching github credentials: %w", err) |
| 328 | } |
| 329 | |
| 330 | return creds, nil |
| 331 | } |
| 332 | |
| 333 | func (s *sqlDatabase) GetGithubCredentialsByName(ctx context.Context, name string, detailed bool) (params.ForgeCredentials, error) { |
| 334 | creds, err := s.getGithubCredentialsByName(ctx, s.conn, name, detailed) |
no test coverage detected