Skip to content

Commit 54ff6a1

Browse files
committed
Use gh token for Models auth
1 parent 9a1948a commit 54ff6a1

File tree

8 files changed

+32
-657
lines changed

8 files changed

+32
-657
lines changed

cmd/standup/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func runStandup(cmd *cobra.Command, args []string) error {
6262
endDate := time.Now()
6363
startDate := endDate.AddDate(0, 0, -flagDays)
6464

65-
fmt.Printf("Analyzing GitHub activity for %s (%s to %s)\n",
65+
fmt.Printf("Analyzing GitHub activity for %s (%s to %s)\n",
6666
flagUser, startDate.Format("2006-01-02"), endDate.Format("2006-01-02"))
6767

6868
fmt.Print("Collecting GitHub activity data...\n")

github.go

Lines changed: 0 additions & 241 deletions
This file was deleted.

internal/github/client.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func NewClient() (*Client, error) {
2121
return nil, err
2222
}
2323
fmt.Println("Done")
24-
24+
2525
return &Client{client: client}, nil
2626
}
2727

@@ -89,9 +89,9 @@ func (c *Client) getCommits(username, repo string, startDate, endDate time.Time)
8989
var activities []types.GitHubActivity
9090

9191
// Search for commits by author
92-
query := fmt.Sprintf("author:%s committer-date:%s..%s",
92+
query := fmt.Sprintf("author:%s committer-date:%s..%s",
9393
username, startDate.Format("2006-01-02"), endDate.Format("2006-01-02"))
94-
94+
9595
if repo != "" {
9696
query += fmt.Sprintf(" repo:%s", repo)
9797
}
@@ -139,19 +139,19 @@ func (c *Client) getPullRequests(username, repo string, startDate, endDate time.
139139
var activities []types.GitHubActivity
140140

141141
// Search for pull requests
142-
query := fmt.Sprintf("author:%s created:%s..%s",
142+
query := fmt.Sprintf("author:%s created:%s..%s",
143143
username, startDate.Format("2006-01-02"), endDate.Format("2006-01-02"))
144-
144+
145145
if repo != "" {
146146
query += fmt.Sprintf(" repo:%s", repo)
147147
}
148148

149149
var searchResult struct {
150150
Items []struct {
151-
Number int `json:"number"`
152-
Title string `json:"title"`
153-
Body string `json:"body"`
154-
State string `json:"state"`
151+
Number int `json:"number"`
152+
Title string `json:"title"`
153+
Body string `json:"body"`
154+
State string `json:"state"`
155155
Repository struct {
156156
FullName string `json:"full_name"`
157157
} `json:"repository"`
@@ -184,19 +184,19 @@ func (c *Client) getIssues(username, repo string, startDate, endDate time.Time)
184184
var activities []types.GitHubActivity
185185

186186
// Search for issues created by user
187-
query := fmt.Sprintf("author:%s created:%s..%s",
187+
query := fmt.Sprintf("author:%s created:%s..%s",
188188
username, startDate.Format("2006-01-02"), endDate.Format("2006-01-02"))
189-
189+
190190
if repo != "" {
191191
query += fmt.Sprintf(" repo:%s", repo)
192192
}
193193

194194
var searchResult struct {
195195
Items []struct {
196-
Number int `json:"number"`
197-
Title string `json:"title"`
198-
Body string `json:"body"`
199-
State string `json:"state"`
196+
Number int `json:"number"`
197+
Title string `json:"title"`
198+
Body string `json:"body"`
199+
State string `json:"state"`
200200
Repository struct {
201201
FullName string `json:"full_name"`
202202
} `json:"repository"`
@@ -229,13 +229,13 @@ func (c *Client) getReviews(username string, startDate, endDate time.Time) ([]ty
229229
var activities []types.GitHubActivity
230230

231231
// Search for pull requests reviewed by user
232-
query := fmt.Sprintf("reviewed-by:%s created:%s..%s",
232+
query := fmt.Sprintf("reviewed-by:%s created:%s..%s",
233233
username, startDate.Format("2006-01-02"), endDate.Format("2006-01-02"))
234234

235235
var searchResult struct {
236236
Items []struct {
237-
Number int `json:"number"`
238-
Title string `json:"title"`
237+
Number int `json:"number"`
238+
Title string `json:"title"`
239239
Repository struct {
240240
FullName string `json:"full_name"`
241241
} `json:"repository"`

internal/llm/client.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@ import (
66
"fmt"
77
"io"
88
"net/http"
9-
"os"
109
"strings"
1110
"time"
1211

12+
"github.com/cli/go-gh/v2/pkg/auth"
1313
"github.com/gh-standup/internal/types"
1414
)
1515

1616
type Request struct {
17-
Messages []Message `json:"messages"`
18-
Model string `json:"model"`
19-
Temperature float64 `json:"temperature"`
20-
TopP float64 `json:"top_p"`
21-
Stream bool `json:"stream"`
17+
Messages []Message `json:"messages"`
18+
Model string `json:"model"`
19+
Temperature float64 `json:"temperature"`
20+
TopP float64 `json:"top_p"`
21+
Stream bool `json:"stream"`
2222
}
2323

2424
type Message struct {
@@ -40,10 +40,13 @@ type Client struct {
4040

4141
func NewClient() (*Client, error) {
4242
fmt.Print(" Checking GitHub token... ")
43-
token := os.Getenv("GITHUB_TOKEN")
43+
44+
host, _ := auth.DefaultHost()
45+
token, _ := auth.TokenForHost(host) // check GH_TOKEN, GITHUB_TOKEN, keychain, etc
46+
4447
if token == "" {
4548
fmt.Println("Failed")
46-
return nil, fmt.Errorf("GITHUB_TOKEN environment variable is not set")
49+
return nil, fmt.Errorf("No GitHub token found. Please run 'gh auth login' to authenticate.")
4750
}
4851
fmt.Println("Done")
4952

@@ -109,7 +112,7 @@ func (c *Client) formatActivitiesForLLM(activities []types.GitHubActivity) strin
109112
}
110113

111114
var builder strings.Builder
112-
115+
113116
commits := make([]types.GitHubActivity, 0)
114117
prs := make([]types.GitHubActivity, 0)
115118
issues := make([]types.GitHubActivity, 0)

0 commit comments

Comments
 (0)