Skip to content
Merged
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
53 changes: 53 additions & 0 deletions backend/core/models/domainlayer/devops/cicd_release.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
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 (
"github.com/apache/incubator-devlake/core/models/domainlayer"
"time"
)

type CicdRelease struct {
domainlayer.DomainEntity
PublishedAt time.Time `json:"publishedAt"`

CicdScopeId string `gorm:"index;type:varchar(255)"`

Name string `gorm:"type:varchar(255)"`
DisplayTitle string `gorm:"type:varchar(255)"`
Description string `json:"description"`
URL string `json:"url"`

IsDraft bool `json:"isDraft"`
IsLatest bool `json:"isLatest"`
IsPrerelease bool `json:"isPrerelease"`

AuthorID string `json:"id" gorm:"type:varchar(255)"`

RepoId string `gorm:"type:varchar(255)"`
//RepoUrl string `gorm:"index;not null"`

TagName string `json:"tagName"`
//CommitSha string `gorm:"primaryKey;type:varchar(255)"`
//CommitMsg string
//RefName string `gorm:"type:varchar(255)"`
}

func (CicdRelease) TableName() string {
return "cicd_releases"
}
1 change: 1 addition & 0 deletions backend/core/models/domainlayer/domaininfo/domaininfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ func GetDomainTablesInfo() []dal.Tabler {
&devops.CiCDPipelineCommit{},
&devops.CicdScope{},
&devops.CICDDeployment{},
&devops.CicdRelease{},
// didgen no table
// ticket
&ticket.Board{},
Expand Down
69 changes: 69 additions & 0 deletions backend/core/models/migrationscripts/20240514_add_cicd_release.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
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/models/migrationscripts/archived"
"time"

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

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

type cicdRelease20240514 struct {
archived.DomainEntity
PublishedAt time.Time `json:"publishedAt"`

CicdScopeId string `gorm:"index;type:varchar(255)"`

Name string `gorm:"type:varchar(255)"`
DisplayTitle string `gorm:"type:varchar(255)"`
Description string `json:"description"`
URL string `json:"url"`

IsDraft bool `json:"isDraft"`
IsLatest bool `json:"isLatest"`
IsPrerelease bool `json:"isPrerelease"`

AuthorID string `json:"id" gorm:"type:varchar(255)"`

RepoId string `gorm:"type:varchar(255)"`

TagName string `json:"tagName"`
}

func (cicdRelease20240514) TableName() string {
return "cicd_releases"
}

type addCicdRelease struct{}

func (*addCicdRelease) Up(basicRes context.BasicRes) errors.Error {
return basicRes.GetDal().AutoMigrate(cicdRelease20240514{})
}

func (*addCicdRelease) Version() uint64 {
return 20240514181200
}

func (*addCicdRelease) Name() string {
return "add cicd_releases table"
}
1 change: 1 addition & 0 deletions backend/core/models/migrationscripts/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,5 +113,6 @@ func All() []plugin.MigrationScript {
new(addSubtaskField),
new(addDisplayTitleAndUrl),
new(addSubtaskStates),
new(addCicdRelease),
}
}
1 change: 1 addition & 0 deletions backend/plugins/github/impl/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ func (p Github) GetTablesInfo() []dal.Tabler {
&models.GithubIssueAssignee{},
&models.GithubScopeConfig{},
&models.GithubDeployment{},
&models.GithubRelease{},
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
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/models/migrationscripts/archived"
"github.com/apache/incubator-devlake/helpers/migrationhelper"
"time"
)

type addReleaseTable struct{}

type release20240514 struct {
archived.NoPKModel `json:"-" mapstructure:"-"`
ConnectionId uint64 `json:"connection_id" gorm:"primaryKey"`
GithubId int `json:"github_id"`
Id string `json:"id" gorm:"type:varchar(255);primaryKey"`
AuthorName string `json:"authorName"`
AuthorID string `json:"authorId"`
CreatedAt time.Time `json:"createdAt"`
DatabaseID int `json:"databaseId"`
Description string `json:"description"`
DescriptionHTML string `json:"descriptionHTML"`
IsDraft bool `json:"isDraft"`
IsLatest bool `json:"isLatest"`
IsPrerelease bool `json:"isPrerelease"`
Name string `json:"name"`
PublishedAt time.Time `json:"publishedAt"`
ResourcePath string `json:"resourcePath"`
TagName string `json:"tagName"`
UpdatedAt time.Time `json:"updatedAt"`
URL string `json:"url"`
}

func (release20240514) TableName() string {
return "_tool_github_releases"
}

func (u *addReleaseTable) Up(baseRes context.BasicRes) errors.Error {
return migrationhelper.AutoMigrateTables(baseRes, &release20240514{})
}

func (*addReleaseTable) Version() uint64 {
return 20240514182300
}

