api: remove oldestCommit support

For codesite-migrated repositories, looking at the oldest commit is
preferable to determine the "create date". But for forked projects,
looking at the oldest commit is incorrect for when we started the project
If inferring the real create date has to be manual, then let's rely on
the Gitea metadata - it's faster and can be modified by hand if needed
This commit is contained in:
mappu 2020-11-19 12:06:57 +13:00
parent 65e369deea
commit 90cd2b6440
3 changed files with 3 additions and 25 deletions

22
api.go
View File

@ -19,7 +19,6 @@ type Repo struct {
GiteaCreated time.Time `json:"created_at"` GiteaCreated time.Time `json:"created_at"`
GiteaUpdated time.Time `json:"updated_at"` GiteaUpdated time.Time `json:"updated_at"`
oldestCommit time.Time
newestCommit time.Time newestCommit time.Time
topics []string topics []string
} }
@ -46,16 +45,6 @@ func (this *Application) populateCommitInfo(ctx context.Context, rr *Repo) {
} }
} }
// The oldest commit needs us to page through the commit history to find it
oldestCommit, err := this.oldestCommit(ctx, rr.Name, "")
if err != nil {
log.Printf("finding oldest commit for '%s': %s", rr.Name, err)
rr.oldestCommit = rr.GiteaCreated // best guess
} else {
rr.oldestCommit = oldestCommit.Commit.Author.Date
}
} }
type ContentsResponse struct { type ContentsResponse struct {
@ -189,17 +178,6 @@ func (this *Application) commits(ctx context.Context, repo, ref string) ([]Commi
return ret, nil return ret, nil
} }
func (this *Application) oldestCommit(ctx context.Context, repo, ref string) (CommitListEntry, error) {
cc, err := this.commits(ctx, repo, ref)
if err != nil {
return CommitListEntry{}, err
}
// Take the last listed entry
// TODO maybe need to iterate/sort?
return cc[len(cc)-1], nil
}
// reposPage gets a single page of the list of Git repositories in this organisation. // reposPage gets a single page of the list of Git repositories in this organisation.
func (this *Application) reposPage(ctx context.Context, page, limit int) ([]Repo, error) { func (this *Application) reposPage(ctx context.Context, page, limit int) ([]Repo, error) {
var repos []Repo var repos []Repo

View File

@ -114,8 +114,8 @@ func (this *Application) Homepage(w http.ResponseWriter, r *http.Request) {
<tr <tr
class="`+html.EscapeString(rowClass)+`" class="`+html.EscapeString(rowClass)+`"
data-sort-al="`+fmt.Sprintf("-%d", this.reposAlphabeticalOrder[repo.Name])+`" data-sort-al="`+fmt.Sprintf("-%d", this.reposAlphabeticalOrder[repo.Name])+`"
data-sort-ls="`+fmt.Sprintf("%.0f", repo.newestCommit.Sub(repo.oldestCommit).Seconds())+`" data-sort-ls="`+fmt.Sprintf("%.0f", repo.newestCommit.Sub(repo.GiteaCreated).Seconds())+`"
data-sort-ct="`+fmt.Sprintf("%d", repo.oldestCommit.Unix())+`" data-sort-ct="`+fmt.Sprintf("%d", repo.GiteaCreated.Unix())+`"
data-sort-mt="`+fmt.Sprintf("%d", repo.newestCommit.Unix())+`" data-sort-mt="`+fmt.Sprintf("%d", repo.newestCommit.Unix())+`"
> >
<td> <td>

View File

@ -71,7 +71,7 @@ func (this *Application) sync(ctx context.Context) (bool, error) {
// But then make sure the final sort is by most-recently-created // But then make sure the final sort is by most-recently-created
sort.Slice(repos, func(i, j int) bool { sort.Slice(repos, func(i, j int) bool {
return repos[i].oldestCommit.After(repos[j].oldestCommit) return repos[i].GiteaCreated.After(repos[j].GiteaCreated)
}) })
// Commit our changes for the other threads to look at // Commit our changes for the other threads to look at