Skip to content

Commit 8110c15

Browse files
authored
Merge branch 'main' into feat#6101
2 parents 337fdd4 + 6526762 commit 8110c15

File tree

85 files changed

+901
-1894
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+901
-1894
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#
2+
# Licensed to the Apache Software Foundation (ASF) under one or more
3+
# contributor license agreements. See the NOTICE file distributed with
4+
# this work for additional information regarding copyright ownership.
5+
# The ASF licenses this file to You under the Apache License, Version 2.0
6+
# (the "License"); you may not use this file except in compliance with
7+
# the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
name: check-grafana-dashboards
18+
19+
on:
20+
pull_request:
21+
branches:
22+
- main
23+
- release-*
24+
25+
jobs:
26+
check-grafana-dashboards:
27+
name: check grafana dashboards
28+
runs-on: ubuntu-20.04
29+
steps:
30+
- name: Checkout repository
31+
uses: actions/checkout@v2
32+
- name: Check grafana dashboards whether using mysql uid
33+
run: |
34+
if grep '"type": "mysql"' grafana/dashboards/*; then
35+
echo "There are dashboards which use mysql uid as datasource"
36+
exit 1
37+
fi

backend/helpers/pluginhelper/api/api_collector_with_state.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ func NewStatefulApiCollector(args RawDataSubTaskArgs) (*ApiCollectorStateManager
113113
// InitCollector init the embedded collector
114114
func (m *ApiCollectorStateManager) InitCollector(args ApiCollectorArgs) errors.Error {
115115
args.RawDataSubTaskArgs = m.RawDataSubTaskArgs
116-
args.Incremental = m.IsIncreamtal
116+
args.Incremental = args.Incremental || m.IsIncreamtal
117117
apiCollector, err := NewApiCollector(args)
118118
if err != nil {
119119
return err

backend/helpers/pluginhelper/api/scope_generic_helper.go

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ limitations under the License.
1818
package api
1919

2020
import (
21-
"encoding/json"
2221
"fmt"
2322
"reflect"
2423
"strconv"
@@ -36,7 +35,6 @@ import (
3635
"github.com/apache/incubator-devlake/helpers/dbhelper"
3736
serviceHelper "github.com/apache/incubator-devlake/helpers/pluginhelper/services"
3837
"github.com/go-playground/validator/v10"
39-
"github.com/mitchellh/mapstructure"
4038
)
4139

4240
type NoScopeConfig struct{}
@@ -64,8 +62,9 @@ type (
6462
// Alias, for swagger purposes
6563
ScopeRefDoc = serviceHelper.BlueprintProjectPairs
6664
ScopeRes[Scope plugin.ToolLayerScope, ScopeConfig any] struct {
67-
Scope Scope `mapstructure:",squash"` // ideally we need this field to be embedded in the struct
68-
ScopeResDoc[ScopeConfig] `mapstructure:",squash"` // however, only this type of embeding is supported as of golang 1.20
65+
Scope Scope `mapstructure:"scope,omitempty" json:"scope,omitempty"`
66+
ScopeConfig *ScopeConfig `mapstructure:"scopeConfig,omitempty" json:"scopeConfig,omitempty"`
67+
Blueprints []*models.Blueprint `mapstructure:"blueprints,omitempty" json:"blueprints,omitempty"`
6968
}
7069
ScopeListRes[Scope plugin.ToolLayerScope, ScopeConfig any] struct {
7170
Scopes []*ScopeRes[Scope, ScopeConfig] `mapstructure:"scopes" json:"scopes"`
@@ -601,22 +600,6 @@ func (gs *GenericScopeApiHelper[Conn, Scope, ScopeConfig]) transactionalDelete(t
601600
return nil
602601
}
603602

604-
// Implement MarshalJSON method to flatten all fields
605-
func (sr *ScopeRes[T, Y]) MarshalJSON() ([]byte, error) {
606-
var flatMap map[string]interface{}
607-
err := mapstructure.Decode(sr, &flatMap)
608-
if err != nil {
609-
return nil, err
610-
}
611-
// Encode the flattened map to JSON
612-
result, err := json.Marshal(flatMap)
613-
if err != nil {
614-
return nil, err
615-
}
616-
617-
return result, nil
618-
}
619-
620603
func (gs *GenericScopeApiHelper[Conn, Scope, ScopeConfig]) getAffectedTables(pluginName string) ([]string, errors.Error) {
621604
var tables []string
622605
meta, err := plugin.GetPlugin(pluginName)

backend/plugins/github/tasks/cicd_job_convertor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func ConvertJobs(taskCtx plugin.SubTaskContext) (err errors.Error) {
9999
Result: devops.GetResult(&devops.ResultRule{
100100
Failed: []string{"failure"},
101101
Success: []string{"success"},
102-
Skipped: []string{"skipped"},
102+
Skipped: []string{"skipped", "NEUTRAL"},
103103
}, line.Conclusion),
104104
Status: devops.GetStatus(&devops.StatusRule[string]{
105105
Done: []string{"completed", "COMPLETED"},

backend/plugins/github/tasks/cicd_run_collector.go

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,14 @@ package tasks
2020
import (
2121
"encoding/json"
2222
"fmt"
23-
"io"
2423
"net/http"
2524
"net/url"
26-
"reflect"
2725
"time"
2826

29-
"github.com/apache/incubator-devlake/core/dal"
3027
"github.com/apache/incubator-devlake/core/errors"
3128
"github.com/apache/incubator-devlake/core/models/common"
3229
"github.com/apache/incubator-devlake/core/plugin"
3330
helper "github.com/apache/incubator-devlake/helpers/pluginhelper/api"
34-
"github.com/apache/incubator-devlake/plugins/github/models"
3531
)
3632

3733
func init() {
@@ -67,7 +63,6 @@ var CollectRunsMeta = plugin.SubTaskMeta{
6763

6864
func CollectRuns(taskCtx plugin.SubTaskContext) errors.Error {
6965
data := taskCtx.GetData().(*GithubTaskData)
70-
db := taskCtx.GetDal()
7166
collector, err := helper.NewStatefulApiCollectorForFinalizableEntity(helper.FinalizableApiCollectorArgs{
7267
RawDataSubTaskArgs: helper.RawDataSubTaskArgs{
7368
Ctx: taskCtx,
@@ -85,6 +80,7 @@ func CollectRuns(taskCtx plugin.SubTaskContext) errors.Error {
8580
UrlTemplate: "repos/{{ .Params.Name }}/actions/runs",
8681
Query: func(reqData *helper.RequestData, createdAfter *time.Time) (url.Values, errors.Error) {
8782
query := url.Values{}
83+
query.Set("status", "completed")
8884
query.Set("page", fmt.Sprintf("%v", reqData.Pager.Page))
8985
query.Set("per_page", fmt.Sprintf("%v", reqData.Pager.Size))
9086
return query, nil
@@ -110,36 +106,6 @@ func CollectRuns(taskCtx plugin.SubTaskContext) errors.Error {
110106
return pj.CreatedAt.ToTime(), nil
111107
},
112108
},
113-
CollectUnfinishedDetails: &helper.FinalizableApiCollectorDetailArgs{
114-
BuildInputIterator: func() (helper.Iterator, errors.Error) {
115-
// load unfinished runs from the database
116-
cursor, err := db.Cursor(
117-
dal.Select("id"),
118-
dal.From(&models.GithubRun{}),
119-
dal.Where(
120-
"repo_id = ? AND connection_id = ? AND status IN ('ACTION_REQUIRED', 'STALE', 'IN_PROGRESS', 'QUEUED', 'REQUESTED', 'WAITING', 'PENDING')",
121-
data.Options.GithubId, data.Options.ConnectionId,
122-
),
123-
)
124-
if err != nil {
125-
return nil, err
126-
}
127-
return helper.NewDalCursorIterator(db, cursor, reflect.TypeOf(SimpleGithubApiJob{}))
128-
},
129-
130-
FinalizableApiCollectorCommonArgs: helper.FinalizableApiCollectorCommonArgs{
131-
UrlTemplate: "repos/{{ .Params.Name }}/actions/runs/{{ .Input.ID }}",
132-
ResponseParser: func(res *http.Response) ([]json.RawMessage, errors.Error) {
133-
body, err := io.ReadAll(res.Body)
134-
if err != nil {
135-
return nil, errors.Convert(err)
136-
}
137-
res.Body.Close()
138-
return []json.RawMessage{body}, nil
139-
},
140-
AfterResponse: ignoreHTTPStatus404,
141-
},
142-
},
143109
})
144110

145111
if err != nil {

backend/plugins/jenkins/tasks/build_collector.go

Lines changed: 14 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,13 @@ package tasks
2020
import (
2121
"encoding/json"
2222
"fmt"
23-
"io"
2423
"net/http"
2524
"net/url"
26-
"reflect"
2725
"time"
2826

29-
"github.com/apache/incubator-devlake/core/dal"
3027
"github.com/apache/incubator-devlake/core/errors"
3128
"github.com/apache/incubator-devlake/core/plugin"
3229
helper "github.com/apache/incubator-devlake/helpers/pluginhelper/api"
33-
"github.com/apache/incubator-devlake/plugins/jenkins/models"
3430
)
3531

3632
const RAW_BUILD_TABLE = "jenkins_api_builds"
@@ -55,7 +51,6 @@ type SimpleJenkinsApiBuild struct {
5551

5652
func CollectApiBuilds(taskCtx plugin.SubTaskContext) errors.Error {
5753
data := taskCtx.GetData().(*JenkinsTaskData)
58-
db := taskCtx.GetDal()
5954
collector, err := helper.NewStatefulApiCollectorForFinalizableEntity(helper.FinalizableApiCollectorArgs{
6055
RawDataSubTaskArgs: helper.RawDataSubTaskArgs{
6156
Params: JenkinsApiParams{
@@ -87,7 +82,20 @@ func CollectApiBuilds(taskCtx plugin.SubTaskContext) errors.Error {
8782
if err != nil {
8883
return nil, err
8984
}
90-
return data.Builds, nil
85+
86+
builds := make([]json.RawMessage, 0, len(data.Builds))
87+
for _, build := range data.Builds {
88+
var buildObj map[string]interface{}
89+
err := json.Unmarshal(build, &buildObj)
90+
if err != nil {
91+
return nil, errors.Convert(err)
92+
}
93+
if buildObj["result"] != nil {
94+
builds = append(builds, build)
95+
}
96+
}
97+
98+
return builds, nil
9199
},
92100
},
93101
GetCreated: func(item json.RawMessage) (time.Time, errors.Error) {
@@ -101,34 +109,6 @@ func CollectApiBuilds(taskCtx plugin.SubTaskContext) errors.Error {
101109
return time.Unix(seconds, nanos), nil
102110
},
103111
},
104-
CollectUnfinishedDetails: &helper.FinalizableApiCollectorDetailArgs{
105-
BuildInputIterator: func() (helper.Iterator, errors.Error) {
106-
cursor, err := db.Cursor(
107-
dal.Select("number"),
108-
dal.From(&models.JenkinsBuild{}),
109-
dal.Where(
110-
"full_name = ? AND connection_id = ? AND result != 'SUCCESS' AND result != 'FAILURE'",
111-
data.Options.JobFullName, data.Options.ConnectionId,
112-
),
113-
)
114-
if err != nil {
115-
return nil, err
116-
}
117-
return helper.NewDalCursorIterator(db, cursor, reflect.TypeOf(SimpleJenkinsApiBuild{}))
118-
},
119-
FinalizableApiCollectorCommonArgs: helper.FinalizableApiCollectorCommonArgs{
120-
UrlTemplate: fmt.Sprintf("%sjob/%s/{{ .Input.Number }}/api/json?tree=number,url,result,timestamp,id,duration,estimatedDuration,building",
121-
data.Options.JobPath, data.Options.JobName),
122-
ResponseParser: func(res *http.Response) ([]json.RawMessage, errors.Error) {
123-
body, err := io.ReadAll(res.Body)
124-
if err != nil {
125-
return nil, errors.Convert(err)
126-
}
127-
res.Body.Close()
128-
return []json.RawMessage{body}, nil
129-
},
130-
},
131-
},
132112
})
133113

134114
if err != nil {

backend/plugins/pagerduty/api/remote.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ type RemoteScopesChild struct {
3939
Id string `json:"id"`
4040
Name string `json:"name"`
4141
Data interface{} `json:"data"`
42+
FullName string `json:"fullName"` // temporary fix, to adopt remote scope helper
4243
}
4344

4445
type RemoteScopesOutput struct {
@@ -127,9 +128,10 @@ func RemoteScopes(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, er
127128
// append service to output
128129
for _, service := range response.Services {
129130
child := RemoteScopesChild{
130-
Type: TypeScope,
131-
Id: service.Id,
132-
Name: service.Name,
131+
Type: TypeScope,
132+
Id: service.Id,
133+
Name: service.Name,
134+
FullName: service.Name,
133135
Data: models.Service{
134136
Url: service.HtmlUrl,
135137
Id: service.Id,

backend/server/services/remote/plugin/scope_api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ func convertScopeResponse(scopes ...*api.ScopeRes[models.DynamicScopeModel, mode
115115
responses := make([]map[string]any, len(scopes))
116116
for i, scope := range scopes {
117117
resMap := map[string]any{}
118-
err := models.MapTo(scope.ScopeResDoc, &resMap)
118+
err := models.MapTo(scope, &resMap)
119119
if err != nil {
120120
return nil, err
121121
}

config-ui/nginx.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ server {
22
listen 4000;
33
server_name localhost;
44
absolute_redirect off;
5+
client_max_body_size: 20m;
56

67
${SERVER_CONF}
78

config-ui/src/routes/api-keys/api.ts renamed to config-ui/src/api/api-key/index.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,14 @@
1717
*/
1818

