mirror of
https://github.com/grafana/grafana.git
synced 2025-07-30 05:32:32 +08:00

* Spike: Extras * Attempt to wire it up * Hack * Fix issue with jobs * Wire more things up * Fix more wiring stuff * Remove webhook secret key from main registration * Move secret encryption also outside register * Add TODOs in code * Add more explanations * Move connectors to different package * Move pull request job into webhooks * Separate registration * Remove duplicate files * Fix missing function * Extract webhook repository logic out of the core github repository * Use status patcher in webhook connector * Fix change in go mod * Change hooks signature * Remove TODOs * Remove Webhook methos from go-git * Remove leftover * Fix mistake in OpenAPI spec * Fix some tests * Fix some issues * Fix linting
38 lines
1.1 KiB
Go
38 lines
1.1 KiB
Go
package controller
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
|
|
provisioning "github.com/grafana/grafana/pkg/apis/provisioning/v0alpha1"
|
|
client "github.com/grafana/grafana/pkg/generated/clientset/versioned/typed/provisioning/v0alpha1"
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
"k8s.io/apimachinery/pkg/types"
|
|
)
|
|
|
|
type RepositoryStatusPatcher struct {
|
|
client client.ProvisioningV0alpha1Interface
|
|
}
|
|
|
|
func NewRepositoryStatusPatcher(client client.ProvisioningV0alpha1Interface) *RepositoryStatusPatcher {
|
|
return &RepositoryStatusPatcher{
|
|
client: client,
|
|
}
|
|
}
|
|
|
|
func (r *RepositoryStatusPatcher) Patch(ctx context.Context, repo *provisioning.Repository, patchOperations ...map[string]interface{}) error {
|
|
patch, err := json.Marshal(patchOperations)
|
|
if err != nil {
|
|
return fmt.Errorf("unable to marshal patch data: %w", err)
|
|
}
|
|
|
|
_, err = r.client.Repositories(repo.Namespace).
|
|
Patch(ctx, repo.Name, types.JSONPatchType, patch, metav1.PatchOptions{}, "status")
|
|
if err != nil {
|
|
return fmt.Errorf("unable to update repo with job status: %w", err)
|
|
}
|
|
|
|
return nil
|
|
}
|