Skip to content

Commit 43cbe0f

Browse files
committed
feat: replace last update with last commit
1 parent a1eba99 commit 43cbe0f

File tree

1 file changed

+34
-17
lines changed

1 file changed

+34
-17
lines changed

internal/cli/action_overlook.go

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"text/tabwriter"
1111
"time"
1212

13+
"github.com/google/go-github/v53/github"
1314
"github.com/sourcegraph/conc/pool"
1415
"github.com/urfave/cli/v2"
1516
)
@@ -19,9 +20,9 @@ const maxPoolGoroutine = 8
1920
var reGitHub = regexp.MustCompile(`github\.com/([^/]*)/([^/]*)`)
2021

2122
type GitHubRepoData struct {
22-
UpdatedAt time.Time
23-
Name string
24-
Star int
23+
LastCommitAt time.Time
24+
Name string
25+
StarCount int
2526
}
2627

2728
func (a *action) Overlook(c *cli.Context) error {
@@ -51,6 +52,8 @@ func (a *action) Overlook(c *cli.Context) error {
5152
for module := range mapImportedModules {
5253
module := module
5354
p.Go(func() {
55+
ctx := context.Background()
56+
5457
if !reGitHub.MatchString(module) {
5558
return
5659
}
@@ -60,41 +63,55 @@ func (a *action) Overlook(c *cli.Context) error {
6063
return
6164
}
6265

63-
ghRepoName := parts[0]
66+
name := parts[0]
6467
mMutex.RLock()
65-
if _, ok := mGHRepoData[ghRepoName]; ok {
68+
if _, ok := mGHRepoData[name]; ok {
6669
mMutex.RUnlock()
6770
return
6871
}
6972
mMutex.RUnlock()
7073

7174
mMutex.Lock()
72-
mGHRepoData[ghRepoName] = struct{}{}
75+
mGHRepoData[name] = struct{}{}
7376
mMutex.Unlock()
7477

7578
owner := parts[1]
7679
repo := parts[2]
7780

78-
ghRepo, _, err := a.ghClient.Repositories.Get(context.Background(), owner, repo)
81+
ghRepo, _, err := a.ghClient.Repositories.Get(ctx, owner, repo)
7982
if err != nil {
80-
a.log("Failed to get GitHub %s/%s: %s\n", owner, repo, err)
83+
a.log("GitHub failed to get repo %s/%s: %s\n", owner, repo, err)
8184
}
8285

83-
var ghStar int
86+
var starCount int
8487
if ghRepo.StargazersCount != nil {
85-
ghStar = *ghRepo.StargazersCount
88+
starCount = *ghRepo.StargazersCount
89+
}
90+
91+
ghCommits, _, err := a.ghClient.Repositories.ListCommits(ctx, owner, repo, &github.CommitsListOptions{
92+
ListOptions: github.ListOptions{
93+
Page: 1,
94+
PerPage: 1,
95+
},
96+
})
97+
if err != nil {
98+
a.log("GitHub failed to get commits %s/%s: %s\n", owner, repo, err)
8699
}
87100

88-
var ghUpdatedAt time.Time
89-
if ghRepo.UpdatedAt != nil {
90-
ghUpdatedAt = ghRepo.UpdatedAt.Time
101+
var lastCommitAt time.Time
102+
if len(ghCommits) != 0 {
103+
if ghCommits[0].Commit != nil &&
104+
ghCommits[0].Commit.Author != nil &&
105+
ghCommits[0].Commit.Author.Date != nil {
106+
lastCommitAt = ghCommits[0].Commit.Author.Date.Time
107+
}
91108
}
92109

93110
listMutex.Lock()
94111
listGHRepoData = append(listGHRepoData, GitHubRepoData{
95-
UpdatedAt: ghUpdatedAt,
96-
Name: ghRepoName,
97-
Star: ghStar,
112+
LastCommitAt: lastCommitAt,
113+
Name: name,
114+
StarCount: starCount,
98115
})
99116
listMutex.Unlock()
100117
})
@@ -109,7 +126,7 @@ func (a *action) Overlook(c *cli.Context) error {
109126
// Print
110127
w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
111128
for _, r := range listGHRepoData {
112-
fmt.Fprintf(w, "Module %s\t%d\t\tLast updated %s\n", r.Name, r.Star, r.UpdatedAt.Format(time.DateOnly))
129+
fmt.Fprintf(w, "Module %s\t%d\t\tLast commit %s\n", r.Name, r.StarCount, r.LastCommitAt.Format(time.DateOnly))
113130
}
114131
w.Flush()
115132

0 commit comments

Comments
 (0)