示例#1
0
文件: ui.go 项目: vsco/dcdr
func (u *UI) DrawConfig(cfg *config.Config) {
	tbl := table.New("Component", "Name", "Value", "Description").WithHeaderFormatter(headerFmt).WithFirstColumnFormatter(columnFmt)

	tbl.AddRow("Config", "ConfigPath", config.Path(), "Path to config.hcl")
	tbl.AddRow("Defaults", "Username", cfg.Username, "The username for commits. default: `whoami`")
	tbl.AddRow("Defaults", "Namespace", cfg.Namespace, "K/V namespace")

	tbl.AddRow("Watcher", "OutputPath", cfg.Watcher.OutputPath, "File path to watch and read from")

	tbl.AddRow("Server", "Endpoint", cfg.Server.Endpoint, "The path to serve (GET '/dcdr.json')")
	tbl.AddRow("Server", "Host", cfg.Server.Host, "The server host (:8000")
	tbl.AddRow("Server", "JSONRoot", cfg.Server.JSONRoot, "JSON root node ('dcdr')")

	if cfg.GitEnabled() {
		tbl.AddRow("Git", "RepoPath", cfg.Git.RepoPath, "Audit repo location")
		tbl.AddRow("Git", "RepoURL", cfg.Git.RepoURL, "Audit repo remote origin")
	}

	if cfg.StatsEnabled() {
		tbl.AddRow("Stats", "Namespace", cfg.Stats.Namespace, "Prefix for `dcdr` change events.")
		tbl.AddRow("Stats", "Host", cfg.Stats.Host, "Statsd host ('localhost')")
		tbl.AddRow("Stats", "Port", fmt.Sprintf("%d", cfg.Stats.Port), "Statsd port (8125)")
	}

	tbl.Print()
}
示例#2
0
文件: ui.go 项目: vsco/dcdr
func (u *UI) DrawFeatures(features models.Features) {
	color.NoColor = false
	tbl := table.New("Name", "Type", "Value", "Scope", "Updated By", "Comment").
		WithHeaderFormatter(headerFmt).
		WithFirstColumnFormatter(columnFmt)

	for _, feature := range features {
		tbl.AddRow(feature.Key, feature.FeatureType, feature.Value, feature.Scope, feature.UpdatedBy, feature.Comment)
	}

	tbl.Print()
}
示例#3
0
文件: list.go 项目: schmich/ward
func (app *App) runList() {
	db := app.openStore()
	defer db.Close()

	headerFmt := color.New(color.FgCyan, color.Underline).SprintfFunc()

	table := table.New("Login", "Realm")
	table.WithHeaderFormatter(headerFmt)

	credentials := db.AllCredentials()
	for _, credential := range credentials {
		table.AddRow(credential.Login, credential.Realm)
	}

	table.Print()
}
示例#4
0
func main() {

	var err error
	var cmdLog string

	config := initConfig()

	// Get command line arguments and store args as refs
	f := parseFlags()

	repopath := *f.Path

	// Override the default slack channel if flag is passed in
	if *f.SlackChannel != "" {
		config.Slack.Channel = *f.SlackChannel
	}

	ref1, ref2 := parseArgs()

	// Derive repo from the path
	repo := path.Base(repopath)

	// Determine that Git is installed
	checkForGit()

	// Auth with GitHub
	client := authWithGitHub(config.Github.Token)

	// define table output
	tbl := table.New("PR", "Author", "Description", "URL")

	// Check to ensure our path is a Git repo, if not exit!
	checkPathIsGitRepo(repopath)

	// Output what we are about to do
	cmdLog = fmt.Sprintf("Determining merged branches between the following hashes: %s %s \n", ref1, ref2)
	fmt.Println(cmdLog)

	// Strict vs loose comparison based upon dev branch paradigm
	comparison := "..."
	if *f.Dev {
		comparison = ".."
	}

	// Determine the merged branches between the two hashes
	marg := fmt.Sprintf("%s%s%s", ref1, comparison, ref2)
	c := exec.Command(gc, "-C", repopath, "log", "--merges", "--pretty=format:\"%s\"", marg)
	out, err := c.StdoutPipe()
	if err != nil {
		log.Fatal(err)
	}

	err = c.Start()
	if err != nil {
		log.Fatal(err)
	}

	// iterate through matches, and pull out the issues id into a slice
	var ids []int
	s := bufio.NewScanner(out)
	for s.Scan() {
		t := s.Text()
		r, _ := regexp.Compile("#([0-9]+)")
		sm := r.FindStringSubmatch(t)
		if len(sm) > 0 {
			i, err := strconv.Atoi(sm[1])
			if err == nil {
				ids = append(ids, i)
			}
		}
	}
	err = c.Wait()
	if err != nil {
		log.Fatal(err)
	}

	// if the list is empty, error out
	if len(ids) == 0 {
		cmdLog = fmt.Sprintf("No merged PRs / GitHub issues found between: %s %s", ref1, ref2)
		fmt.Println(cmdLog)
		os.Exit(2)
	}

	// Get info from GitHub (experiment with concurrency)
	pulls := processPullRequests(ids, client, config, repo)

	for _, pull := range pulls {
		i := fmt.Sprintf("#%d", *pull.Number)
		u := fmt.Sprintf("@%s", *pull.User.Login)
		t := fmt.Sprintf("%s", *pull.Title)
		l := fmt.Sprintf("%s/%s/%s/pull/%d", gitHubRoot, config.Github.Org, repo, *pull.Number)
		tbl.AddRow(i, u, t, l)
	}

	// Generate results output
	output := new(bytes.Buffer)
	tbl.WithWriter(output)
	output.WriteString(fmt.Sprintf("%s: Merged GitHub PRs between the following refs: %s %s", strings.ToUpper(repo), ref1, ref2))
	tbl.Print()

	// Print the merge message to console and notifies slack
	mergedMessage := output.String()
	fmt.Println(mergedMessage)
	if !*f.Test {
		notifySlack(mergedMessage, config.Slack)
	}
}