-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
745 lines (669 loc) · 20.6 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
package main
import (
"bufio"
"context"
"flag"
"fmt"
"html/template"
"log"
"os"
"sort"
"strings"
"time"
"github.com/google/go-github/v50/github"
"golang.org/x/oauth2"
)
type UserMetrics struct {
Commits int
HoC int
Issues int
LcP float64
Msgs int
Pulls int
Reviews int
Score float64
Repos map[string]int // Repositories touched and lines changed
}
type UserMetricsView struct {
User string
Metrics UserMetrics
CreatedSince string
Organization string
TopRepos string // Top 3 repositories formatted as org/repo(LoC)
}
var (
client *github.Client
verbose bool
days int
organization string
delay int
metricsFile string
outputFile string
)
func main() {
var token string
var coders coderList
var repos repoList
var metric string
// Define flags
flag.StringVar(&token, "token", "", "GitHub token")
flag.IntVar(&days, "days", 30, "Number of days to measure")
flag.Var(&coders, "coder", "GitHub usernames to measure (can be specified multiple times)")
flag.Var(&repos, "repo", "GitHub repositories to measure (can be specified multiple times)")
flag.BoolVar(&verbose, "verbose", false, "Enable verbose logging")
flag.StringVar(&metric, "metric", "all", "Specific metric to calculate (commits, hoc, issues, lcp, msgs, pulls, reviews, score)")
flag.IntVar(&delay, "delay", 30, "Delay between API calls in seconds")
flag.StringVar(&organization, "organization", "", "GitHub organization to filter repositories")
flag.StringVar(&metricsFile, "metrics-file", ".githubmetrics", "Path to the metrics configuration file")
flag.StringVar(&outputFile, "output-file", "metrics.html", "Path to the output file")
flag.Parse()
if _, err := os.Stat(metricsFile); err == nil {
file, err := os.Open(metricsFile)
if err != nil {
log.Fatalf("Error opening metrics file: %v", err)
}
defer file.Close()
scanner := bufio.NewScanner(file)
for scanner.Scan() {
line := strings.TrimSpace(scanner.Text())
if line != "" {
// Split the line into key and value
keyValue := strings.SplitN(line, "=", 2)
if len(keyValue) != 2 {
continue
}
key, value := keyValue[0], keyValue[1]
// Manually set the flags using flag.CommandLine.Set
switch key {
case "--token":
flag.CommandLine.Set("token", value)
case "--days":
flag.CommandLine.Set("days", value)
case "--coder":
coders.Set(value)
case "--repo":
repos.Set(value)
case "--verbose":
flag.CommandLine.Set("verbose", value)
case "--metric":
flag.CommandLine.Set("metric", value)
case "--delay":
flag.CommandLine.Set("delay", value)
case "--organization":
flag.CommandLine.Set("organization", value)
}
}
}
if err := scanner.Err(); err != nil {
log.Fatalf("Error reading metrics file: %v", err)
}
}
// Parse command-line flags
flag.Parse()
if len(repos) == 0 && organization == "" {
log.Fatal("No repositories or organization specified. Use --repo to add repositories or --organization to filter by organization.")
}
client = createGitHubClient(token)
metrics := calculateMetrics(coders, metric)
err := renderTemplate(metrics)
if err != nil {
log.Fatalf("Error rendering template: %v", err)
}
}
// coderList is a custom flag.Value implementation to handle multiple coders
type coderList []string
func (c *coderList) String() string {
return fmt.Sprint(*c)
}
func (c *coderList) Set(value string) error {
*c = append(*c, value)
return nil
}
// repoList is a custom flag.Value implementation to handle multiple repositories
type repoList []string
func (r *repoList) String() string {
return fmt.Sprint(*r)
}
func (r *repoList) Set(value string) error {
*r = append(*r, value)
return nil
}
func createGitHubClient(token string) *github.Client {
ctx := context.Background()
ts := oauth2.StaticTokenSource(&oauth2.Token{AccessToken: token})
tc := oauth2.NewClient(ctx, ts)
return github.NewClient(tc)
}
func calculateMetrics(users []string, metric string) map[string]UserMetrics {
if verbose {
log.Printf("Calculating %s metric for %d users for %d days\n", metric, len(users), days)
}
metrics := make(map[string]UserMetrics)
for _, user := range users {
repos := getUserRepositories(user)
fmt.Printf("User %s has %d repositories\n", user, len(repos))
for _, repoFullName := range repos {
owner, repoName := parseRepo(repoFullName)
if owner == "" || repoName == "" {
log.Printf("Skipping invalid repo string: %s", repoFullName)
continue
}
switch metric {
case "commits":
commits := getCommits(owner, repoName, user)
metrics[user] = updateUserMetrics(metrics[user], UserMetrics{Commits: commits})
case "hoc":
hoc := getHoC(owner, repoName, user)
metrics[user] = updateUserMetrics(metrics[user], UserMetrics{HoC: hoc, Repos: map[string]int{repoFullName: hoc}})
case "issues":
issues := getIssues(owner, repoName, user)
metrics[user] = updateUserMetrics(metrics[user], UserMetrics{Issues: issues})
case "lcp":
lcp := getLcP(owner, repoName, user)
metrics[user] = updateUserMetrics(metrics[user], UserMetrics{LcP: lcp})
case "msgs":
msgs := getMsgs(owner, repoName, user)
metrics[user] = updateUserMetrics(metrics[user], UserMetrics{Msgs: msgs})
case "pulls":
pulls := getPulls(owner, repoName, user)
metrics[user] = updateUserMetrics(metrics[user], UserMetrics{Pulls: pulls})
case "reviews":
reviews := getReviews(owner, repoName, user)
metrics[user] = updateUserMetrics(metrics[user], UserMetrics{Reviews: reviews})
case "all":
commits := getCommits(owner, repoName, user)
hoc := getHoC(owner, repoName, user)
issues := getIssues(owner, repoName, user)
lcp := getLcP(owner, repoName, user)
msgs := getMsgs(owner, repoName, user)
pulls := getPulls(owner, repoName, user)
reviews := getReviews(owner, repoName, user)
metrics[user] = updateUserMetrics(metrics[user], UserMetrics{
Commits: commits,
HoC: hoc,
Issues: issues,
LcP: lcp,
Msgs: msgs,
Pulls: pulls,
Reviews: reviews,
Repos: map[string]int{repoFullName: hoc},
})
default:
log.Fatalf("Unknown metric: %s", metric)
}
}
err := renderTemplate(metrics)
if err != nil {
log.Fatalf("Error rendering template: %v", err)
}
}
return metrics
}
func retryWithBackoff(_ context.Context, attempts int, delay time.Duration, fn func() (interface{}, *github.Response, error)) (interface{}, *github.Response, error) {
var err error
for i := 0; i < attempts; i++ {
var result interface{}
var resp *github.Response
result, resp, err = fn()
if err == nil {
return result, resp, nil
}
log.Printf("Attempt %d failed with error: %v", i+1, err)
if resp != nil {
if resp.StatusCode == 403 {
sleepDuration := time.Until(time.Unix(resp.Rate.Reset.Unix(), 0))
log.Printf("Rate limit exceeded. Sleeping until rate limit reset at %v", time.Unix(resp.Rate.Reset.Unix(), 0))
time.Sleep(sleepDuration + delay) // Adding extra buffer time
}
}
}
return nil, nil, err
}
func updateUserMetrics(metrics, update UserMetrics) UserMetrics {
metrics.Commits += update.Commits
metrics.HoC += update.HoC
metrics.Issues += update.Issues
metrics.LcP += update.LcP
metrics.Msgs += update.Msgs
metrics.Pulls += update.Pulls
metrics.Reviews += update.Reviews
if metrics.Repos == nil {
metrics.Repos = make(map[string]int)
}
for repo, hoc := range update.Repos {
metrics.Repos[repo] += hoc
}
metrics.Score = calculateScore(metrics)
return metrics
}
func calculateScore(metrics UserMetrics) float64 {
return float64(metrics.HoC) + float64(metrics.Pulls)*250 + float64(metrics.Issues)*50 + float64(metrics.Commits)*5 + float64(metrics.Reviews)*150 + float64(metrics.Msgs)*5
}
func renderTemplate(metrics map[string]UserMetrics) error {
var sortedMetrics []UserMetricsView
for user, metric := range metrics {
topRepos := getTopRepos(metric.Repos)
sortedMetrics = append(sortedMetrics, UserMetricsView{
User: user,
Metrics: metric,
CreatedSince: time.Now().AddDate(0, 0, -days).Format("2006-01-02"),
Organization: organization,
TopRepos: topRepos,
})
}
sort.Slice(sortedMetrics, func(i, j int) bool {
return sortedMetrics[i].Metrics.Score > sortedMetrics[j].Metrics.Score
})
tmpl, err := template.ParseFiles("template.html")
if err != nil {
return err
}
file, err := os.Create(outputFile)
if err != nil {
return err
}
defer file.Close()
return tmpl.Execute(file, sortedMetrics)
}
func getTopRepos(repos map[string]int) string {
type repo struct {
Name string
HoC int
}
var repoList []repo
for name, hoc := range repos {
repoList = append(repoList, repo{Name: name, HoC: hoc})
}
sort.Slice(repoList, func(i, j int) bool {
return repoList[i].HoC > repoList[j].HoC
})
var topRepos []string
for i := 0; i < len(repoList) && i < 3; i++ {
topRepos = append(topRepos, fmt.Sprintf("%s(%d)", repoList[i].Name, repoList[i].HoC))
}
return strings.Join(topRepos, ", ")
}
func parseRepo(repo string) (string, string) {
parts := strings.Split(repo, "/")
if len(parts) != 2 {
return "", ""
}
return parts[0], parts[1]
}
func getCommits(owner, repo, user string) int {
ctx := context.Background()
commits := 0
opts := &git.luolix.topmitsListOptions{
Author: user,
Since: time.Now().AddDate(0, 0, -days),
ListOptions: github.ListOptions{
PerPage: 100,
},
}
for {
result, resp, err := retryWithBackoff(ctx, 5, time.Second, func() (interface{}, *github.Response, error) {
return client.Repositories.ListCommits(ctx, owner, repo, opts)
})
if err != nil {
log.Printf("Error fetching commits for user %s in repo %s/%s: %v\n", user, owner, repo, err)
return commits
}
commitList := result.([]*github.RepositoryCommit)
for _, commit := range commitList {
if commit.Author != nil && commit.Author.GetLogin() == user && !isMergeCommit(commit) {
commits++
if verbose {
log.Printf("Found commit %s by %s in repo %s/%s\n", commit.GetSHA(), user, owner, repo)
}
}
}
if resp.NextPage == 0 {
break
}
opts.Page = resp.NextPage
}
return commits
}
func getHoC(owner, repo, user string) int {
ctx := context.Background()
hoc := 0
opts := &git.luolix.topmitsListOptions{
Author: user,
Since: time.Now().AddDate(0, 0, -days),
ListOptions: github.ListOptions{
PerPage: 100,
},
}
for {
result, resp, err := retryWithBackoff(ctx, 5, time.Second, func() (interface{}, *github.Response, error) {
return client.Repositories.ListCommits(ctx, owner, repo, opts)
})
if err != nil {
log.Printf("Error fetching commits for user %s in repo %s/%s: %v\n", user, owner, repo, err)
return hoc
}
commitList := result.([]*github.RepositoryCommit)
for _, commit := range commitList {
if commit.Author != nil && commit.Author.GetLogin() == user && !isMergeCommit(commit) {
details, _, err := client.Repositories.GetCommit(ctx, owner, repo, commit.GetSHA(), nil)
if err != nil {
log.Printf("Error fetching commit details for commit %s: %v\n", commit.GetSHA(), err)
continue
}
for _, file := range details.Files {
hoc += file.GetAdditions() + file.GetChanges()
if verbose {
log.Printf("Commit %s: file %s - additions: %d, changes: %d\n", commit.GetSHA(), file.GetFilename(), file.GetAdditions(), file.GetChanges())
}
}
}
}
if resp.NextPage == 0 {
break
}
opts.Page = resp.NextPage
}
return hoc
}
func getIssues(owner, repo, user string) int {
ctx := context.Background()
issues := 0
opts := &github.IssueListByRepoOptions{
Creator: user,
Since: time.Now().AddDate(0, 0, -days),
ListOptions: github.ListOptions{
PerPage: 100,
},
}
for {
if verbose {
log.Printf("Fetching issues for user %s in repo %s/%s\n", user, owner, repo)
}
result, resp, err := retryWithBackoff(ctx, 5, time.Second, func() (interface{}, *github.Response, error) {
return client.Issues.ListByRepo(ctx, owner, repo, opts)
})
if err != nil {
log.Printf("Error fetching issues for user %s in repo %s/%s: %v\n", user, owner, repo, err)
return issues
}
issueList := result.([]*github.Issue)
for _, issue := range issueList {
if !issue.IsPullRequest() {
issues++
if verbose {
log.Printf("Found issue #%d by %s in repo %s/%s\n", issue.GetNumber(), user, owner, repo)
}
}
}
if resp.NextPage == 0 {
break
}
opts.Page = resp.NextPage
}
if verbose {
log.Printf("Total issues for user %s in repo %s/%s: %d\n", user, owner, repo, issues)
}
return issues
}
func getLcP(owner, repo, user string) float64 {
ctx := context.Background()
totalTime := 0.0
count := 0
opts := &github.IssueListByRepoOptions{
Creator: user,
State: "closed",
Since: time.Now().AddDate(0, 0, -days),
ListOptions: github.ListOptions{
PerPage: 100,
},
}
for {
result, resp, err := retryWithBackoff(ctx, 5, time.Second, func() (interface{}, *github.Response, error) {
return client.Issues.ListByRepo(ctx, owner, repo, opts)
})
if err != nil {
log.Printf("Error fetching issues for user %s in repo %s/%s: %v\n", user, owner, repo, err)
return 0.0
}
issues := result.([]*github.Issue)
for _, issue := range issues {
if issue.IsPullRequest() && issue.CreatedAt != nil && issue.ClosedAt != nil {
duration := issue.ClosedAt.Sub(issue.CreatedAt.Time).Hours()
totalTime += duration
count++
if verbose {
log.Printf("Pull request #%d by %s: created at %s, closed at %s, duration: %.2f hours\n", issue.GetNumber(), user, issue.CreatedAt.String(), issue.ClosedAt.String(), duration)
}
}
}
if resp.NextPage == 0 {
break
}
opts.Page = resp.NextPage
}
if count == 0 {
return 0.0
}
averageLifecycle := totalTime / float64(count)
if verbose {
log.Printf("Average lifecycle of pull requests for user %s in repo %s/%s over the last %d days: %.2f hours\n", user, owner, repo, days, averageLifecycle)
}
return averageLifecycle
}
func getMsgs(owner, repo, user string) int {
ctx := context.Background()
msgs := 0
query := fmt.Sprintf("repo:%s/%s is:pr commenter:%s created:>%s", owner, repo, user, time.Now().AddDate(0, 0, -days).Format("2006-01-02"))
opts := &github.SearchOptions{
Sort: "created",
Order: "desc",
ListOptions: github.ListOptions{
PerPage: 100,
},
}
for {
result, resp, err := retryWithBackoff(ctx, 5, time.Second, func() (interface{}, *github.Response, error) {
return client.Search.Issues(ctx, query, opts)
})
if err != nil {
log.Printf("Error fetching pull request comments for user %s in repo %s/%s: %v\n", user, owner, repo, err)
return msgs
}
issues := result.(*github.IssuesSearchResult)
for _, pr := range issues.Issues {
msgs += pr.GetComments()
if verbose {
log.Printf("Pull request #%d by %s in repo %s/%s has %d comments\n", pr.GetNumber(), user, owner, repo, pr.GetComments())
}
}
if resp.NextPage == 0 {
break
}
opts.Page = resp.NextPage
}
return msgs
}
func getPulls(owner, repo, user string) int {
ctx := context.Background()
pulls := 0
query := fmt.Sprintf("repo:%s/%s is:pr author:%s merged:>%s", owner, repo, user, time.Now().AddDate(0, 0, -days).Format("2006-01-02"))
opts := &github.SearchOptions{
Sort: "created",
Order: "desc",
ListOptions: github.ListOptions{
PerPage: 100,
},
}
for {
result, resp, err := retryWithBackoff(ctx, 5, time.Second, func() (interface{}, *github.Response, error) {
return client.Search.Issues(ctx, query, opts)
})
if err != nil {
log.Printf("Error fetching pull requests for user %s in repo %s/%s: %v\n", user, owner, repo, err)
return pulls
}
issues := result.(*github.IssuesSearchResult)
for _, issue := range issues.Issues {
if issue.IsPullRequest() && issue.ClosedAt != nil {
pulls++
if verbose {
log.Printf("Pull request #%d by %s in repo %s/%s was merged at %s\n", issue.GetNumber(), user, owner, repo, issue.ClosedAt.String())
}
}
}
if resp.NextPage == 0 {
break
}
opts.Page = resp.NextPage
}
return pulls
}
func getReviews(owner, repo, user string) int {
ctx := context.Background()
reviewsCount := 0
query := fmt.Sprintf("repo:%s/%s reviewed-by:%s is:pr merged:>%s", owner, repo, user, time.Now().AddDate(0, 0, -days).Format("2006-01-02"))
opts := &github.SearchOptions{
Sort: "created",
Order: "desc",
ListOptions: github.ListOptions{
PerPage: 100,
},
}
for {
result, resp, err := retryWithBackoff(ctx, 5, time.Second, func() (interface{}, *github.Response, error) {
return client.Search.Issues(ctx, query, opts)
})
issues := result.(*github.IssuesSearchResult)
if err != nil {
log.Printf("Error fetching reviewed pull requests for user %s in repo %s/%s: %v\n", user, owner, repo, err)
return reviewsCount
}
for _, issue := range issues.Issues {
reviewsCount++
if verbose {
log.Printf("Pull request #%d reviewed by %s in repo %s/%s was merged at %s\n", issue.GetNumber(), user, owner, repo, issue.ClosedAt.String())
}
}
if resp.NextPage == 0 {
break
}
opts.Page = resp.NextPage
}
return reviewsCount
}
func isMergeCommit(commit *github.RepositoryCommit) bool {
return commit.Parents != nil && len(commit.Parents) > 1
}
func getUserRepositories(user string) []string {
ctx := context.Background()
reposMap := make(map[string]bool)
since := time.Now().AddDate(0, 0, -days)
// Get repositories where the user created pull requests
query := fmt.Sprintf("author:%s created:>%s", user, since)
searchOpts := &github.SearchOptions{
Sort: "created",
Order: "desc",
ListOptions: github.ListOptions{
PerPage: 100,
},
}
for {
result, resp, err := retryWithBackoff(ctx, 5, time.Second, func() (interface{}, *github.Response, error) {
return client.Search.Issues(ctx, query, searchOpts)
})
if err != nil {
log.Printf("Error fetching pull requests commented by user %s: %v\n", user, err)
break
}
issues := result.(*github.IssuesSearchResult)
for _, issue := range issues.Issues {
if issue.IsPullRequest() {
repoFullName := parseRepoURL(issue.GetRepositoryURL())
if repoFullName != "" && (organization == "" || strings.HasPrefix(repoFullName, organization+"/")) {
reposMap[repoFullName] = true
if verbose {
log.Printf("User %s created pull request in repository %s\n", user, repoFullName)
}
}
}
}
if resp.NextPage == 0 {
break
}
searchOpts.Page = resp.NextPage
}
// Get repositories where the user commented on pull requests
query = fmt.Sprintf("commenter:%s created:>%s", user, since.Format("2006-01-02"))
searchOpts = &github.SearchOptions{
Sort: "created",
Order: "desc",
ListOptions: github.ListOptions{
PerPage: 100,
},
}
for {
result, resp, err := retryWithBackoff(ctx, 5, time.Second, func() (interface{}, *github.Response, error) {
return client.Search.Issues(ctx, query, searchOpts)
})
if err != nil {
log.Printf("Error fetching pull requests commented by user %s: %v\n", user, err)
break
}
issues := result.(*github.IssuesSearchResult)
for _, issue := range issues.Issues {
if issue.IsPullRequest() {
repoFullName := parseRepoURL(issue.GetRepositoryURL())
if repoFullName != "" && (organization == "" || strings.HasPrefix(repoFullName, organization+"/")) {
reposMap[repoFullName] = true
if verbose {
log.Printf("User %s commented on pull request in repository %s\n", user, repoFullName)
}
}
}
}
if resp.NextPage == 0 {
break
}
searchOpts.Page = resp.NextPage
}
// Get repositories where the user reviewed pull requests
query = fmt.Sprintf("reviewed-by:%s created:>%s", user, since.Format("2006-01-02"))
for {
result, resp, err := retryWithBackoff(ctx, 5, time.Second, func() (interface{}, *github.Response, error) {
return client.Search.Issues(ctx, query, searchOpts)
})
if err != nil {
log.Printf("Error fetching pull requests reviewed by user %s: %v\n", user, err)
break
}
issues := result.(*github.IssuesSearchResult)
for _, issue := range issues.Issues {
if issue.IsPullRequest() {
repoFullName := parseRepoURL(issue.GetRepositoryURL())
if repoFullName != "" && (organization == "" || strings.HasPrefix(repoFullName, organization+"/")) {
reposMap[repoFullName] = true
if verbose {
log.Printf("User %s reviewed pull request in repository %s\n", user, repoFullName)
}
}
}
}
if resp.NextPage == 0 {
break
}
searchOpts.Page = resp.NextPage
}
// Convert map keys to slice
var reposList []string
for repo := range reposMap {
reposList = append(reposList, repo)
}
return reposList
}
func parseRepoURL(repoURL string) string {
parts := strings.Split(repoURL, "/")
if len(parts) < 2 {
return ""
}
return fmt.Sprintf("%s/%s", parts[len(parts)-2], parts[len(parts)-1])
}