Skip to content

Commit

Permalink
Use custom config path to sanitize build names (#280)
Browse files Browse the repository at this point in the history
fix #270
  • Loading branch information
anbraten authored Aug 29, 2021
1 parent 6f4528f commit 8aeae0a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions server/hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,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)
Expand Down Expand Up @@ -329,15 +329,15 @@ 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 {
conf = &model.Config{
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 {
Expand Down
6 changes: 3 additions & 3 deletions server/procBuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
}

0 comments on commit 8aeae0a

Please sign in to comment.