Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
abing258 committed Apr 7, 2024
2 parents 5d5e321 + cf14553 commit ea1667c
Show file tree
Hide file tree
Showing 31 changed files with 573 additions and 53 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,4 @@ pipeline2.yml
/pipeline3.yml
/pkg/service/arrange_test.go
pkg/service/bnb_test.go
/hamster-test-private-key.pem
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
FROM docker.io/hamstershare/debian_docker_cli:20231010
RUN npm install -g truffle
FROM docker.io/hamstershare/debian_docker_cli:20240308

COPY ./aline-test /usr/local/bin/aline-test
COPY ./aline-test /usr/local/bin/aline-test

ENV PORT=8080
ENV GRPC_PORT=50001
ENV DB_USER=root
ENV DB_PASSWORD=123456
ENV DB_HOST=127.0.0.1
ENV DB_PORT=3306
ENV REDIS_HOST=redis
ENV DB_NAME=aline
EXPOSE ${PORT}
EXPOSE ${GRPC_PORT}
Expand Down
2 changes: 2 additions & 0 deletions Dockerfile_base
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,5 @@ RUN "$HOME/.cargo/bin/rustup" default stable && \
"$HOME/.cargo/bin/rustup" update nightly && \
"$HOME/.cargo/bin/rustup" target add wasm32-unknown-unknown --toolchain nightly


