Files
Roberto Jiménez Sánchez 3cb62e370b Provisioning: Add pure git repository type (#106815)
* Add repository type git to spec
* Register git type
* Update test checks
2025-06-18 09:05:37 +02:00

43 lines
1.1 KiB
Go

package repository
import (
apierrors "k8s.io/apimachinery/pkg/api/errors"
provisioning "github.com/grafana/grafana/pkg/apis/provisioning/v0alpha1"
)
func IsWriteAllowed(repo *provisioning.Repository, ref string) error {
if len(repo.Spec.Workflows) == 0 {
return apierrors.NewBadRequest("this repository is read only")
}
var supportsWrite, supportsBranch bool
for _, v := range repo.Spec.Workflows {
switch v {
case provisioning.WriteWorkflow:
supportsWrite = true
case provisioning.BranchWorkflow:
supportsBranch = repo.Spec.Type.IsGit()
}
}
// Ref may be the configured branch for github repositories
if ref != "" && repo.Spec.GitHub != nil && repo.Spec.GitHub.Branch == ref {
ref = ""
}
// Ref may be the configured branch for git repositories
if ref != "" && repo.Spec.Git != nil && repo.Spec.Git.Branch == ref {
ref = ""
}
switch {
case ref == "" && !supportsWrite:
return apierrors.NewBadRequest("this repository does not support the write workflow")
case ref != "" && !supportsBranch:
return apierrors.NewBadRequest("this repository does not support the branch workflow")
default:
return nil
}
}