Exemplo n.º 1
0
func main() {
	flag.Parse()

	token := os.Getenv("GITHUB_OAUTH_TOKEN")
	if len(token) == 0 {
		log.Fatalf("Set GITHUB_OAUTH_TOKEN env")
	}

	args := flag.Args()
	if len(args) == 0 {
		log.Fatalf("Need path to godeps file")
	}
	gd, err := gosupplychain.LoadGodepsFile(args[0])
	if err != nil {
		log.Fatalf("Error loading godeps file %q: %s", args[0], err)
	}
	gh := gosupplychain.NewGitHub(token)

	for _, dep := range gd.Deps {
		parts := strings.Split(dep.ImportPath, "/")
		if len(parts) < 2 {
			log.Printf("Skipping %s", dep.ImportPath)
			continue
		}
		if parts[0] != "github.com" {
			log.Printf("Skupping %s", dep.ImportPath)
			continue
		}

		compare, _, err := gh.Client.Repositories.CompareCommits(parts[1], parts[2], dep.Rev, "HEAD")
		if err != nil {
			log.Printf("got error reading repo %s: %s", dep.ImportPath, err)
			continue
		}

		fmt.Printf("%s \n", dep.ImportPath)
		for pos, commit := range compare.Commits {
			msg := ""
			if commit.Commit.Message != nil {
				msg = *commit.Commit.Message
				msg = strings.Replace(msg, "\t", " ", -1)
				msg = strings.Replace(msg, "\r", " ", -1)
				msg = strings.Replace(msg, "\n", " ", -1)
				msg = strings.Replace(msg, "  ", " ", -1)
				if len(msg) > 80 {
					msg = msg[:80] + "..."
				}
			}
			fmt.Printf("    %d %s %s\n", pos, *commit.SHA, msg)
		}
	}
}
Exemplo n.º 2
0
func main() {
	searchQuery := flag.String("query", "language:go", "Search query to be executed per user")
	addLicense := flag.Bool("add-license", true, "Attemp to determine software license (slower)")

	// TODO add flag for template
	// TODO add flag for output file

	flag.Parse()

	token := os.Getenv("GITHUB_OAUTH_TOKEN")
	if len(token) == 0 {
		log.Fatalf("Set GITHUB_OAUTH_TOKEN env")
	}

	names := flag.Args()
	sort.Strings(names)

	gh := gosupplychain.NewGitHub(token)
	users, err := gh.SearchByUsers(token, *searchQuery, names)
	if err != nil {
		log.Fatalf("Github failed: %s", err)
	}

	licmap := make(map[string]license.License)
	if *addLicense {
		for _, user := range users {
			for _, repo := range user.Repos {
				log.Printf("Checking license for %s", repo.Name)
				parts := strings.SplitN(repo.Name, "/", 2)
				lic, err := gh.GuessLicenseFromRepo(parts[0], parts[1], "master")
				if err != nil {
					log.Printf("Unable to check license for %s: %s", repo.Name, err)
				}
				log.Printf("... Got %s", lic.Type)
				licmap[repo.Name] = lic
			}
		}
	}
	t, err := template.New("test").Parse(SearchMarkdownTemplate)
	if err != nil {
		log.Fatalf("Template init failed: %s", err)
	}

	err = t.Execute(os.Stdout, map[string]interface{}{
		"Users":    users,
		"Licenses": licmap,
	})
	if err != nil {
		log.Fatalf("Template exec failed: %s", err)
	}
}
Exemplo n.º 3
0
func main() {
	flag.Parse()

	repo := flag.Args()[0]
	parts := strings.SplitN(repo, "/", 2)

	log.Printf("%+v", parts)
	token := os.Getenv("GITHUB_OAUTH_TOKEN")
	if len(token) == 0 {
		log.Fatalf("Set GITHUB_OAUTH_TOKEN env")
	}

	gh := gosupplychain.NewGitHub(token)
	lic, err := gh.GuessLicenseFromRepo(parts[0], parts[1], "master")
	if err != nil {
		log.Fatalf("%s", err)
	}
	if lic.Type != "" {
		fmt.Printf("%s, %s\n", lic.Type, lic.File)
	}
}