Skip to content

Commit

Permalink
Fix slice bounds out of range (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
ksindi committed Apr 27, 2020
1 parent 53730b7 commit 8bd0095
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
15 changes: 7 additions & 8 deletions git.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ func determineGitArgs(branch string, defaultBranch string) []string {
}

func index(slice []string, item string) int {
for i, _ := range slice {
if slice[i] == item {
return i
}
}
return -1
for i, _ := range slice {
if slice[i] == item {
return i
}
}
return -1
}

func getChangedFiles() []string {
Expand All @@ -74,8 +74,7 @@ func getChangedFiles() []string {
defaultBranch := getEnv(pluginPrefix+"DEFAULT_BRANCH", "master")

cmdArgs := determineGitArgs(branch, defaultBranch)
out := execCommand("git", cmdArgs)
changedFiles := strings.Split(strings.TrimSpace(out), "\n")
changedFiles := strings.Split(execCommand("git", cmdArgs), "\n")

if branch == defaultBranch {
firstMergeBreak := index(changedFiles, "")
Expand Down
3 changes: 3 additions & 0 deletions project.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ func (p *Project) checkAffected(changedFiles []string) bool {
normalizedPath := path.Clean(filePath)
projectDirs := strings.Split(normalizedPath, "/")
for _, changedFile := range changedFiles {
if changedFile == "" {
continue
}
changedDirs := strings.Split(changedFile, "/")
if reflect.DeepEqual(changedDirs[:len(projectDirs)], projectDirs) {
return true
Expand Down

0 comments on commit 8bd0095

Please sign in to comment.