Skip to content

Commit 6a616d8

Browse files
committed
feat(credit-manager): add star information when requesting user information
1 parent d81c03c commit 6a616d8

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

cmd/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ var serveCmd = &cobra.Command{
132132

133133
syncStar := github.SyncStar(globalConfig.GithubConfig)
134134
syncStar.HTTPClient = initHTTPClient(nil)
135+
github.Owner, github.Repo = syncStar.Owner, syncStar.Repo
135136
go syncStar.StarSyncTimer(ctx)
136137

137138
go func() {

internal/handler/manger_handler.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ import (
99
"time"
1010

1111
"github.com/gin-gonic/gin"
12-
1312
"github.com/zgsm-ai/oidc-auth/internal/constants"
1413
"github.com/zgsm-ai/oidc-auth/internal/providers"
1514
"github.com/zgsm-ai/oidc-auth/internal/repository"
1615
"github.com/zgsm-ai/oidc-auth/internal/service"
16+
github "github.com/zgsm-ai/oidc-auth/internal/sync"
1717
"github.com/zgsm-ai/oidc-auth/pkg/response"
1818
"github.com/zgsm-ai/oidc-auth/pkg/utils"
1919
)
@@ -210,6 +210,7 @@ func (s *Server) bindAccountCallback(c *gin.Context) {
210210
return
211211
}
212212
url := providerInstance.GetEndpoint(false) + constants.BindAccountBindURI + "?state=" + parameterCarrier.TokenHash
213+
url = url + "&bind=true"
213214
c.Redirect(http.StatusFound, url)
214215
}
215216

@@ -232,6 +233,14 @@ func (s *Server) userInfoHandler(c *gin.Context) {
232233
return
233234
}
234235

236+
isStar := true
237+
starProject := user.GithubStar
238+
239+
project := fmt.Sprintf("%s.%s", github.Owner, github.Repo)
240+
if starProject == "" || starProject != project {
241+
isStar = false
242+
}
243+
235244
data := gin.H{
236245
"state": c.DefaultQuery("state", ""),
237246
"username": user.Name,
@@ -241,6 +250,7 @@ func (s *Server) userInfoHandler(c *gin.Context) {
241250
"githubID": user.GithubID,
242251
"githubName": user.GithubName,
243252
"isPrivate": s.IsPrivate,
253+
"isStar": isStar,
244254
}
245255

246256
response.JSONSuccess(c, "", data)

internal/sync/sync_star.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ type ProcessedStargazer struct {
4343
StarredAtUnix int64
4444
}
4545

46+
var (
47+
Owner string
48+
Repo string
49+
)
50+
4651
func (s *SyncStar) StarCount() (int, error) {
4752
starURL := fmt.Sprintf("%s/%s/%s", constants.GitHubStarBaseURL, s.Owner, s.Repo)
4853

0 commit comments

Comments
 (0)