Skip to content

Commit

Permalink
fix tags with tag-prefix (#549)
Browse files Browse the repository at this point in the history
* fix tags with tag-prefix

* new UT

---------

Co-authored-by: ChanochShayner <[email protected]>
  • Loading branch information
MIRIAM-SLOV and ChanochShayner authored Jul 25, 2024
1 parent 77cc55b commit f86cd7e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/common/tagging/tag_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (t *TagGroup) SetTags(tags []tags.ITag) {
for _, tag := range tags {
tag.Init()
tag.SetTagPrefix(t.Options.TagPrefix)
if !t.IsTagSkipped(tag) && (t.SpecifiedTags == nil || len(t.SpecifiedTags) == 0 || utils.InSlice(t.SpecifiedTags, tag.GetKey())) {
if !t.IsTagSkipped(tag) && (t.SpecifiedTags == nil || len(t.SpecifiedTags) == 0 || utils.InSlice(t.SpecifiedTags, strings.TrimPrefix(tag.GetKey(), t.Options.TagPrefix))) {
t.tags = append(t.tags, tag)
}
}
Expand Down
16 changes: 16 additions & 0 deletions src/common/tagging/tag_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,20 @@ func TestTagGroup(t *testing.T) {
tgs := tagGroup.GetTags()
assert.Equal(t, 0, len(tgs))
})

t.Run("Test tag prefix not broke tags", func(t *testing.T) {
tagGroup := TagGroup{Options: InitTagGroupOptions{
TagPrefix: "prefix_",
},
SpecifiedTags: []string{"yor_trace"},
}
tagGroup.SetTags([]tags.ITag{
&tags.Tag{Key: "yor_trace"},
&tags.Tag{Key: "git_modifiers"},
})
tgs := tagGroup.GetTags()
assert.Equal(t, 1, len(tgs))
assert.Equal(t, string("prefix_yor_trace"), tgs[0].GetKey())

})
}

0 comments on commit f86cd7e

Please sign in to comment.