func (*addReleaseTable) Name() string {
return "add table _tool_github_releases"
}
1 change: 1 addition & 0 deletions backend/plugins/github/models/migrationscripts/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,6 @@ func All() []plugin.MigrationScript {
new(addEnvNamePattern),
new(modifyIssueTypeLength),
new(addWorkflowDisplayTitle),
new(addReleaseTable),
}
}
50 changes: 50 additions & 0 deletions backend/plugins/github/models/release.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
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 models

import (
"time"

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

type GithubRelease struct {
common.NoPKModel `json:"-" mapstructure:"-"`
ConnectionId uint64 `json:"connection_id" gorm:"primaryKey"`
GithubId int `json:"github_id"`
Id string `json:"id" gorm:"type:varchar(255);primaryKey"`
AuthorName string `json:"authorName"`
AuthorID string `json:"authorId"`
CreatedAt time.Time `json:"createdAt"`
DatabaseID int `json:"databaseId"`
Description string `json:"description"`
DescriptionHTML string `json:"descriptionHTML"`
IsDraft bool `json:"isDraft"`
IsLatest bool `json:"isLatest"`
IsPrerelease bool `json:"isPrerelease"`
Name string `json:"name"`
PublishedAt time.Time `json:"publishedAt"`
ResourcePath string `json:"resourcePath"`
TagName string `json:"tagName"`
UpdatedAt time.Time `json:"updatedAt"`
URL string `json:"url"`
}

func (GithubRelease) TableName() string {
return "_tool_github_releases"
}
103 changes: 103 additions & 0 deletions backend/plugins/github/tasks/release_convertor.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*
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 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"
"github.com/apache/incubator-devlake/core/models/domainlayer/devops"
"github.com/apache/incubator-devlake/core/models/domainlayer/didgen"
"github.com/apache/incubator-devlake/core/plugin"
"github.com/apache/incubator-devlake/helpers/pluginhelper/api"
"github.com/apache/incubator-devlake/plugins/github/models"
)

func init() {
RegisterSubtaskMeta(&ConvertReleasesMeta)
}

const (
RAW_RELEASE_TABLE = "github_graphql_release"
)

var ConvertReleasesMeta = plugin.SubTaskMeta{
Name: "Convert Releases",
EntryPoint: ConvertRelease,
EnabledByDefault: true,
Description: "Convert tool layer table github_releases into domain layer table releases",
DomainTypes: []string{plugin.DOMAIN_TYPE_CICD},
DependencyTables: []string{models.GithubRelease{}.TableName()},
ProductTables: []string{devops.CicdRelease{}.TableName()},
}

func ConvertRelease(taskCtx plugin.SubTaskContext) errors.Error {
db := taskCtx.GetDal()
rawDataSubTaskArgs, data := CreateRawDataSubTaskArgs(taskCtx, RAW_RELEASE_TABLE)
cursor, err := db.Cursor(
dal.From(&models.GithubRelease{}),
dal.Where("connection_id = ? and github_id = ?", data.Options.ConnectionId, data.Options.GithubId),
)
if err != nil {
return err
}
defer cursor.Close()

releaseIdGen := didgen.NewDomainIdGenerator(&models.GithubRelease{})
releaseScopeIdGen := didgen.NewDomainIdGenerator(&models.GithubRepo{})

converter, err := api.NewDataConverter(api.DataConverterArgs{
InputRowType: reflect.TypeOf(models.GithubRelease{}),
Input: cursor,
RawDataSubTaskArgs: *rawDataSubTaskArgs,
Convert: func(inputRow interface{}) ([]interface{}, errors.Error) {
githubRelease := inputRow.(*models.GithubRelease)
release := &devops.CicdRelease{
DomainEntity: domainlayer.DomainEntity{
Id: releaseIdGen.Generate(githubRelease.ConnectionId, githubRelease.Id),
},
PublishedAt: githubRelease.PublishedAt,
CicdScopeId: releaseScopeIdGen.Generate(githubRelease.ConnectionId, githubRelease.GithubId),
Name: githubRelease.Name,
DisplayTitle: githubRelease.Name,
Description: githubRelease.Description,
URL: githubRelease.URL,
IsDraft: githubRelease.IsDraft,
IsLatest: githubRelease.IsLatest,
IsPrerelease: githubRelease.IsPrerelease,
TagName: githubRelease.TagName,

AuthorID: githubRelease.AuthorID,

RepoId: releaseScopeIdGen.Generate(githubRelease.ConnectionId, githubRelease.GithubId),
}

return []interface{}{
release,
}, nil
},
})

if err != nil {
return err
}

return converter.Execute()
}
5 changes: 5 additions & 0 deletions backend/plugins/github_graphql/impl/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@ func (p GithubGraphql) SubTaskMetas() []plugin.SubTaskMeta {
tasks.CollectDeploymentsMeta,
tasks.ExtractDeploymentsMeta,
githubTasks.ConvertDeploymentsMeta,

// releases
tasks.CollectReleaseMeta,
tasks.ExtractReleasesMeta,
githubTasks.ConvertReleasesMeta,
}
}

Expand Down
Loading