Skip to content

Commit

Permalink
Adding 'branch_slug' as an output of the generator
Browse files Browse the repository at this point in the history
Signed-off-by: Aymen Ben Tanfous <[email protected]>
  • Loading branch information
Aymen Ben Tanfous committed Jun 8, 2022
1 parent 76c6f98 commit ad078bc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 21 deletions.
32 changes: 14 additions & 18 deletions applicationset/generators/pull_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,27 +69,23 @@ func (g *PullRequestGenerator) GenerateParams(appSetGenerator *argoprojiov1alpha
}
params := make([]map[string]string, 0, len(pulls))

if appSetGenerator.PullRequest.BranchSlug {
// In order to follow the DNS label standard as defined in RFC 1123,
// we need to limit the 'branch' to 50 to give room to append/suffix-ing it
// with 13 more characters. Also, there is the need to clean it as recommended
// here https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#dns-label-names

// Converting underscores to dashes
slug.CustomSub = map[string]string{
"_": "-",
}
slug.MaxLength = 50
// In order to follow the DNS label standard as defined in RFC 1123,
// we need to limit the 'branch' to 50 to give room to append/suffix-ing it
// with 13 more characters. Also, there is the need to clean it as recommended
// here https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#dns-label-names
slug.MaxLength = 50

// Converting underscores to dashes
slug.CustomSub = map[string]string{
"_": "-",
}

for _, pull := range pulls {
pullBranchName := pull.Branch
if appSetGenerator.PullRequest.BranchSlug {
pullBranchName = slug.Make(pull.Branch)
}
params = append(params, map[string]string{
"number": strconv.Itoa(pull.Number),
"branch": pullBranchName,
"head_sha": pull.HeadSHA,
"number": strconv.Itoa(pull.Number),
"branch": pull.Branch,
"branch_slug": slug.Make(pull.Branch),
"head_sha": pull.HeadSHA,
})
}
return params, nil
Expand Down
3 changes: 0 additions & 3 deletions pkg/apis/applicationset/v1alpha1/applicationset_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,9 +398,6 @@ type PullRequestGenerator struct {
// Filters for which pull requests should be considered.
Filters []PullRequestGeneratorFilter `json:"filters,omitempty"`

// If BranchSlug is set to true, the PR generator will slugify the branch name to be conform to RFC 1123
BranchSlug bool `json:"branchSlug,omitempty"`

// Standard parameters.
RequeueAfterSeconds *int64 `json:"requeueAfterSeconds,omitempty"`
Template ApplicationSetTemplate `json:"template,omitempty"`
Expand Down

0 comments on commit ad078bc

Please sign in to comment.