1919
import { request } from '@/utils';
20-
2120
import * as T from './types';
2221

23-
export const getApiKeys = (params?: Pagination): Promise<{ count: number; apikeys: T.Key[] }> =>
22+
export const list = (data?: Pagination): Promise<{ count: number; apikeys: T.Key[] }> =>
2423
request('/api-keys', {
25-
data: params,
24+
data,
2625
});
2726

28-
export const createApiKey = (data: Pick<T.Key, 'name' | 'expiredAt' | 'allowedPath'>): Promise<T.Key> =>
27+
export const create = (data: Pick<T.Key, 'name' | 'expiredAt' | 'allowedPath'>): Promise<T.Key> =>
2928
request('/api-keys', {
3029
method: 'POST',
3130
data: {
@@ -34,7 +33,9 @@ export const createApiKey = (data: Pick<T.Key, 'name' | 'expiredAt' | 'allowedPa
3433
},
3534
});
3635

37-
export const deleteApiKey = (id: string): Promise<void> =>
36+
export const remove = (id: string): Promise<void> =>
3837
request(`/api-keys/${id}`, {
3938
method: 'DELETE',
4039
});
40+
41+
export const renew = (id: ID) => request(`/api-keys/${id}`, { method: 'put' });

0 commit comments

Comments
 (0)