Пример #1
0
func Unsubscribe(user *model.HGHUser, reponame string, w http.ResponseWriter) {
	bind := model.LoadRepoBinds(reponame, user.Login)
	if bind == nil {
		WriteError(w, "Cant find repo bind.")
		return
	}

	model.DeleteBind(reponame, user.Login)

	WriteAllRepos(user, w)
}
Пример #2
0
func UserOpenedRepo(user *model.HGHUser, reponame string, w http.ResponseWriter) {
	bind := model.LoadRepoBinds(reponame, user.Login)
	if bind == nil {
		WriteError(w, "Cant find repo bind.")
		return
	}

	bind.NewCommitsCount = 0
	bind.LastUserCheck = time.Now().Unix()
	bind.Save()

	WriteAllRepos(user, w)
}
Пример #3
0
func processRepo(repo *model.HGHRepo) {
	fmt.Println("ProcessRepo: " + repo.FullName)
	ts := oauth2.StaticTokenSource(
		&oauth2.Token{AccessToken: GetAvailabelToken()},
	)
	tc := oauth2.NewClient(oauth2.NoContext, ts)

	client := github.NewClient(tc)

	commits, _, err := client.Repositories.ListCommits(repo.Owner, repo.Name, &github.CommitsListOptions{Since: time.Unix(repo.LastCheck, 0)})
	if err != nil {
		fmt.Printf("error: %v\n\n", err)
		AddToQueue(repo)
		return
	}

	users := repo.GetBindedUsers()

	for _, commit := range commits {
		fmt.Printf("Repo: %s. Commit message: %s\n", repo.Name, *commit.SHA)
		for _, user := range users {
			userMap.AddUser(&user)
			bind := model.LoadRepoBinds(repo.FullName, user.Login)
			if bind != nil {
				bind.NewCommitsCount++
				bind.Save()
			}
		}
	}
	repo.LastCheck = time.Now().Unix()
	repo.Save()

	if len(users) == 0 {
		model.DeleteRepo(repo.FullName)
		return // dont add to queue
	}

	AddToQueue(repo)
}