Skip to content

Commit

Permalink
fix git tag group ignore git tag prefix issue (#358)
Browse files Browse the repository at this point in the history
Co-authored-by: zjhe <action@github.com>
  • Loading branch information
lonegunmanb and actions-user committed Apr 20, 2023
1 parent 1f06729 commit d159f98
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/common/tagging/gittag/git_tag_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func (t *TagGroup) InitTagGroup(path string, skippedTags []string, explicitlySpe
}
t.SkippedTags = skippedTags
t.SpecifiedTags = explicitlySpecifiedTags
t.Options = opt
if path != "" {
gitService, err := gitservice.NewGitService(path)
if err != nil {
Expand Down
26 changes: 26 additions & 0 deletions src/common/tagging/gittag/git_tag_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ package gittag

import (
"os"
"strings"
"sync"
"testing"

"github.com/bridgecrewio/yor/src/common/gitservice"
"github.com/bridgecrewio/yor/src/common/structure"
"github.com/bridgecrewio/yor/src/common/tagging"
"github.com/bridgecrewio/yor/src/common/tagging/tags"
"github.com/bridgecrewio/yor/src/common/utils"
"github.com/bridgecrewio/yor/tests/utils/blameutils"
Expand Down Expand Up @@ -82,6 +84,30 @@ func TestGittagGroup_mapOriginFileToGitFile(t *testing.T) {
})
}

func TestGitTagGroupWithPrefix(t *testing.T) {
path := "../../../../tests/utils/blameutils/git_tagger_file.txt"
blame := blameutils.SetupBlameResults(t, path, 3)
var blameByFile sync.Map
blameByFile.Store(path, blame)
gitService := &gitservice.GitService{BlameByFile: &blameByFile}
tagGroup := TagGroup{}
tagGroup.GitService = gitService
tagGroup.InitTagGroup("", nil, nil, tagging.WithTagPrefix("prefix_"))

block := &MockTestBlock{
Block: structure.Block{
FilePath: path,
IsTaggable: true,
},
}

err := tagGroup.CreateTagsForBlock(block)
assert.NoError(t, err)
for _, tag := range block.NewTags {
assert.True(t, strings.HasPrefix(tag.GetKey(), "prefix_"))
}
}

var ExpectedFileMappingTagged = map[string]map[int]int{
"originToGit": {1: 1, 2: 2, 3: 3, 4: 4, 5: 5, 6: -1, 7: -1, 8: -1, 9: -1, 10: -1, 11: -1, 12: -1, 13: -1, 14: -1, 15: -1, 16: 6, 17: 7, 18: 8, 19: 9, 20: 10, 21: 11, 22: 12},
"gitToOrigin": {1: 1, 2: 2, 3: 3, 4: 4, 5: 5, 6: 16, 7: 17, 8: 18, 9: 19, 10: 20, 11: 21, 12: 22},
Expand Down

0 comments on commit d159f98

Please sign in to comment.