Use custom config path to sanitize build names (#280)

fix #270
This commit is contained in:
Anbraten 2021-08-29 22:25:41 +02:00 committed by 6543
parent 214e10ef17
commit a0a58c560d
No known key found for this signature in database
GPG key ID: C99B82E40B027BAE
2 changed files with 6 additions and 6 deletions

View file

@ -208,7 +208,7 @@ func PostHook(c *gin.Context) {
// persist the build config for historical correctness, restarts, etc
for _, remoteYamlConfig := range remoteYamlConfigs {
_, err := findOrPersistPipelineConfig(build, remoteYamlConfig)
_, err := findOrPersistPipelineConfig(repo, build, remoteYamlConfig)
if err != nil {
logrus.Errorf("failure to find or persist build config for %s. %s", repo.FullName, err)
c.AbortWithError(500, err)
@ -330,7 +330,7 @@ func zeroSteps(build *model.Build, remoteYamlConfigs []*remote.FileMeta) bool {
return false
}
func findOrPersistPipelineConfig(build *model.Build, remoteYamlConfig *remote.FileMeta) (*model.Config, error) {
func findOrPersistPipelineConfig(repo *model.Repo, build *model.Build, remoteYamlConfig *remote.FileMeta) (*model.Config, error) {
sha := shasum(remoteYamlConfig.Data)
conf, err := Config.Storage.Config.ConfigFindIdentical(build.RepoID, sha)
if err != nil {
@ -338,7 +338,7 @@ func findOrPersistPipelineConfig(build *model.Build, remoteYamlConfig *remote.Fi
RepoID: build.RepoID,
Data: string(remoteYamlConfig.Data),
Hash: sha,
Name: sanitizePath(remoteYamlConfig.Name),
Name: sanitizePath(remoteYamlConfig.Name, repo.Config),
}
err = Config.Storage.Config.ConfigCreate(conf)
if err != nil {

View file

@ -78,7 +78,7 @@ func (b *procBuilder) Build() ([]*buildItem, error) {
PGID: pidSequence,
State: model.StatusPending,
Environ: axis,
Name: sanitizePath(y.Name),
Name: sanitizePath(y.Name, b.Repo.Config),
}
metadata := metadataFromStruct(b.Repo, b.Curr, b.Last, proc, b.Link)
@ -358,9 +358,9 @@ func metadataFromStruct(repo *model.Repo, build, last *model.Build, proc *model.
}
}
func sanitizePath(path string) string {
func sanitizePath(path string, configFolder string) string {
path = strings.TrimSuffix(path, ".yml")
path = strings.TrimPrefix(path, ".drone/")
path = strings.TrimPrefix(path, configFolder)
path = strings.TrimPrefix(path, ".")
return path
}