Skip to content

Commit

Permalink
Allow . as watched path
Browse files Browse the repository at this point in the history
  • Loading branch information
simonjohansson committed Jan 3, 2024
1 parent 80a97b5 commit f344aa0
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 1 deletion.
5 changes: 5 additions & 0 deletions e2e/actions/artifacts/.halfpipe.io
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ team: halfpipe-team
pipeline: artifacts
platform: actions

triggers:
- type: git
watched_paths:
- e2e/actions/artifacts

tasks:
- type: run
name: build
Expand Down
3 changes: 3 additions & 0 deletions e2e/actions/artifacts/workflowExpected.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ name: artifacts
push:
branches:
- main
paths:
- e2e/actions/artifacts**
- .github/workflows/artifacts.yml
workflow_dispatch: {}
env:
ARTIFACTORY_PASSWORD: ${{ secrets.EE_ARTIFACTORY_PASSWORD }}
Expand Down
5 changes: 5 additions & 0 deletions e2e/actions/consumer-integration-test/.halfpipe.io
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ team: halfpipe-team
pipeline: pipeline-name
platform: actions

triggers:
- type: git
watched_paths:
- .

tasks:
- type: consumer-integration-test
name: c-name
Expand Down
3 changes: 3 additions & 0 deletions e2e/actions/consumer-integration-test/workflowExpected.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ name: pipeline-name
push:
branches:
- main
paths:
- e2e/actions/consumer-integration-test**
- .github/workflows/pipeline-name.yml
workflow_dispatch: {}
env:
ARTIFACTORY_PASSWORD: ${{ secrets.EE_ARTIFACTORY_PASSWORD }}
Expand Down
2 changes: 1 addition & 1 deletion e2e/concourse/artifacts/.halfpipe.io
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pipeline: halfpipe-e2e-artifacts
triggers:
- type: git
watched_paths:
- e2e/concourse/artifacts
- .

tasks:
- type: run
Expand Down
34 changes: 34 additions & 0 deletions mapper/git_trigger.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package mapper

import (
"github.com/springernature/halfpipe/manifest"
)

type gitTriggerMapper struct {
}

func (g gitTriggerMapper) Apply(original manifest.Manifest) (updated manifest.Manifest, err error) {
updated = original
updated.Triggers = g.updateGitTrigger(updated.Triggers)
return updated, nil
}

func (g gitTriggerMapper) updateGitTrigger(triggerList manifest.TriggerList) (updated manifest.TriggerList) {
for _, trigger := range triggerList {
switch trigger := trigger.(type) {
case manifest.GitTrigger:
for i, path := range trigger.WatchedPaths {
if path == "." {
trigger.WatchedPaths[i] = trigger.BasePath
}
}
updated = append(updated, trigger)
default:
updated = append(updated, trigger)
}
}
return
}
func NewGitTriggerMapper() Mapper {
return gitTriggerMapper{}
}
56 changes: 56 additions & 0 deletions mapper/git_trigger_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package mapper

import (
"github.com/springernature/halfpipe/manifest"
"github.com/stretchr/testify/assert"
"testing"
)

func TestGitTriggerMapper_Apply(t *testing.T) {
t.Run("does nothing on empty manifest", func(t *testing.T) {
input := manifest.Manifest{}
expected := manifest.Manifest{}

updated, err := NewGitTriggerMapper().Apply(input)

assert.NoError(t, err)
assert.Equal(t, expected, updated)
})

t.Run("does nothing when there is no dot in the watched paths", func(t *testing.T) {
input := manifest.Manifest{
Triggers: manifest.TriggerList{
manifest.GitTrigger{WatchedPaths: []string{"a", "b"}},
},
}
expected := manifest.Manifest{
Triggers: manifest.TriggerList{
manifest.GitTrigger{WatchedPaths: []string{"a", "b"}},
},
}

updated, err := NewGitTriggerMapper().Apply(input)

assert.NoError(t, err)
assert.Equal(t, expected, updated)
})

t.Run("converts dots to base path", func(t *testing.T) {
input := manifest.Manifest{
Triggers: manifest.TriggerList{
manifest.GitTrigger{WatchedPaths: []string{"a", "."}, BasePath: "some/path/to/something"},
},
}
expected := manifest.Manifest{
Triggers: manifest.TriggerList{
manifest.GitTrigger{WatchedPaths: []string{"a", "some/path/to/something"}, BasePath: "some/path/to/something"},
},
}

updated, err := NewGitTriggerMapper().Apply(input)

assert.NoError(t, err)
assert.Equal(t, expected, updated)
})

}
1 change: 1 addition & 0 deletions mapper/mapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func New() Mapper {
NewUpdatePipelineMapper(),
NewNotificationsMapper(),
NewCfMapper(),
NewGitTriggerMapper(),
},
}
}

0 comments on commit f344aa0

Please sign in to comment.