Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
justlorain committed Mar 30, 2024
1 parent 3d11292 commit ae4164e
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 43 deletions.
19 changes: 10 additions & 9 deletions api/api.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
package api

import (
"fmt"
"context"
"github.com/B1NARY-GR0UP/openalysis/client/graphql"
"github.com/B1NARY-GR0UP/openalysis/client/rest"
"github.com/B1NARY-GR0UP/openalysis/config"
"github.com/B1NARY-GR0UP/openalysis/cron"
"github.com/B1NARY-GR0UP/openalysis/storage"
)

// TODO: main 应该只负责 oa 的初始化以及使用,不负责数据库初始化,配置文件读取等
// TODO: 配置文件读取,数据库读取,开始服务器等都应该在 api 层提供
// TODO: AddGroups SetDataSource SetBackend SetCron SetToken

func Start(path string) {
func Start(ctx context.Context, path string) {
Init(path)
// TODO
cron.Start(ctx)
}

func Restart(ctx context.Context, path string) {
Init(path)
cron.Restart(ctx)
}

func Init(path string) {
Expand All @@ -23,7 +28,3 @@ func Init(path string) {
graphql.Init()
rest.Init()
}

func AddGroups(groups ...config.Group) {
fmt.Println(groups)
}
38 changes: 13 additions & 25 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,20 @@ import (
"github.com/spf13/cobra"
)

const name = "oa"

// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: name,
Short: "A brief description of your application",
Long: `A longer description that spans multiple lines and likely contains
examples and usage of using your application. For example:
Cobra is a CLI library for Go that empowers applications.
This application is a tool to generate the needed files
to quickly create a Cobra application.`,
// Uncomment the following line if your bare application
// has an action associated with it:
// Run: func(cmd *cobra.Command, args []string) { },
Use: CMD,
Short: "OPEN ANALYSIS SERVICE",
Long: `
██████╗ ██████╗ ███████╗███╗ ██╗ █████╗ ██╗ ██╗ ██╗███████╗██╗███████╗
██╔═══██╗██╔══██╗██╔════╝████╗ ██║██╔══██╗██║ ╚██╗ ██╔╝██╔════╝██║██╔════╝
██║ ██║██████╔╝█████╗ ██╔██╗ ██║███████║██║ ╚████╔╝ ███████╗██║███████╗
██║ ██║██╔═══╝ ██╔══╝ ██║╚██╗██║██╔══██║██║ ╚██╔╝ ╚════██║██║╚════██║
╚██████╔╝██║ ███████╗██║ ╚████║██║ ██║███████╗██║ ███████║██║███████║
╚═════╝ ╚═╝ ╚══════╝╚═╝ ╚═══╝╚═╝ ╚═╝╚══════╝╚═╝ ╚══════╝╚═╝╚══════╝
`,
Version: Version,
}

// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
err := rootCmd.Execute()
if err != nil {
Expand All @@ -33,13 +28,6 @@ func Execute() {
}

func init() {
// Here you will define your flags and configuration settings.
// Cobra supports persistent flags, which, if defined here,
// will be global for your application.

// rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.openalysis.yaml)")

// Cobra also supports local flags, which will only run
// when this action is called directly.
rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
rootCmd.SetVersionTemplate("{{ .Version }}")
rootCmd.CompletionOptions.DisableDefaultCmd = true
}
7 changes: 7 additions & 0 deletions cmd/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package cmd

const (
Name = "openalysis"
CMD = "oa"
Version = "dev"
)
22 changes: 13 additions & 9 deletions cron/cron.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ import (
// TODO: add progress bar
// TODO: data cleaning e.g. ByteDance, bytedance, Bytedance => bytedance

// TODO: fix bug pr assignees deleted
// TODO: fix bug contributor logic
// TODO: fix bug counting logic 计算数量时应该只计算最新的,不应该计算旧的

func Start(ctx context.Context) {
slog.Info("openalysis service started")

Expand Down Expand Up @@ -360,7 +364,7 @@ type RepoData struct {
ContributorCount int
}

func FetchRepoData(ctx context.Context, rd *RepoData, lu time.Time, ec string) error {
func FetchRepoData(ctx context.Context, rd *RepoData, issueCursor time.Time, prCursor string) error {
g := new(errgroup.Group)
g.Go(func() error {
repo, err := graphql.QueryRepoInfo(ctx, rd.Owner, rd.Name)
Expand All @@ -370,23 +374,23 @@ func FetchRepoData(ctx context.Context, rd *RepoData, lu time.Time, ec string) e
return err
})
g.Go(func() error {
t := time.Time{}
if !lu.IsZero() {
t = lu
cursor := time.Time{}
if !issueCursor.IsZero() {
cursor = issueCursor
}
issues, lastUpdate, err := graphql.QueryIssueInfoByRepo(ctx, rd.Owner, rd.Name, t)
issues, lastUpdate, err := graphql.QueryIssueInfoByRepo(ctx, rd.Owner, rd.Name, cursor)
if err == nil {
rd.Issues = issues
rd.LastUpdate = lastUpdate
}
return err
})
g.Go(func() error {
c := ""
if ec != "" {
c = ec
cursor := ""
if prCursor != "" {
cursor = prCursor
}
prs, endCursor, err := graphql.QueryPRInfoByRepo(ctx, rd.Owner, rd.Name, c)
prs, endCursor, err := graphql.QueryPRInfoByRepo(ctx, rd.Owner, rd.Name, cursor)
if err == nil {
rd.PRs = prs
rd.EndCursor = endCursor
Expand Down
Empty file added template/example.json
Empty file.

0 comments on commit ae4164e

Please sign in to comment.