Skip to content

Commit

Permalink
fix(webhook): support relative parent paths
Browse files Browse the repository at this point in the history
  • Loading branch information
corrieriluca committed Jul 10, 2023
1 parent ece5804 commit ab53e48
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
2 changes: 2 additions & 0 deletions internal/webhook/event/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ func layerFilesHaveChanged(layer configv1alpha1.TerraformLayer, changedFiles []s
if val, ok := layer.Annotations[annotations.AdditionnalTriggerPaths]; ok {
for _, p := range strings.Split(val, ",") {
p = ensureAbsPath(p)
// Handle relative parent paths (like "../")
p = filepath.Clean(filepath.Join(layer.Spec.Path, p))
if strings.Contains(f, p) {
return true
}
Expand Down
22 changes: 11 additions & 11 deletions internal/webhook/event/event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,17 +200,17 @@ var _ = Describe("Webhook", func() {
Expect(layer.Annotations[annotations.LastRelevantCommit]).To(Equal(PushEventAdditionalPathChanges.ChangeInfo.ShaAfter))
})
// TODO: make this test pass
// It("should have updated commit annotations for a relative change path", func() {
// layer := &configv1alpha1.TerraformLayer{}
// err := k8sClient.Get(context.TODO(), types.NamespacedName{
// Namespace: "default",
// Name: "layer-additional-paths-2",
// }, layer)
// Expect(err).NotTo(HaveOccurred())
// Expect(handleErr).NotTo(HaveOccurred())
// Expect(layer.Annotations[annotations.LastBranchCommit]).To(Equal(PushEventAdditionalPathChanges.ChangeInfo.ShaAfter))
// Expect(layer.Annotations[annotations.LastRelevantCommit]).To(Equal(PushEventAdditionalPathChanges.ChangeInfo.ShaAfter))
// })
It("should have updated commit annotations for a relative change path", func() {
layer := &configv1alpha1.TerraformLayer{}
err := k8sClient.Get(context.TODO(), types.NamespacedName{
Namespace: "default",
Name: "layer-additional-paths-2",
}, layer)
Expect(err).NotTo(HaveOccurred())
Expect(handleErr).NotTo(HaveOccurred())
Expect(layer.Annotations[annotations.LastBranchCommit]).To(Equal(PushEventAdditionalPathChanges.ChangeInfo.ShaAfter))
Expect(layer.Annotations[annotations.LastRelevantCommit]).To(Equal(PushEventAdditionalPathChanges.ChangeInfo.ShaAfter))
})
})
Describe("Multiple paths have been modified", Ordered, func() {
BeforeAll(func() {
Expand Down
2 changes: 1 addition & 1 deletion internal/webhook/event/pullrequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (e *PullRequestEvent) getAffectedRepositories(repositories []configv1alpha1
affectedRepositories := []configv1alpha1.TerraformRepository{}
for _, repo := range repositories {
log.Infof("evaluating terraform repository %s for url %s", repo.Name, repo.Spec.Repository.Url)
log.Infof("comparing noramlized url %s with received URL from paylaod %s", NormalizeUrl(repo.Spec.Repository.Url), e.URL)
log.Infof("comparing normalized url %s with received URL from payload %s", NormalizeUrl(repo.Spec.Repository.Url), e.URL)
if e.URL == NormalizeUrl(repo.Spec.Repository.Url) {
affectedRepositories = append(affectedRepositories, repo)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/webhook/event/testdata/layers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ metadata:
name: layer-additional-paths-2
namespace: default
annotations:
config.terraform.padok.cloud/additionnal-trigger-paths: "../module.hcl"
config.terraform.padok.cloud/additionnal-trigger-paths: "../../terragrunt.hcl,../module.hcl"
spec:
branch: main
path: terragrunt/layer-path-changed/prod/
Expand Down

0 comments on commit ab53e48

Please sign in to comment.