This is an automated email from the ASF dual-hosted git repository.
abeizn pushed a commit to branch release-v0.19
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git
The following commit(s) were added to refs/heads/release-v0.19 by this push:
new b9ba51247 cherry-pick [bamboo] fix cicd_scope.url field to v0.19
(#6121)
b9ba51247 is described below
commit b9ba512473e1ac22fc397b512cdda2b7dea7887a
Author: Lynwee <[email protected]>
AuthorDate: Wed Sep 20 14:44:22 2023 +0800
cherry-pick [bamboo] fix cicd_scope.url field to v0.19 (#6121)
* fix(bamboo): fix cicd_scope.url field
* fix(bamboo): fix e2e test
* refactor(bamboo): update cicd_scopes.url field
* fix(bamboo): fix e2e test
* fix(bamboo): remove unused codes
---
.../bamboo/e2e/snapshot_tables/cicd_scopes.csv | 2 +-
backend/plugins/bamboo/tasks/plan_convertor.go | 12 +++-
backend/plugins/bamboo/tasks/shared.go | 17 +++++
backend/plugins/bamboo/tasks/shared_test.go | 81 ++++++++++++++++++++++
4 files changed, 108 insertions(+), 4 deletions(-)
diff --git a/backend/plugins/bamboo/e2e/snapshot_tables/cicd_scopes.csv
b/backend/plugins/bamboo/e2e/snapshot_tables/cicd_scopes.csv
index e8174b15f..f4742b2ab 100644
--- a/backend/plugins/bamboo/e2e/snapshot_tables/cicd_scopes.csv
+++ b/backend/plugins/bamboo/e2e/snapshot_tables/cicd_scopes.csv
@@ -1,2 +1,2 @@
id,name,description,url,created_date,updated_date
-bamboo:BambooPlan:3:TEST1,test_project - test_plan,just a test
plan,http://54.172.92.89:8085/rest/api/latest/plan/TEST1-TEST1,,
+bamboo:BambooPlan:3:TEST1,test_project - test_plan,just a test
plan,http://54.172.92.89:8085/browse/TEST1,,
diff --git a/backend/plugins/bamboo/tasks/plan_convertor.go
b/backend/plugins/bamboo/tasks/plan_convertor.go
index 9e5a2051b..ba04a8ce7 100644
--- a/backend/plugins/bamboo/tasks/plan_convertor.go
+++ b/backend/plugins/bamboo/tasks/plan_convertor.go
@@ -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"
@@ -28,6 +26,7 @@ import (
"github.com/apache/incubator-devlake/core/plugin"
"github.com/apache/incubator-devlake/helpers/pluginhelper/api"
bambooModels "github.com/apache/incubator-devlake/plugins/bamboo/models"
+ "reflect"
)
const RAW_PLAN_TABLE = "bamboo_plan"
@@ -42,6 +41,7 @@ var ConvertPlansMeta = plugin.SubTaskMeta{
func ConvertPlans(taskCtx plugin.SubTaskContext) errors.Error {
db := taskCtx.GetDal()
+ logger := taskCtx.GetLogger()
rawDataSubTaskArgs, data := CreateRawDataSubTaskArgs(taskCtx,
RAW_PLAN_TABLE)
cursor, err := db.Cursor(dal.From(bambooModels.BambooPlan{}),
dal.Where("connection_id = ? and plan_key = ?",
data.Options.ConnectionId, data.Options.PlanKey))
@@ -61,8 +61,14 @@ func ConvertPlans(taskCtx plugin.SubTaskContext)
errors.Error {
DomainEntity: domainlayer.DomainEntity{Id:
planIdGen.Generate(data.Options.ConnectionId, bambooPlan.PlanKey)},
Name: bambooPlan.Name,
Description: bambooPlan.Description,
- Url: bambooPlan.Href,
}
+ homepage, err := getBambooHomePage(bambooPlan.Href)
+ if err != nil {
+ logger.Warn(err, "get bamboo home")
+ } else {
+ domainPlan.Url = homepage + "/browse/" +
bambooPlan.PlanKey
+ }
+
return []interface{}{
domainPlan,
}, nil
diff --git a/backend/plugins/bamboo/tasks/shared.go
b/backend/plugins/bamboo/tasks/shared.go
index 554a2c75e..f74af27a1 100644
--- a/backend/plugins/bamboo/tasks/shared.go
+++ b/backend/plugins/bamboo/tasks/shared.go
@@ -22,6 +22,7 @@ import (
"fmt"
"net/http"
"net/url"
+ "strings"
"github.com/apache/incubator-devlake/core/errors"
"github.com/apache/incubator-devlake/core/plugin"
@@ -86,3 +87,19 @@ func GetResultsResult(res *http.Response)
([]json.RawMessage, errors.Error) {
}
return resData.Results.Result, nil
}
+
+// getBambooHomePage receive endpoint like
"http://127.0.0.1:30001/rest/api/latest/" and return bamboo's homepage like
"http://127.0.0.1:30001/"
+func getBambooHomePage(endpoint string) (string, error) {
+ if endpoint == "" {
+ return "", errors.Default.New("empty endpoint")
+ }
+ endpointURL, err := url.Parse(endpoint)
+ if err != nil {
+ return "", err
+ } else {
+ protocol := endpointURL.Scheme
+ host := endpointURL.Host
+ bambooPath, _, _ := strings.Cut(endpointURL.Path,
"/rest/api/latest")
+ return fmt.Sprintf("%s://%s%s", protocol, host, bambooPath), nil
+ }
+}
diff --git a/backend/plugins/bamboo/tasks/shared_test.go
b/backend/plugins/bamboo/tasks/shared_test.go
new file mode 100644
index 000000000..462408cd2
--- /dev/null
+++ b/backend/plugins/bamboo/tasks/shared_test.go
@@ -0,0 +1,81 @@
+/*
+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 "testing"
+
+func Test_getBambooWebURL(t *testing.T) {
+ type args struct {
+ endpoint string
+ }
+ tests := []struct {
+ name string
+ args args
+ want string
+ wantErr bool
+ }{
+ {
+ name: "without-bamboo",
+ args: args{endpoint:
"http://54.158.1.10:30001/rest/api/latest"},
+ want: "http://54.158.1.10:30001",
+ wantErr: false,
+ },
+ {
+ name: "without-bamboo-1",
+ args: args{endpoint:
"http://54.158.1.10:30001/rest/api/latest/"},
+ want: "http://54.158.1.10:30001",
+ wantErr: false,
+ },
+ {
+ name: "with-bamboo",
+ args: args{endpoint:
"http://54.158.1.10:30001/bamboo/rest/api/latest"},
+ want: "http://54.158.1.10:30001/bamboo",
+ wantErr: false,
+ },
+ {
+ name: "with-bamboo-1",
+ args: args{endpoint:
"http://54.158.1.10:30001/bamboo/rest/api/latest/"},
+ want: "http://54.158.1.10:30001/bamboo",
+ wantErr: false,
+ },
+ {
+ name: "with-others",
+ args: args{endpoint:
"http://54.158.1.10:30001/abc/rest/api/latest"},
+ want: "http://54.158.1.10:30001/abc",
+ wantErr: false,
+ },
+ {
+ name: "with-others-1",
+ args: args{endpoint:
"http://54.158.1.10:30001/abc/rest/api/latest/repos"},
+ want: "http://54.158.1.10:30001/abc",
+ wantErr: false,
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ got, err := getBambooHomePage(tt.args.endpoint)
+ if (err != nil) != tt.wantErr {
+ t.Errorf("getbambooHomePage() error = %v,
wantErr %v", err, tt.wantErr)
+ return
+ }
+ if got != tt.want {
+ t.Errorf("getbambooHomePage() got = %v, want
%v", got, tt.want)
+ }
+ })
+ }
+}