Просмотр исходного кода

Rename starInfo to repoInfo

Because that's the correct name.  `/users/:username/repos` has the same
format as `/users/:username/starred`.  (Or rather, the other way
around.)
Lucas Stadler лет назад: 10
Родитель
Сommit
c7594b11db
1 измененных файлов с 6 добавлено и 6 удалено
  1. 6 6
      go/stars/stars.go

+ 6 - 6
go/stars/stars.go

28
func main() {
28
func main() {
29
	flag.Parse()
29
	flag.Parse()
30
30
31
	var stars []starInfo
31
	var stars []repoInfo
32
	decoder := json.NewDecoder(os.Stdin)
32
	decoder := json.NewDecoder(os.Stdin)
33
	err := decoder.Decode(&stars)
33
	err := decoder.Decode(&stars)
34
	if err != nil {
34
	if err != nil {
59
	wg.Wait()
59
	wg.Wait()
60
}
60
}
61
61
62
func updateRepo(info starInfo) error {
62
func updateRepo(info repoInfo) error {
63
	f, err := os.Open(path.Join(config.directory, info.RepoName))
63
	f, err := os.Open(path.Join(config.directory, info.RepoName))
64
	if err != nil {
64
	if err != nil {
65
		if os.IsNotExist(err) {
65
		if os.IsNotExist(err) {
82
	return nil
82
	return nil
83
}
83
}
84
84
85
func gitClone(info starInfo) error {
85
func gitClone(info repoInfo) error {
86
	cmd := exec.Command("git", "clone", info.CloneUrl,
86
	cmd := exec.Command("git", "clone", info.CloneUrl,
87
		path.Join(config.directory, info.RepoName))
87
		path.Join(config.directory, info.RepoName))
88
	return cmd.Run()
88
	return cmd.Run()
89
}
89
}
90
90
91
func gitPull(info starInfo) error {
91
func gitPull(info repoInfo) error {
92
	cmd := exec.Command("git", "-C", path.Join(config.directory, info.RepoName), "pull")
92
	cmd := exec.Command("git", "-C", path.Join(config.directory, info.RepoName), "pull")
93
	return cmd.Run()
93
	return cmd.Run()
94
}
94
}
95
95
96
func gitLastCommit(info starInfo) (time.Time, error) {
96
func gitLastCommit(info repoInfo) (time.Time, error) {
97
	cmd := exec.Command("git", "-C", path.Join(config.directory, info.RepoName),
97
	cmd := exec.Command("git", "-C", path.Join(config.directory, info.RepoName),
98
		"log", "-n", "1", "--format=%cd", "--date=iso8601-strict")
98
		"log", "-n", "1", "--format=%cd", "--date=iso8601-strict")
99
	out, err := cmd.Output()
99
	out, err := cmd.Output()
105
	return time.Parse(time.RFC3339, outStr)
105
	return time.Parse(time.RFC3339, outStr)
106
}
106
}
107
107
108
type starInfo struct {
108
type repoInfo struct {
109
	RepoName    string    `json:"full_name"`
109
	RepoName    string    `json:"full_name"`
110
	Description string    `json:"description"`
110
	Description string    `json:"description"`
111
	CloneUrl    string    `json:"git_url"`
111
	CloneUrl    string    `json:"git_url"`