Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ require (
github.com/klauspost/cpuid/v2 v2.2.4 // indirect
github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 // indirect
github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0 // indirect
github.com/larksuite/project-oapi-sdk-golang v1.0.15 // indirect
github.com/leodido/go-urn v1.2.4 // indirect
github.com/lib/pq v1.10.9 // indirect
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,8 @@ github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0 h1:P6pPBnrTSX3DEVR4fDembhR
github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0/go.mod h1:vmVJ0l/dxyfGW6FmdpVm2joNMFikkuWg0EoCKLGUMNw=
github.com/larksuite/oapi-sdk-go/v3 v3.4.20 h1:Ul1NWAHXYzbXBHFmUxMTSZ9v2ahy/O8EthYOQnLvPo0=
github.com/larksuite/oapi-sdk-go/v3 v3.4.20/go.mod h1:ZEplY+kwuIrj/nqw5uSCINNATcH3KdxSN7y+UxYY5fI=
github.com/larksuite/project-oapi-sdk-golang v1.0.15 h1:5GqWotqVDTWk3Sg+YjTtaocRx/0dHQabU6F2Qd7MUSk=
github.com/larksuite/project-oapi-sdk-golang v1.0.15/go.mod h1:M4gZ6QA4sa6U9iukFsSVQ58LQwlWO8eqk13nArHRHCk=
github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY=
github.com/leodido/go-urn v1.2.4 h1:XlAE/cm/ms7TE/VMVoduSpNBoyc2dOxHs5MZSwAN63Q=
github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4=
Expand Down
11 changes: 11 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,3 +295,14 @@ func RedisPassword() string {
func RedisCommonCacheTokenDB() int {
return viper.GetInt(setting.ENVRedisCommonCacheDB)
}

func LarkPluginID() string {
return viper.GetString(setting.ENVLarkPluginID)
}

func LarkPluginSecret() string {
return viper.GetString(setting.ENVLarkPluginSecret)
}
func LarkPluginAccessTokenType() int {
return viper.GetInt(setting.ENVLarkPluginAccessTokenType)
}
4 changes: 4 additions & 0 deletions pkg/microservice/aslan/core/common/repository/models/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,10 @@ type ServiceWithModule struct {
ServiceModule string `bson:"service_module" json:"service_module" yaml:"service_module"`
}

func (s *ServiceWithModule) GetKey() string {
return s.ServiceName + "-" + s.ServiceModule
}

type ServiceModuleTargetBase struct {
ProductName string `json:"product_name"`
ServiceWithModule `json:",inline"`
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
Copyright 2025 The KodeRover Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package models

import (
"go.mongodb.org/mongo-driver/bson/primitive"
)

type LarkPluginAuthConfig struct {
ID primitive.ObjectID `bson:"_id,omitempty" json:"id,omitempty"`
WorkspaceID string `bson:"workspace_id" json:"workspace_id"`
ZadigAddress string `bson:"zadig_address" json:"zadig_address"`
ApiToken string `bson:"api_token" json:"api_token"`
UpdateTime int64 `bson:"update_time" json:"update_time"`
}

func (LarkPluginAuthConfig) TableName() string {
return "lark_plugin_auth_config"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
Copyright 2025 The KodeRover Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package models

import (
"go.mongodb.org/mongo-driver/bson/primitive"
)

type LarkPluginWorkflowConfig struct {
ID primitive.ObjectID `bson:"_id,omitempty" json:"id,omitempty"`
WorkspaceID string `bson:"workspace_id" json:"workspace_id"`
WorkItemTypeKey string `bson:"work_item_type_key" json:"work_item_type_key"`
Nodes []*LarkPluginWorkflowConfigNode `bson:"nodes" json:"nodes"`
UpdateTime int64 `bson:"update_time" json:"update_time"`
}

type LarkPluginWorkflowConfigNode struct {
TemplateID int64 `bson:"template_id" json:"template_id"`
TemplateName string `bson:"template_name" json:"template_name"`
NodeID string `bson:"node_id" json:"node_id"`
NodeName string `bson:"node_name" json:"node_name"`
ProjectKey string `bson:"project_key" json:"project_key"`
WorkflowName string `bson:"workflow_name" json:"workflow_name"`
}

func (LarkPluginWorkflowConfig) TableName() string {
return "lark_plugin_workflow_config"
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ type WorkflowTask struct {
Hash string `bson:"hash" json:"hash"`
ApprovalTicketID string `bson:"approval_ticket_id" json:"approval_ticket_id"`
ApprovalID string `bson:"approval_id" json:"approval_id"`

LarkWorkItemTypeKey string `bson:"lark_workitem_type_key" json:"lark_workitem_type_key"`
LarkWorkItemID string `bson:"lark_workitem_id" json:"lark_workitem_id"`
}

func (WorkflowTask) TableName() string {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
Copyright 2024 The KodeRover Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package mongodb

import (
"context"

"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"

"github.com/koderover/zadig/v2/pkg/microservice/aslan/config"
"github.com/koderover/zadig/v2/pkg/microservice/aslan/core/common/repository/models"
mongotool "github.com/koderover/zadig/v2/pkg/tool/mongo"
)

type LarkPluginAuthConfigColl struct {
*mongo.Collection

coll string
}

func NewLarkPluginAuthConfigColl() *LarkPluginAuthConfigColl {
name := models.LarkPluginAuthConfig{}.TableName()
return &LarkPluginAuthConfigColl{Collection: mongotool.Database(config.MongoDatabase()).Collection(name), coll: name}
}

func (c *LarkPluginAuthConfigColl) GetCollectionName() string {
return c.coll
}

func (c *LarkPluginAuthConfigColl) EnsureIndex(ctx context.Context) error {
mod := []mongo.IndexModel{
{
Keys: bson.D{
bson.E{Key: "workspace_id", Value: 1},
},
Options: options.Index().SetUnique(true),
},
}

_, err := c.Indexes().CreateMany(ctx, mod)

return err
}

func (c *LarkPluginAuthConfigColl) Get(workspaceID string) (*models.LarkPluginAuthConfig, error) {
resp := new(models.LarkPluginAuthConfig)
cursor, err := c.Collection.Find(context.TODO(), bson.M{"workspace_id": workspaceID})
if err != nil {
return nil, err
}

err = cursor.All(context.TODO(), &resp)
if err != nil {
return nil, err
}

return resp, nil
}

func (c *LarkPluginAuthConfigColl) Update(config *models.LarkPluginAuthConfig) error {
if config == nil {
return nil
}

query := bson.M{"workspace_id": config.WorkspaceID}
opts := options.Replace().SetUpsert(true)
_, err := c.ReplaceOne(context.TODO(), query, config, opts)

return err
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/*
Copyright 2024 The KodeRover Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package mongodb

import (
"context"
"time"

"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"

"github.com/koderover/zadig/v2/pkg/microservice/aslan/config"
"github.com/koderover/zadig/v2/pkg/microservice/aslan/core/common/repository/models"
mongotool "github.com/koderover/zadig/v2/pkg/tool/mongo"
)

type LarkPluginWorkflowConfigColl struct {
*mongo.Collection

coll string
}

func NewLarkPluginWorkflowConfigColl() *LarkPluginWorkflowConfigColl {
name := models.LarkPluginWorkflowConfig{}.TableName()
return &LarkPluginWorkflowConfigColl{Collection: mongotool.Database(config.MongoDatabase()).Collection(name), coll: name}
}

func (c *LarkPluginWorkflowConfigColl) GetCollectionName() string {
return c.coll
}

func (c *LarkPluginWorkflowConfigColl) EnsureIndex(ctx context.Context) error {
mod := []mongo.IndexModel{
{
Keys: bson.D{
bson.E{Key: "workspace_id", Value: 1},
bson.E{Key: "work_item_type_key", Value: 1},
},
Options: options.Index().SetUnique(true),
},
}

_, err := c.Indexes().CreateMany(ctx, mod)

return err
}

func (c *LarkPluginWorkflowConfigColl) Get(workspaceID string) ([]*models.LarkPluginWorkflowConfig, error) {
resp := make([]*models.LarkPluginWorkflowConfig, 0)
cursor, err := c.Collection.Find(context.TODO(), bson.M{"workspace_id": workspaceID})
if err != nil {
return nil, err
}

err = cursor.All(context.TODO(), &resp)
if err != nil {
return nil, err
}

return resp, nil
}

func (c *LarkPluginWorkflowConfigColl) GetWorkItemTypeConfig(workspaceID, workItemType string) (*models.LarkPluginWorkflowConfig, error) {
resp := new(models.LarkPluginWorkflowConfig)

query := bson.M{"workspace_id": workspaceID, "work_item_type_key": workItemType}
err := c.Collection.FindOne(context.TODO(), query).Decode(resp)
if err != nil {
return nil, err
}

return resp, nil
}

func (c *LarkPluginWorkflowConfigColl) Update(configs []*models.LarkPluginWorkflowConfig) error {
if len(configs) == 0 {
return nil
}

// 构建批量操作
operations := make([]mongo.WriteModel, 0, len(configs))
for _, config := range configs {
config.UpdateTime = time.Now().Unix()
// 使用 WorkspaceID 和 WorkItemType 作为唯一标识字段进行 upsert 操作
query := bson.M{"workspace_id": config.WorkspaceID, "work_item_type_key": config.WorkItemTypeKey}
operation := mongo.NewReplaceOneModel().
SetFilter(query).
SetReplacement(config).
SetUpsert(true)
operations = append(operations, operation)
}

// 执行批量操作
opts := options.BulkWrite().SetOrdered(false)
_, err := c.BulkWrite(context.TODO(), operations, opts)

return err
}

func (c *LarkPluginWorkflowConfigColl) Delete(workItemTypeKeys []string) error {
if len(workItemTypeKeys) == 0 {
return nil
}

query := bson.M{"work_item_type_key": bson.M{"$in": workItemTypeKeys}}
_, err := c.DeleteMany(context.TODO(), query)
return err
}
Loading