Provisioning: Implement connection repositories endpoint for GitHub
This change implements the `/repositories` subresource endpoint for Connection resources, enabling listing of repositories accessible through a GitHub App connection. Changes: - Add ListRepositories method to Connection interface - Add ListInstallationRepositories to GitHub Client interface - Implement GitHub client method to list installation repositories - Creates installation access token from JWT - Handles pagination up to 1000 repos - Implement ListRepositories in GitHub Connection - Update connectionRepositoriesConnector to use Connection.ListRepositories - Add ConnectionGetter interface and GetConnection method to APIBuilder - Add comprehensive tests for the new functionality
This commit is contained in:
@@ -187,6 +187,31 @@ func toError(name string, list field.ErrorList) error {
|
||||
)
|
||||
}
|
||||
|
||||
// ListRepositories returns the list of repositories accessible through this GitHub App connection.
|
||||
func (c *Connection) ListRepositories(ctx context.Context) ([]provisioning.ExternalRepository, error) {
|
||||
if c.obj.Spec.GitHub == nil {
|
||||
return nil, fmt.Errorf("github configuration is required")
|
||||
}
|
||||
|
||||
ghClient := c.ghFactory.New(ctx, c.obj.Secure.Token.Create)
|
||||
|
||||
repos, err := ghClient.ListInstallationRepositories(ctx, c.obj.Spec.GitHub.InstallationID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("list installation repositories: %w", err)
|
||||
}
|
||||
|
||||
result := make([]provisioning.ExternalRepository, 0, len(repos))
|
||||
for _, repo := range repos {
|
||||
result = append(result, provisioning.ExternalRepository{
|
||||
Name: repo.Name,
|
||||
Owner: repo.Owner,
|
||||
URL: repo.URL,
|
||||
})
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
var (
|
||||
_ connection.Connection = (*Connection)(nil)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user