From e50b8bd8f1656d56dfdcffc54649220cf799a1f1 Mon Sep 17 00:00:00 2001 From: Xinwei Xiong <86140903+cubxxw@users.noreply.github.com> Date: Mon, 3 Jul 2023 12:16:34 +0800 Subject: [PATCH 1/2] feat: adding actions (#461) --- .github/sync.yml | 26 +++++------ .github/workflows/e2e-test.yml | 1 - .github/workflows/link-pr.yml | 78 ++++++++++++++------------------ .github/workflows/opencommit.yml | 5 +- Makefile | 6 --- scripts/make-rules/golang.mk | 2 +- 6 files changed, 50 insertions(+), 68 deletions(-) diff --git a/.github/sync.yml b/.github/sync.yml index f543b2d39..859096c6f 100644 --- a/.github/sync.yml +++ b/.github/sync.yml @@ -6,12 +6,6 @@ OpenIMSDK/.github: - source: scripts/LICENSE/ dest: scripts/LICENSE/ replace: false - - source: .github/ - dest: .github/ - replace: false - exclude: | - workflows/ - sync.yml OpenIMSDK/community: - source: LICENSE @@ -21,14 +15,6 @@ OpenIMSDK/community: replace: false - source: .github/workflows/ dest: .github/workflows/ - exclude: - - e2e-test.yml - - sync.yml - - source: .github/ - dest: .github/ - replace: false - exclude: | - sync.yml OpenIMSDK/openim-sdk-core: - source: LICENSE @@ -53,6 +39,18 @@ OpenIMSDK/OpenIM-Docs: dest: scripts/githooks/ replace: true +OpenIMSDK/OpenKF: + - source: LICENSE + dest: LICENSE + - source: scripts/LICENSE/ + dest: scripts/LICENSE/ + replace: false + - source: .github/workflows/issue-robot.yml + dest: .github/workflows/issue-robot.yml + replace: false + - source: .github/workflows/stale.yml + dest: .github/workflows/stale.yml + replace: false group: # first group:common to all warehouses diff --git a/.github/workflows/e2e-test.yml b/.github/workflows/e2e-test.yml index 4e768b56d..e69de29bb 100644 --- a/.github/workflows/e2e-test.yml +++ b/.github/workflows/e2e-test.yml @@ -1 +0,0 @@ -# \ No newline at end of file diff --git a/.github/workflows/link-pr.yml b/.github/workflows/link-pr.yml index 844dd5fde..a3e0ee2de 100644 --- a/.github/workflows/link-pr.yml +++ b/.github/workflows/link-pr.yml @@ -1,47 +1,39 @@ -# name: Github Rebot for Link check error +name: Github Rebot for Link check error -# on: -# pull_request: -# branches: [ main ] -# paths: -# - '**.md' -# - 'docs/**' -# - '.lycheeignore' -# push: -# branches: [ main ] - -# schedule: -# - cron: '0 11 * * *' +# Every Monday at 12:30 p.m +on: + schedule: + - cron: '30 12 * * 1' -# jobs: -# linkChecker: -# runs-on: ubuntu-latest -# steps: -# - uses: actions/checkout@v3 +jobs: + linkChecker: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 -# - name: Link Checker -# id: lychee -# uses: lycheeverse/lychee-action@v1.7.0 -# with: -# # For parameter description, see https://github.com/lycheeverse/lychee#commandline-parameters -# # Actions Link address -> https://github.com/lycheeverse/lychee-action -# # -E, --exclude-all-private Exclude all private IPs from checking. -# # -i, --insecure Proceed for server connections considered insecure (invalid TLS) -# # -n, --no-progress Do not show progress bar. -# # -t, --timeout Website timeout in seconds from connect to response finished [default:20] -# # --max-concurrency Maximum number of concurrent network requests [default: 128] -# # -a --accept Comma-separated list of accepted status codes for valid links -# # docs/.vitepress/dist the site directory to check -# # ./*.md all markdown files in the root directory -# args: --verbose -E -i --no-progress --exclude-path './CHANGELOG' './**/*.md' -# env: -# GITHUB_TOKEN: ${{secrets.GH_PAT}} + - name: Link Checker + id: lychee + uses: lycheeverse/lychee-action@v1.7.0 + with: + # For parameter description, see https://github.com/lycheeverse/lychee#commandline-parameters + # Actions Link address -> https://github.com/lycheeverse/lychee-action + # -E, --exclude-all-private Exclude all private IPs from checking. + # -i, --insecure Proceed for server connections considered insecure (invalid TLS) + # -n, --no-progress Do not show progress bar. + # -t, --timeout Website timeout in seconds from connect to response finished [default:20] + # --max-concurrency Maximum number of concurrent network requests [default: 128] + # -a --accept Comma-separated list of accepted status codes for valid links + # docs/.vitepress/dist the site directory to check + # ./*.md all markdown files in the root directory + args: --verbose -E -i --no-progress --exclude-path './CHANGELOG' './**/*.md' + env: + GITHUB_TOKEN: ${{secrets.GH_PAT}} -# - name: Create Issue From File -# if: env.lychee_exit_code != 0 -# uses: peter-evans/create-issue-from-file@v4 -# with: -# title: Bug reports for links in OpenIM docs -# content-filepath: ./lychee/out.md -# labels: kind/documentation, triage/unresolved, report -# token: ${{ secrets.BOT_GITHUB_TOKEN }} + - name: Create Issue From File + if: env.lychee_exit_code != 0 + uses: peter-evans/create-issue-from-file@v4 + with: + title: Bug reports for links in OpenIM docs + content-filepath: ./lychee/out.md + labels: kind/documentation, triage/unresolved, report + token: ${{ secrets.BOT_GITHUB_TOKEN }} diff --git a/.github/workflows/opencommit.yml b/.github/workflows/opencommit.yml index d3d52508d..80fc9e302 100644 --- a/.github/workflows/opencommit.yml +++ b/.github/workflows/opencommit.yml @@ -2,9 +2,8 @@ name: 'OpenCommit Action' on: push: - # this list of branches is often enough, - # but you may still ignore other public branches - branches-ignore: [main master dev development release] + branches: + - main jobs: opencommit: diff --git a/Makefile b/Makefile index 5d7ac6bd3..2dd10fdbd 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,3 @@ - -# TODO: 参考我对 horizon 的 Makefile 设计: -# TODO: https://github.com/horizoncd/horizon/pull/141 -# TODO: 设计稿:代写~ -# TODO:请在 issue 关闭之前不要使用 Makefile 中的 targe(尤其是重构前) - # ============================================================================== # define the default goal # diff --git a/scripts/make-rules/golang.mk b/scripts/make-rules/golang.mk index 336fead4a..1b70f09da 100644 --- a/scripts/make-rules/golang.mk +++ b/scripts/make-rules/golang.mk @@ -17,7 +17,7 @@ # GO := go -GO_SUPPORTED_VERSIONS ?= |1.15|1.16|1.17|1.18|1.19|1.20| +GO_SUPPORTED_VERSIONS ?= 1.18|1.19|1.20 GO_LDFLAGS += -X $(VERSION_PACKAGE).gitVersion=$(GIT_TAG) \ -X $(VERSION_PACKAGE).gitCommit=$(GIT_COMMIT) \ From 941c1f954e88187e630465beef11cc3865597265 Mon Sep 17 00:00:00 2001 From: WangchuXiao Date: Mon, 3 Jul 2023 15:21:17 +0800 Subject: [PATCH 2/2] V3dev (#463) * statistics user register * refactor: router change * minio init --------- Co-authored-by: withchao <993506633@qq.com> Co-authored-by: Gordon <1432970085@qq.com> --- internal/api/route.go | 17 +++++++------- pkg/common/db/obj/minio.go | 34 ++++++++++++++++------------ pkg/common/db/relation/user_model.go | 6 ++--- 3 files changed, 32 insertions(+), 25 deletions(-) diff --git a/internal/api/route.go b/internal/api/route.go index 84df97bb0..fb8c2d9a0 100644 --- a/internal/api/route.go +++ b/internal/api/route.go @@ -34,15 +34,16 @@ func NewGinRouter(discov discoveryregistry.SvcDiscoveryRegistry, rdb redis.Unive r.GET("/metrics", prome.PrometheusHandler()) } ParseToken := mw.GinParseToken(rdb) - userRouterGroup := r.Group("/user", ParseToken) + userRouterGroup := r.Group("/user") { - userRouterGroup.POST("/update_user_info", u.UpdateUserInfo) - userRouterGroup.POST("/set_global_msg_recv_opt", u.SetGlobalRecvMessageOpt) - userRouterGroup.POST("/get_users_info", u.GetUsersPublicInfo) - userRouterGroup.POST("/get_all_users_uid", u.GetAllUsersID) - userRouterGroup.POST("/account_check", u.AccountCheck) - userRouterGroup.POST("/get_users", u.GetUsers) - userRouterGroup.POST("/get_users_online_status", u.GetUsersOnlineStatus) + userRouterGroup.POST("/user_register", u.UserRegister) + userRouterGroup.POST("/update_user_info", ParseToken, u.UpdateUserInfo) + userRouterGroup.POST("/set_global_msg_recv_opt", ParseToken, u.SetGlobalRecvMessageOpt) + userRouterGroup.POST("/get_users_info", ParseToken, u.GetUsersPublicInfo) + userRouterGroup.POST("/get_all_users_uid", ParseToken, u.GetAllUsersID) + userRouterGroup.POST("/account_check", ParseToken, u.AccountCheck) + userRouterGroup.POST("/get_users", ParseToken, u.GetUsers) + userRouterGroup.POST("/get_users_online_status", ParseToken, u.GetUsersOnlineStatus) } //friend routing group friendRouterGroup := r.Group("/friend", ParseToken) diff --git a/pkg/common/db/obj/minio.go b/pkg/common/db/obj/minio.go index d8d9ff70e..8e28896bd 100644 --- a/pkg/common/db/obj/minio.go +++ b/pkg/common/db/obj/minio.go @@ -33,21 +33,27 @@ func NewMinioInterface() (Interface, error) { } ctx, cancel := context.WithTimeout(context.Background(), time.Second*20) defer cancel() - for _, bucket := range utils.Distinct([]string{conf.TempBucket, conf.DataBucket}) { - exists, err := client.BucketExists(ctx, bucket) - if err != nil { - return nil, fmt.Errorf("minio bucket %s exists %w", bucket, err) - } - if exists { - continue - } - opt := minio.MakeBucketOptions{ - Region: conf.Location, - ObjectLocking: conf.IsDistributedMod, - } - if err := client.MakeBucket(ctx, bucket, opt); err != nil { - return nil, fmt.Errorf("minio make bucket %s %w", bucket, err) + initBucket := func(ctx context.Context) error { + for _, bucket := range utils.Distinct([]string{conf.TempBucket, conf.DataBucket}) { + exists, err := client.BucketExists(ctx, bucket) + if err != nil { + return fmt.Errorf("minio bucket %s exists %w", bucket, err) + } + if exists { + continue + } + opt := minio.MakeBucketOptions{ + Region: conf.Location, + ObjectLocking: conf.IsDistributedMod, + } + if err := client.MakeBucket(ctx, bucket, opt); err != nil { + return fmt.Errorf("minio make bucket %s %w", bucket, err) + } } + return nil + } + if err := initBucket(ctx); err != nil { + fmt.Println("minio init error:", err) } return &minioImpl{ client: client, diff --git a/pkg/common/db/relation/user_model.go b/pkg/common/db/relation/user_model.go index 385e65809..3390f7d3b 100644 --- a/pkg/common/db/relation/user_model.go +++ b/pkg/common/db/relation/user_model.go @@ -74,8 +74,8 @@ func (u *UserGorm) CountTotal(ctx context.Context) (count int64, err error) { func (u *UserGorm) CountRangeEverydayTotal(ctx context.Context, start time.Time, end time.Time) (map[string]int64, error) { var res []struct { - Date string `gorm:"column:date"` - Count int64 `gorm:"column:count"` + Date time.Time `gorm:"column:date"` + Count int64 `gorm:"column:count"` } err := u.db(ctx).Model(&relation.UserModel{}).Select("DATE(create_time) AS date, count(1) AS count").Where("create_time >= ? and create_time < ?", start, end).Group("date").Find(&res).Error if err != nil { @@ -83,7 +83,7 @@ func (u *UserGorm) CountRangeEverydayTotal(ctx context.Context, start time.Time, } v := make(map[string]int64) for _, r := range res { - v[r.Date] = r.Count + v[r.Date.Format("2006-01-02")] = r.Count } return v, nil }