Skip to content

Commit

Permalink
feat(db): add date relation fields to devops tables
Browse files Browse the repository at this point in the history
  • Loading branch information
d4x1 committed Nov 22, 2023
1 parent 7cc6c04 commit aa07ad9
Show file tree
Hide file tree
Showing 25 changed files with 327 additions and 190 deletions.
17 changes: 7 additions & 10 deletions backend/core/models/domainlayer/devops/cicd_deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,17 @@ package devops

import (
"github.com/apache/incubator-devlake/core/models/domainlayer"
"time"
)

type CICDDeployment struct {
domainlayer.DomainEntity
CicdScopeId string `gorm:"index;type:varchar(255)"`
Name string `gorm:"type:varchar(255)"`
Result string `gorm:"type:varchar(100)"`
Status string `gorm:"type:varchar(100)"`
Environment string `gorm:"type:varchar(255)"`
CreatedDate time.Time
StartedDate *time.Time
FinishedDate *time.Time
DurationSec *float64
CicdScopeId string `gorm:"index;type:varchar(255)"`
Name string `gorm:"type:varchar(255)"`
Result string `gorm:"type:varchar(100)"`
Status string `gorm:"type:varchar(100)"`
Environment string `gorm:"type:varchar(255)"`
ItemDateInfo
DurationSec *float64
}

func (CICDDeployment) TableName() string {
Expand Down
38 changes: 18 additions & 20 deletions backend/core/models/domainlayer/devops/cicd_deployment_commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,18 @@ limitations under the License.
package devops

import (
"time"

"github.com/apache/incubator-devlake/core/models/domainlayer"
)

type CicdDeploymentCommit struct {
domainlayer.DomainEntity
CicdScopeId string `gorm:"index;type:varchar(255)"`
CicdDeploymentId string `gorm:"type:varchar(255)"` // if it is converted from a cicd_pipeline_commit
Name string `gorm:"type:varchar(255)"`
Result string `gorm:"type:varchar(100)"`
Status string `gorm:"type:varchar(100)"`
Environment string `gorm:"type:varchar(255)"`
CreatedDate time.Time
StartedDate *time.Time
FinishedDate *time.Time
CicdScopeId string `gorm:"index;type:varchar(255)"`
CicdDeploymentId string `gorm:"type:varchar(255)"` // if it is converted from a cicd_pipeline_commit
Name string `gorm:"type:varchar(255)"`
Result string `gorm:"type:varchar(100)"`
Status string `gorm:"type:varchar(100)"`
Environment string `gorm:"type:varchar(255)"`
ItemDateInfo
DurationSec *float64
CommitSha string `gorm:"primaryKey;type:varchar(255)"`
RefName string `gorm:"type:varchar(255)"` // to delete?
Expand All @@ -52,14 +48,16 @@ func (cicdDeploymentCommit CicdDeploymentCommit) ToDeployment() *CICDDeployment
Id: cicdDeploymentCommit.CicdDeploymentId,
NoPKModel: cicdDeploymentCommit.DomainEntity.NoPKModel,
},
CicdScopeId: cicdDeploymentCommit.CicdScopeId,
Name: cicdDeploymentCommit.Name,
Result: cicdDeploymentCommit.Result,
Status: cicdDeploymentCommit.Status,
Environment: cicdDeploymentCommit.Environment,
CreatedDate: cicdDeploymentCommit.CreatedDate,
StartedDate: cicdDeploymentCommit.StartedDate,
FinishedDate: cicdDeploymentCommit.FinishedDate,
DurationSec: cicdDeploymentCommit.DurationSec,
CicdScopeId: cicdDeploymentCommit.CicdScopeId,
Name: cicdDeploymentCommit.Name,
Result: cicdDeploymentCommit.Result,
Status: cicdDeploymentCommit.Status,
Environment: cicdDeploymentCommit.Environment,
ItemDateInfo: ItemDateInfo{
CreatedDate: cicdDeploymentCommit.CreatedDate,
StartedDate: cicdDeploymentCommit.StartedDate,
FinishedDate: cicdDeploymentCommit.FinishedDate,
},
DurationSec: cicdDeploymentCommit.DurationSec,
}
}
21 changes: 9 additions & 12 deletions backend/core/models/domainlayer/devops/cicd_pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,22 @@ limitations under the License.
package devops

import (
"strings"
"time"

"github.com/spf13/cast"
"strings"

"github.com/apache/incubator-devlake/core/models/domainlayer"
)