RUN npm install -g truffle
24 changes: 23 additions & 1 deletion cmd/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/hamster-shared/hamster-develop/pkg/application"
"github.com/hamster-shared/hamster-develop/pkg/controller"
"github.com/hamster-shared/hamster-develop/pkg/service"
"github.com/redis/go-redis/v9"
"github.com/spf13/cobra"
"gorm.io/driver/mysql"
"gorm.io/gorm"
Expand Down Expand Up @@ -58,7 +59,28 @@ to quickly create a Cobra application.`,
if err != nil {
return
}

application.SetBean[*gorm.DB]("db", db)
redisHost := os.Getenv("REDIS_HOST")
if redisHost == "" {
redisHost = "127.0.0.1"
}
redisPort := os.Getenv("REDIS_PORT")
if redisPort == "" {
redisPort = "6379"
}

fmt.Println(redisHost)
redisAddr := fmt.Sprintf("%s:%s", redisHost, redisPort)

fmt.Println("redis addr : ", redisAddr)

rdb := redis.NewClient(&redis.Options{
Addr: redisAddr,
Password: "", // no password set
DB: 0, // use default DB
})
application.SetBean[*redis.Client]("rdb", rdb)
application.SetBean[engine.Engine]("engine", Engine)
workflowService := service.NewWorkflowService()
application.SetBean[*service.WorkflowService]("workflowService", workflowService)
Expand All @@ -83,7 +105,7 @@ to quickly create a Cobra application.`,
icpService := service.NewIcpService(icNetwork)
application.SetBean[*service.IcpService]("icpService", icpService)
templateService.Init(db)
projectService.Init(db)
projectService.Init(db, rdb)
application.SetBean[service.IProjectService]("projectService", projectService)
arrangeService := service.NewArrangeService()
application.SetBean[*service.ArrangeService]("arrangeService", arrangeService)
Expand Down
8 changes: 8 additions & 0 deletions deploy-master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,14 @@ spec:
key: APPS_RW_CLIENT_SECRETS
- name: GITHUB_APP_RW_PEM
value: "/home/ubuntu/rwGithubApp/hamster-rw-private-key.pem"
- name: REDIS_HOST
value: redis
- name: REDIS_PORT
value: "6379"
- name: GITHUB_BRANCH_WEBHOOK_NAME
value: hamster_test_webhook
- name: GITHUB_BRANCH_WEBHOOK_URL
value: https://develop.hamster.newtouch.com/api/v2/github/webhook
ports:
- containerPort: 8080
volumeMounts:
Expand Down
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ require (
github.com/jinzhu/copier v0.3.5
github.com/mohaijiang/agent-go v0.3.1
github.com/pkg/errors v0.9.1
github.com/redis/go-redis/v9 v9.5.1
github.com/samber/lo v1.36.0
github.com/sirupsen/logrus v1.9.0
github.com/spf13/cobra v1.6.1
Expand All @@ -45,11 +46,13 @@ require (
github.com/aviate-labs/secp256k1 v0.0.0-5e6736a // indirect
github.com/benbjohnson/clock v1.3.0 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.2.0 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/cloudflare/circl v1.3.3 // indirect
github.com/crackcomm/go-gitignore v0.0.0-20170627025303-887ab5e44cc3 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/deckarep/golang-set/v2 v2.1.0 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/di-wu/parser v0.3.0 // indirect
github.com/emicklei/go-restful/v3 v3.10.2 // indirect
github.com/evanphx/json-patch v5.6.0+incompatible // indirect
Expand Down
1 change: 1 addition & 0 deletions pkg/controller/gin.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ func (h *HttpServer) StartHttpServer() {
api.POST("/projects/code", h.handlerServer.createProjectByCodeV2)
api.GET("/projects/:id", h.handlerServer.projectDetail)
api.PUT("/projects/:id", h.handlerServer.updateProject)
api.PUT("/projects/:id/branch", h.handlerServer.setProjectRepositoryBranch) // 查询项目分支信息
api.DELETE("projects/:id", h.handlerServer.deleteProject)
api.POST("/projects/check-name", h.handlerServer.checkName)
api.GET("/user", h.handlerServer.getUseInfo)
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/log_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func (h *HandlerServer) getDeployFrontendLog(gin *gin.Context) {
//userAny, _ := gin.Get("user")
//user, _ := userAny.(db2.User)

project, err := h.projectService.GetProject(projectIdStr)
project, err := h.projectService.GetProject(projectIdStr, 0)
if err != nil {
log.Println("get project failed", err.Error())
Fail(err.Error(), gin)
Expand Down
54 changes: 52 additions & 2 deletions pkg/controller/login_handler.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
package controller

import (
"context"
"encoding/json"
"fmt"
"github.com/gin-gonic/gin"
"github.com/golang-jwt/jwt/v4"
"github.com/google/go-github/v48/github"
"github.com/hamster-shared/aline-engine/logger"
"github.com/hamster-shared/hamster-develop/pkg/application"
"github.com/hamster-shared/hamster-develop/pkg/consts"
db2 "github.com/hamster-shared/hamster-develop/pkg/db"
"github.com/hamster-shared/hamster-develop/pkg/parameter"
"github.com/hamster-shared/hamster-develop/pkg/service"
"github.com/hamster-shared/hamster-develop/pkg/utils"
"github.com/redis/go-redis/v9"
"gorm.io/gorm"
"log"
"net/http"
Expand Down Expand Up @@ -132,13 +136,25 @@ func (h *HandlerServer) githubWebHook(gin *gin.Context) {
func (h *HandlerServer) githubWebHookV2(gin *gin.Context) {
event := gin.GetHeader("X-GitHub-Event")
githubService := application.GetBean[*service.GithubService]("githubService")
var githubInstall parameter.GithubWebHookInstall
err := gin.BindJSON(&githubInstall)
rdb := application.GetBean[*redis.Client]("rdb")

bytes, err := gin.GetRawData()

logger.Info("event name: ", event)
logger.Info("github webhook: ", string(bytes))

//err := gin.BindJSON(&githubInstall)
if err != nil {
Fail(err.Error(), gin)
return
}
if event == "installation" {
var githubInstall parameter.GithubWebHookInstall
err = json.Unmarshal(bytes, &githubInstall)
if err != nil {
Fail(err.Error(), gin)
return
}
if githubInstall.Action == "created" {
githubService.HandleAppsInstall(githubInstall, consts.SAVE_INSTALL, "GITHUB_APP_ID", "GITHUB_APP_PEM")
err = githubService.HandlerInstallData(githubInstall.Installation.GetID(), githubInstall.Installation.GetAppID(), consts.INSTALLATION_CREATED)
Expand All @@ -160,6 +176,12 @@ func (h *HandlerServer) githubWebHookV2(gin *gin.Context) {
}
}
if event == "installation_repositories" {
var githubInstall parameter.GithubWebHookInstall
err = json.Unmarshal(bytes, &githubInstall)
if err != nil {
Fail(err.Error(), gin)
return
}
githubService.UpdateRepositorySelection(githubInstall.Installation.GetID(), githubInstall.Installation.GetRepositorySelection())
if githubInstall.Action == "added" {
//err = githubService.HandlerInstallData(githubInstall.Installation.GetID(), consts.REPO_ADDED)
Expand All @@ -179,6 +201,33 @@ func (h *HandlerServer) githubWebHookV2(gin *gin.Context) {
}
}
}
if event == "create" {
var createEvent github.CreateEvent
err = json.Unmarshal(bytes, &createEvent)
if err != nil {
Fail(err.Error(), gin)
return
}
if createEvent.GetRefType() == "branch" {
key := fmt.Sprintf("PROJECT_BRANCH:https://github.com/%s.git", createEvent.GetRepo().GetFullName())
ctx, _ := context.WithTimeout(context.Background(), time.Second*10)
_, err = rdb.RPush(ctx, key, createEvent.GetRef()).Result()
}
}
if event == "delete" {
var deleteEvent github.DeleteEvent
err = json.Unmarshal(bytes, &deleteEvent)
if err != nil {
Fail(err.Error(), gin)
return
}
if deleteEvent.GetRefType() == "branch" {
key := fmt.Sprintf("PROJECT_BRANCH:https://github.com/%s.git", deleteEvent.GetRepo().GetFullName())
ctx, _ := context.WithTimeout(context.Background(), time.Second*10)
_, err = rdb.LRem(ctx, key, 0, deleteEvent.GetRef()).Result()
}
}

}

func (h *HandlerServer) githubWebHookRw(gin *gin.Context) {
Expand Down Expand Up @@ -384,6 +433,7 @@ func (h *HandlerServer) JwtAuthorize() gin.HandlerFunc {
gin.Abort()
return
}

githubToken = user.Token
gin.Set("user", user)
gin.Set("userId", user.Id)
Expand Down
Loading

0 comments on commit ea1667c

Please sign in to comment.