Esempio n. 1
0
func Handle(repoList map[string]string, projectTypeToCheck string, filter string, output_channel chan output.Payload) {
	var wg sync.WaitGroup

	for projectType, path := range repoList {
		if projectTypeToCheck == "" || projectTypeToCheck == projectType {
			output_channel <- output.Print(fmt.Sprintf("\nChecking '%s' (%s) repos...", projectType, path))

			visit := func(visitedPath string, info os.FileInfo, err error) error {
				if err != nil {
					output_channel <- output.Error(fmt.Sprintf("- %s", err.Error()))
					return nil
				}
				matched, _ := regexp.MatchString(filter, visitedPath)
				if info.IsDir() && (filter == "" || matched) {
					wg.Add(1)
					go repo.Check(path, visitedPath, output_channel, &wg)
				}
				return nil
			}

			err := filepath.Walk(path, visit)
			if err != nil {
				output_channel <- output.FatalError(err.Error())
			}
		}

		wg.Wait()
	}
	wg.Wait()
}
Esempio n. 2
0
func Check(root string, path string, output_channel chan output.Payload, wg *sync.WaitGroup) {
	exists, err := Exists(filepath.Join(path, ".git"))

	if err != nil {
		return
	}

	if exists {
		modified_files := exec.Command("git", "status", "--porcelain")
		modified_files.Dir = path

		count_out, _ := modified_files.Output()
		modified_lines := strings.Split(string(count_out), "\n")
		modified := len(modified_lines) - 1

		if err != nil {
			output_channel <- output.FatalError(err.Error())
		}

		changes := []string{}

		if modified > 0 && modified_lines[0] != "" {
			changes = append(changes, output.ApplyColour(fmt.Sprintf(" M(%d)", modified), "red"))
		}

		branch := exec.Command("git", "rev-parse", "--abbrev-ref", "HEAD")
		branch.Dir = path
		bstdout, _ := branch.Output()
		branch_name := strings.TrimSpace(string(bstdout[:]))

		local := exec.Command("git", "rev-parse", branch_name)
		local.Dir = path
		lstdout, _ := local.Output()
		local_ref := strings.TrimSpace(string(lstdout[:]))

		remote := exec.Command("git", "rev-parse", fmt.Sprintf("origin/%s", branch_name))
		remote.Dir = path
		rstdout, err := remote.Output()
		remote_ref := strings.TrimSpace(string(rstdout[:]))

		if err == nil && remote_ref != local_ref {
			changes = append(changes, output.ApplyColour(" P", "blue"))
		}

		if len(changes) > 0 {
			var buffer bytes.Buffer

			repo_name := strings.Replace(path, fmt.Sprintf("%s%s", root, string(os.PathSeparator)), "", -1)

			buffer.WriteString(fmt.Sprintf("- %s (%s)", repo_name, branch_name))
			for _, change := range changes {
				buffer.WriteString(change)
			}
			output_channel <- output.Print(buffer.String())
		}

	}
	wg.Done()
}