-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
82 lines (69 loc) · 1.88 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
package main
import (
"context"
"fmt"
"os"
"strings"
"time"
"github.com/akagami-harsh/Experience/Jaeger"
"github.com/google/go-github/github"
"golang.org/x/oauth2"
)
const (
owner = "jaegertracing"
repo = "jaeger"
username = "akagami-harsh"
readmeDataPath = "./Jaeger/readmeData.go"
mdFileName = "./Jaeger/README.md"
)
func main() {
ctx := context.Background()
token := os.Getenv("GITHUB_TOKEN")
if token == "" {
fmt.Println("Set the GITHUB_TOKEN environment variable.")
return
}
ts := oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: token},
)
tc := oauth2.NewClient(ctx, ts)
client := github.NewClient(tc)
prs := make([]*github.PullRequest, 0)
for i := 1; i <= 30; i++ {
opts := &github.PullRequestListOptions{
State: "closed",
Head: username,
ListOptions: github.ListOptions{PerPage: 100, Page: i},
}
pr, _, err := client.PullRequests.List(ctx, owner, repo, opts)
if err != nil {
fmt.Printf("Error fetching pull requests: %v\n", err)
return
}
prs = append(prs, pr...)
fmt.Println("Page:", i)
}
filteredPRs := make([]*github.PullRequest, 0)
for _, pull := range prs {
if *pull.User.Login == username {
filteredPRs = append(filteredPRs, pull)
}
}
var sb strings.Builder
sb.WriteString(Jaeger.Data)
sb.WriteString("\n\n")
sb.WriteString("| Date Created | Title | Pull Request Link |\n")
sb.WriteString("| ------------ | ----- | ----------------- |\n")
for _, pr := range filteredPRs {
date := pr.CreatedAt.Format(time.DateOnly)
title := strings.ReplaceAll(*pr.Title, "|", "\\|")
url := *pr.HTMLURL
sb.WriteString(fmt.Sprintf("| %s | %s | [PR link](%s) |\n", date, title, url))
}
err := os.WriteFile(mdFileName, []byte(sb.String()), 0644)
if err != nil {
fmt.Printf("Error writing markdown file: %v\n", err)
return
}
fmt.Printf("Markdown file '%s' created.\n", mdFileName)
}