Skip to content

Commit

Permalink
Merge branch 'fix-5643' of github.com:merico-dev/lake into fix-5643
Browse files Browse the repository at this point in the history
  • Loading branch information
d4x1 committed Nov 23, 2023
2 parents 6bcfe3e + 952cc87 commit 155e1bd
Show file tree
Hide file tree
Showing 12 changed files with 177 additions and 26 deletions.
2 changes: 1 addition & 1 deletion backend/core/models/locking.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (LockingHistory) TableName() string {

// LockingStub does nothing but offer a locking target
type LockingStub struct {
Stub string `gorm:"type:varchar(255)"`
Stub string `gorm:"primaryKey;type:varchar(255)"`
}

func (LockingStub) TableName() string {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
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/core/plugin"
"time"
)

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

type bitbucketPipelineStep20231123 struct {
ConnectionId uint64 `gorm:"primaryKey"`
BitbucketId string `gorm:"primaryKey"`
PipelineId string `gorm:"type:varchar(255)"`
Name string `gorm:"type:varchar(255)"`
Trigger string `gorm:"type:varchar(255)"`
State string `gorm:"type:varchar(255)"`
Result string `gorm:"type:varchar(255)"`
RepoId string `gorm:"type:varchar(255)"`
MaxTime int
StartedOn *time.Time
CompletedOn *time.Time
DurationInSeconds int
BuildSecondsUsed int
RunNumber int
Type string `gorm:"type:varchar(255)"`
Environment string `gorm:"type:varchar(255)"`
archived.NoPKModel
}

func (bitbucketPipelineStep20231123) TableName() string {
return "_tool_bitbucket_pipeline_steps"
}

type reCreatBitBucketPipelineSteps struct{}

func (script *reCreatBitBucketPipelineSteps) Up(basicRes context.BasicRes) errors.Error {
db := basicRes.GetDal()
if err := db.DropTables(bitbucketPipelineStep20231123{}.TableName()); err != nil {
return err
}
return db.AutoMigrate(&bitbucketPipelineStep20231123{})
}

func (*reCreatBitBucketPipelineSteps) Version() uint64 {
return 20231123160001
}

func (script *reCreatBitBucketPipelineSteps) Name() string {
return "re create _tool_bitbucket_pipeline_steps, make sure primary keys exist."
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,6 @@ func All() []plugin.MigrationScript {
new(renameTr2ScopeConfig),
new(addRawParamTableForScope),
new(addBuildNumberToPipelines),
new(reCreatBitBucketPipelineSteps),
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
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/core/plugin"
)

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

type teambitionConnection20231123 struct {
Name string `gorm:"type:varchar(100);uniqueIndex" json:"name" validate:"required"`
archived.Model
archived.RestConnection `mapstructure:",squash"`
TenantId string `mapstructure:"tenantId" validate:"required" json:"tenantId"`
TenantType string `mapstructure:"tenantType" validate:"required" json:"tenantType"`
}

func (teambitionConnection20231123) TableName() string {
return "_tool_teambition_connections"
}

type reCreateTeambitionConnections struct{}

func (*reCreateTeambitionConnections) Up(basicRes context.BasicRes) errors.Error {
db := basicRes.GetDal()
if err := db.DropTables(teambitionConnection20231123{}.TableName()); err != nil {
return err
}
return db.AutoMigrate(&teambitionConnection20231123{})
}

func (*reCreateTeambitionConnections) Version() uint64 {
return 20231123160000
}

func (*reCreateTeambitionConnections) Name() string {
return "recreate teambition connection table"
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ import "github.com/apache/incubator-devlake/core/plugin"
func All() []plugin.MigrationScript {
return []plugin.MigrationScript{
new(addInitTables),
new(reCreateTeambitionConnections),
}
}
1 change: 1 addition & 0 deletions backend/server/services/locking.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func lockDatabase() {
lockingTx = db.Begin()
c := make(chan bool, 1)
go func() {
errors.Must(lockingTx.DropTables(models.LockingStub{}.TableName()))
errors.Must(lockingTx.AutoMigrate(&models.LockingStub{}))
errors.Must(lockingTx.LockTables(dal.LockTables{{Table: "_devlake_locking_stub", Exclusive: true}}))
lockingHistory.Succeeded = true
Expand Down
2 changes: 1 addition & 1 deletion config-ui/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ ${SERVER_CONF}
proxy_set_header "Connection" "";
}

location ~ ^/grafana(?:/|$) {
location /grafana/ {
set $external "${USE_EXTERNAL_GRAFANA}";
if ($external = "true") {
return 302 "${GRAFANA_ENDPOINT}";
Expand Down
46 changes: 29 additions & 17 deletions config-ui/src/features/connections/slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ export const init = createAsyncThunk('connections/init', async (plugins: string[
.filter((plugin) => plugin === 'webhook')
.map(async () => {
const webhooks = await API.plugin.webhook.list();
console.log(webhooks);
return webhooks.map((webhook) => transformWebhook(webhook));
}),
);
Expand Down Expand Up @@ -93,22 +92,29 @@ export const removeConnection = createAsyncThunk(

export const testConnection = createAsyncThunk(
'connections/testConnection',
async ({ unique, plugin, endpoint, proxy, token, username, password, authMethod, secretKey, appId }: IConnection) => {
const res = await API.connection.test(plugin, {
endpoint,
proxy,
token,
username,
password,
authMethod,
secretKey,
appId,
});

return {
unique,
status: res.success ? IConnectionStatus.ONLINE : IConnectionStatus.OFFLINE,
};
async (
{ unique, plugin, endpoint, proxy, token, username, password, authMethod, secretKey, appId }: IConnection,
{ rejectWithValue },
) => {
try {
const res = await API.connection.test(plugin, {
endpoint,
proxy,
token,
username,
password,
authMethod,
secretKey,
appId,
});

return {
unique,
status: res.success ? IConnectionStatus.ONLINE : IConnectionStatus.OFFLINE,
};
} catch (err: any) {
return rejectWithValue({ unique, response: err.response });
}
},
);

Expand Down Expand Up @@ -185,6 +191,12 @@ export const connectionsSlice = createSlice({
existingConnection.status = action.payload.status;
}
})
.addCase(testConnection.rejected, (state, action) => {
const existingConnection = state.connections.find((cs) => cs.unique === action.meta.arg.unique);
if (existingConnection) {
existingConnection.status = IConnectionStatus.OFFLINE;
}
})
.addCase(addWebhook.fulfilled, (state, action) => {
state.webhooks.push(action.payload.webhook);
})
Expand Down
3 changes: 2 additions & 1 deletion config-ui/src/plugins/components/connection-status/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { useAppDispatch } from '@/app/hook';
import { IconButton } from '@/components';
import { testConnection } from '@/features/connections';
import { IConnection, IConnectionStatus } from '@/types';
import { operator } from '@/utils';

const Wrapper = styled.div`
display: inline-flex;
Expand Down Expand Up @@ -52,7 +53,7 @@ export const ConnectionStatus = ({ connection }: Props) => {

const dispatch = useAppDispatch();

const handleTest = () => dispatch(testConnection(connection));
const handleTest = () => operator(() => dispatch(testConnection(connection)).unwrap());

return (
<Wrapper>
Expand Down
4 changes: 3 additions & 1 deletion config-ui/src/routes/connection/connections.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const Connections = () => {

const [firstPlugins, secondPlugins] = chunk(
plugins.filter((p) => p !== 'webhook'),
6,
7,
);

const handleShowListDialog = (plugin: string) => {
Expand Down Expand Up @@ -145,6 +145,7 @@ export const Connections = () => {
<Modal
open
width={820}
centered
title={
<S.ModalTitle>
<span className="icon">{pluginConfig.icon({ color: colorPrimary })}</span>
Expand All @@ -161,6 +162,7 @@ export const Connections = () => {
<Modal
open
width={820}
centered
title={
<S.ModalTitle>
<span className="icon">{pluginConfig.icon({ color: colorPrimary })}</span>
Expand Down
2 changes: 1 addition & 1 deletion config-ui/src/routes/layout/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export const Layout = () => {
</>
))}
</Header>
<Content style={{ margin: '16px 24px' }}>
<Content style={{ margin: '0 auto', maxWidth: 1188 }}>
<Outlet />
</Content>
<Footer style={{ color: '#a1a1a1', textAlign: 'center' }}>
Expand Down
14 changes: 10 additions & 4 deletions config-ui/src/utils/operator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*
*/

import { toast } from '@/components';
import { message } from 'antd';

export type OperateConfig = {
setOperating?: (success: boolean) => void;
Expand All @@ -40,16 +40,22 @@ export const operator = async <T>(request: () => Promise<T>, config?: OperateCon
try {
setOperating?.(true);
const res = await request();
const message = formatMessage?.() ?? 'Operation successfully completed';
const content = formatMessage?.() ?? 'Operation successfully completed';
if (!config?.hideToast) {
toast.success(message);
message.open({
type: 'success',
content,
});
}
return [true, res];
} catch (err) {
console.error('Operation failed.', err);
const reason = formatReason?.(err) ?? (err as any).response?.data?.message ?? 'Operation failed.';
if (!config?.hideToast) {
toast.error(reason);
message.open({
type: 'error',
content: reason,
});
}

return [false, err];
Expand Down

0 comments on commit 155e1bd

Please sign in to comment.