velodrome/fetcher/issues.go
func UpdateIssues(db *gorm.DB, client ClientInterface) {
	latest, err := findLatestIssueUpdate(db, client.RepositoryName())
	if err != nil {
		glog.Error("Failed to find last issue update: ", err)
		return
	}
	c := make(chan *github.Issue, 200)

	go client.FetchIssues(latest, c)
	for issue := range c {
		issueOrm, err := NewIssue(issue, client.RepositoryName())
		if err != nil {
			glog.Error("Can't create issue:", err)
			continue
		}
		if db.Create(issueOrm).Error != nil {
			// We assume record already exists. Let's
			// update. First we need to delete labels and
			// assignees, as they are just concatenated
			// otherwise.
			db.Delete(sql.Label{},
				"issue_id = ? AND repository = ?",
				issueOrm.ID, client.RepositoryName())
			db.Delete(sql.Assignee{},
				"issue_id = ? AND repository = ?",
				issueOrm.ID, client.RepositoryName())

			if err := db.Save(issueOrm).Error; err != nil {
				glog.Error("Failed to update database issue: ", err)
			}
		}

		// Issue is updated, find if we have new comments
		UpdateComments(*issue.Number, issueOrm.IsPR, db, client)
		// and find if we have new events
		UpdateIssueEvents(*issue.Number, db, client)
	}
}
func UpdateIssues(db *gorm.DB, client ClientInterface) {
	latest, err := findLatestIssueUpdate(db, client.RepositoryName())
	if err != nil {
		glog.Error("Failed to find last issue update: ", err)
		return
	}
	c := make(chan *github.Issue, 200)

	go client.FetchIssues(latest, c)
	for issue := range c {
		issueOrm, err := NewIssue(issue, client.RepositoryName())
		if err != nil {
			glog.Error("Can't create issue:", err)
			continue
		}
		if db.Create(issueOrm).Error != nil {
			// We assume record already exists. Let's
			// update. First we need to delete labels and
			// assignees, as they are just concatenated
			// otherwise.
			db.Delete(sql.Label{},
				"issue_id = ? AND repository = ?",
				issueOrm.ID, client.RepositoryName())
			db.Delete(sql.Assignee{},
				"issue_id = ? AND repository = ?",
				issueOrm.ID, client.RepositoryName())

			if err := db.Save(issueOrm).Error; err != nil {
				glog.Error("Failed to update database issue: ", err)
			}
		}

		// Issue is updated, find if we have new comments
		UpdateComments(*issue.Number, issueOrm.IsPR, db, client)
		// and find if we have new events
		UpdateIssueEvents(*issue.Number, db, client)
	}
}
// UpdateIssues downloads new issues and saves in database