Skip to content

Commit

Permalink
Merge pull request #1085 from wakatime/bugfix/prevent-logging-folder
Browse files Browse the repository at this point in the history
Support for Xcode project folders
  • Loading branch information
alanhamlett committed Aug 21, 2024
2 parents 0a98e63 + 8e55920 commit 7b8aaba
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
8 changes: 4 additions & 4 deletions pkg/filter/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ func WithLengthValidator() heartbeat.HandleOption {
func Filter(h heartbeat.Heartbeat, config Config) error {
// filter by pattern
if err := filterByPattern(h.Entity, config.Include, config.Exclude); err != nil {
return fmt.Errorf(fmt.Sprintf("filter by pattern: %s", err))
return fmt.Errorf("filter by pattern: %s", err)
}

err := filterFileEntity(h, config)
if err != nil {
return fmt.Errorf(fmt.Sprintf("filter file: %s", err))
return fmt.Errorf("filter file: %s", err)
}

return nil
Expand All @@ -92,7 +92,7 @@ func filterByPattern(entity string, include, exclude []regex.Regex) error {
// filter by exclude pattern
for _, pattern := range exclude {
if pattern.MatchString(entity) {
return fmt.Errorf(fmt.Sprintf("skipping because matches exclude pattern %q", pattern.String()))
return fmt.Errorf("skipping because matches exclude pattern %q", pattern.String())
}
}

Expand Down Expand Up @@ -123,7 +123,7 @@ func filterFileEntity(h heartbeat.Heartbeat, config Config) error {

// skip files that don't exist on disk
if _, err := os.Stat(entity); os.IsNotExist(err) {
return fmt.Errorf(fmt.Sprintf("skipping because of non-existing file %q", entity))
return fmt.Errorf("skipping because of non-existing file %q", entity)
}

// when including only with project file, skip files when the project doesn't have a .wakatime-project file
Expand Down
24 changes: 24 additions & 0 deletions pkg/heartbeat/entity_modifier_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,30 @@ func TestIsXCodePlayground(t *testing.T) {
}
}

func TestIsXCodeProject(t *testing.T) {
tests := map[string]struct {
Dir string
Expected bool
}{
"project directory": {
Dir: setupTestXCodePlayground(t, "wakatime.xcodeproj"),
Expected: true,
},
"not project": {
Dir: setupTestXCodePlayground(t, "wakatime"),
Expected: false,
},
}

for name, test := range tests {
t.Run(name, func(t *testing.T) {
ret := isXCodeProject(test.Dir)

assert.Equal(t, test.Expected, ret)
})
}
}

func setupTestXCodePlayground(t *testing.T, dir string) string {
tmpDir := t.TempDir()

Expand Down
12 changes: 12 additions & 0 deletions pkg/heartbeat/entity_modify.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ func WithEntityModifier() HandleOption {
if h.EntityType == FileType && isXCodePlayground(h.Entity) {
hh[n].Entity = filepath.Join(h.Entity, "Contents.swift")
}
// Support XCode projects
if h.EntityType == FileType && isXCodeProject(h.Entity) {
hh[n].Entity = filepath.Join(h.Entity, "project.pbxproj")
}
}

return next(hh)
Expand All @@ -35,3 +39,11 @@ func isXCodePlayground(fp string) bool {

return isDir(fp)
}

func isXCodeProject(fp string) bool {
if !(strings.HasSuffix(fp, ".xcodeproj")) {
return false
}

return isDir(fp)
}

0 comments on commit 7b8aaba

Please sign in to comment.