type CICDPipeline struct {
domainlayer.DomainEntity
Name string `gorm:"type:varchar(255)"`
Result string `gorm:"type:varchar(100)"`
Status string `gorm:"type:varchar(100)"`
Type string `gorm:"type:varchar(100);comment: to indicate this is CI or CD"`
DurationSec float64
Environment string `gorm:"type:varchar(255)"`
CreatedDate time.Time
FinishedDate *time.Time
CicdScopeId string `gorm:"index;type:varchar(255)"`
Name string `gorm:"type:varchar(255)"`
Result string `gorm:"type:varchar(100)"`
Status string `gorm:"type:varchar(100)"`
Type string `gorm:"type:varchar(100);comment: to indicate this is CI or CD"`
DurationSec float64
Environment string `gorm:"type:varchar(255)"`
ItemDateInfo
CicdScopeId string `gorm:"index;type:varchar(255)"`
}

func (CICDPipeline) TableName() string {
Expand Down
21 changes: 10 additions & 11 deletions backend/core/models/domainlayer/devops/cicd_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package devops

import (
"github.com/apache/incubator-devlake/core/models/domainlayer"
"time"
)

const (
Expand All @@ -39,16 +38,16 @@ const ENV_NAME_PATTERN = "ENV_NAME_PATTERN"

type CICDTask struct {
domainlayer.DomainEntity
Name string `gorm:"type:varchar(255)"`
PipelineId string `gorm:"index;type:varchar(255)"`
Result string `gorm:"type:varchar(100)"`
Status string `gorm:"type:varchar(100)"`
Type string `gorm:"type:varchar(100);comment: to indicate this is CI or CD"`
Environment string `gorm:"type:varchar(255)"`
DurationSec float64
StartedDate time.Time
FinishedDate *time.Time
CicdScopeId string `gorm:"index;type:varchar(255)"`
Name string `gorm:"type:varchar(255)"`
PipelineId string `gorm:"index;type:varchar(255)"`
Result string `gorm:"type:varchar(100)"`
Status string `gorm:"type:varchar(100)"`
Type string `gorm:"type:varchar(100);comment: to indicate this is CI or CD"`
Environment string `gorm:"type:varchar(255)"`
DurationSec float64
ItemDateInfo
//StartedDate time.Time // notice here
CicdScopeId string `gorm:"index;type:varchar(255)"`
}

func (CICDTask) TableName() string {
Expand Down
27 changes: 27 additions & 0 deletions backend/core/models/domainlayer/devops/common.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You 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 devops

import "time"

type ItemDateInfo struct {
CreatedDate time.Time
StartedDate *time.Time
QueuedDate *time.Time
FinishedDate *time.Time
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You 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 migrationscripts

import (
"github.com/apache/incubator-devlake/core/context"
"github.com/apache/incubator-devlake/core/errors"
"github.com/apache/incubator-devlake/core/plugin"
"time"
)

var _ plugin.MigrationScript = (*addSomeDateFieldsToDevopsTables)(nil)

type cicdDeployment20231122 struct {
QueuedDate *time.Time
}

func (cicdDeployment20231122) TableName() string {
return "cicd_deployments"
}

type cicdDeploymentCommit20231122 struct {
QueuedDate *time.Time
}

func (cicdDeploymentCommit20231122) TableName() string {
return "cicd_deployment_commits"
}

type cicdPipeline20231122 struct {
StartedDate *time.Time
QueuedDate *time.Time
}

func (cicdPipeline20231122) TableName() string {
return "cicd_pipelines"
}

type cicdTask20231122 struct {
CreatedDate time.Time
QueuedDate *time.Time
}

func (cicdTask20231122) TableName() string {
return "cicd_tasks"
}

type addSomeDateFieldsToDevopsTables struct{}

func (u *addSomeDateFieldsToDevopsTables) Up(basicRes context.BasicRes) errors.Error {
db := basicRes.GetDal()
if err := db.AutoMigrate(&cicdPipeline20231122{}); err != nil {
return err
}
if err := db.AutoMigrate(&cicdTask20231122{}); err != nil {
return err
}
if err := db.AutoMigrate(&cicdDeployment20231122{}); err != nil {
return err
}
if err := db.AutoMigrate(&cicdDeploymentCommit20231122{}); err != nil {
return err
}
return nil
}

func (*addSomeDateFieldsToDevopsTables) Version() uint64 {
return 20231122140000
}

func (*addSomeDateFieldsToDevopsTables) Name() string {
return "change duration_sec field to float64 in all related tables"
}
1 change: 1 addition & 0 deletions backend/core/models/migrationscripts/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,6 @@ func All() []plugin.MigrationScript {
new(addIssueCustomArrayField),
new(removePositionFromPullRequestComments),
new(changeDurationSecToFloat64),
new(addSomeDateFieldsToDevopsTables),
}
}
14 changes: 8 additions & 6 deletions backend/plugins/bamboo/tasks/deploy_build_convertor.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,14 @@ func ConvertDeployBuilds(taskCtx plugin.SubTaskContext) errors.Error {
InProgress: []string{StatusInProgress, StatusPending, StatusQueued},
Default: devops.STATUS_OTHER,
}, input.LifeCycleState),
Environment: input.Environment,
StartedDate: input.StartedDate,
FinishedDate: input.FinishedDate,
CommitSha: input.VcsRevisionKey,
RefName: input.PlanBranchName,
RepoId: strconv.Itoa(input.RepositoryId),
Environment: input.Environment,
ItemDateInfo: devops.ItemDateInfo{
StartedDate: input.StartedDate,
FinishedDate: input.FinishedDate,
},
CommitSha: input.VcsRevisionKey,
RefName: input.PlanBranchName,
RepoId: strconv.Itoa(input.RepositoryId),
}
deploymentCommit.CreatedDate = time.Now()
if input.StartedDate != nil {
Expand Down
13 changes: 7 additions & 6 deletions backend/plugins/bamboo/tasks/job_build_convertor.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ limitations under the License.
package tasks

import (
"reflect"

"github.com/apache/incubator-devlake/core/dal"
"github.com/apache/incubator-devlake/core/errors"
"github.com/apache/incubator-devlake/core/models/domainlayer"
Expand All @@ -28,6 +26,7 @@ import (
"github.com/apache/incubator-devlake/core/plugin"
"github.com/apache/incubator-devlake/helpers/pluginhelper/api"
"github.com/apache/incubator-devlake/plugins/bamboo/models"
"reflect"
)

var ConvertJobBuildsMeta = plugin.SubTaskMeta{
Expand Down Expand Up @@ -66,10 +65,12 @@ func ConvertJobBuilds(taskCtx plugin.SubTaskContext) errors.Error {
DomainEntity: domainlayer.DomainEntity{Id: jobBuildIdGen.Generate(data.Options.ConnectionId, line.JobBuildKey)},
Name: line.JobName,
DurationSec: float64(line.BuildDurationInSeconds),
StartedDate: *line.BuildStartedTime,
FinishedDate: line.BuildCompletedDate,
PipelineId: planBuildIdGen.Generate(data.Options.ConnectionId, line.PlanBuildKey),
CicdScopeId: planIdGen.Generate(data.Options.ConnectionId, data.Options.PlanKey),
ItemDateInfo: devops.ItemDateInfo{
StartedDate: line.BuildStartedTime,
FinishedDate: line.BuildCompletedDate,
},
PipelineId: planBuildIdGen.Generate(data.Options.ConnectionId, line.PlanBuildKey),
CicdScopeId: planIdGen.Generate(data.Options.ConnectionId, data.Options.PlanKey),

Result: devops.GetResult(&devops.ResultRule{
Success: []string{ResultSuccess, ResultSuccessful},
Expand Down
11 changes: 6 additions & 5 deletions backend/plugins/bamboo/tasks/plan_build_convertor.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ limitations under the License.
package tasks

import (
"reflect"

"github.com/apache/incubator-devlake/core/dal"
"github.com/apache/incubator-devlake/core/errors"
"github.com/apache/incubator-devlake/core/models/domainlayer"
Expand All @@ -28,6 +26,7 @@ import (
"github.com/apache/incubator-devlake/core/plugin"
"github.com/apache/incubator-devlake/helpers/pluginhelper/api"
"github.com/apache/incubator-devlake/plugins/bamboo/models"
"reflect"
)

var ConvertPlanBuildsMeta = plugin.SubTaskMeta{
Expand Down Expand Up @@ -65,9 +64,11 @@ func ConvertPlanBuilds(taskCtx plugin.SubTaskContext) errors.Error {
DomainEntity: domainlayer.DomainEntity{Id: planBuildIdGen.Generate(data.Options.ConnectionId, line.PlanBuildKey)},
Name: line.GenerateCICDPipeLineName(),
DurationSec: float64(line.BuildDurationInSeconds),
CreatedDate: *line.BuildStartedTime,
FinishedDate: line.BuildCompletedDate,
CicdScopeId: planIdGen.Generate(data.Options.ConnectionId, data.Options.PlanKey),
ItemDateInfo: devops.ItemDateInfo{
CreatedDate: *line.BuildStartedTime,
FinishedDate: line.BuildCompletedDate,
},
CicdScopeId: planIdGen.Generate(data.Options.ConnectionId, data.Options.PlanKey),

Result: devops.GetResult(&devops.ResultRule{
Success: []string{ResultSuccess, ResultSuccessful},
Expand Down
Loading

0 comments on commit aa07ad9

Please sign in to comment.