From cf21239c4a055a477a4fcc5a23c4d4a98dd2af2b Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Wed, 4 Dec 2024 17:39:45 +0800 Subject: [PATCH 1/8] =?UTF-8?q?feat:=20copilot=20=E7=BC=96=E8=BE=91?= =?UTF-8?q?=E5=99=A8=E6=94=AF=E6=8C=81=E5=85=8D=E7=99=BB=E5=BD=95=20#11290?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../constant/RepositoryMessageCode.kt | 1 + .../repository/pojo/enums/TokenTypeEnum.kt | 4 +++- .../devops/repository/dao/GitTokenDao.kt | 21 +++++++++++++++---- .../i18n/repository/message_en_US.properties | 1 + .../i18n/repository/message_zh_CN.properties | 1 + 5 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/constant/RepositoryMessageCode.kt b/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/constant/RepositoryMessageCode.kt index a0f561300a1..db1e4de5273 100644 --- a/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/constant/RepositoryMessageCode.kt +++ b/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/constant/RepositoryMessageCode.kt @@ -96,6 +96,7 @@ object RepositoryMessageCode { const val REPOSITORY_NO_SUPPORT_OAUTH = "2115045" // ({0})类型代码库暂不支持OAUTH授权 const val USER_NOT_PERMISSIONS_OPERATE_REPOSITORY = "2115046" // 用户({0})无权限在工程({1})下{2}流水线{3} + const val FAIL_TO_GET_OPEN_COPILOT_TOKEN = "2115048" // 获取open copilot token 失败, 失败详情: {0} const val BK_REQUEST_FILE_SIZE_LIMIT = "bkRequestFileSizeLimit" // 请求文件不能超过1M const val OPERATION_ADD_CHECK_RUNS = "OperationAddCheckRuns" // 添加检测任务 diff --git a/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/pojo/enums/TokenTypeEnum.kt b/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/pojo/enums/TokenTypeEnum.kt index 0d66c403582..fc10f5b70bb 100644 --- a/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/pojo/enums/TokenTypeEnum.kt +++ b/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/pojo/enums/TokenTypeEnum.kt @@ -29,13 +29,15 @@ package com.tencent.devops.repository.pojo.enums enum class TokenTypeEnum(val type: Int) { OAUTH(0), // oauth认证 - PRIVATE_KEY(1); // privateKey认证 + PRIVATE_KEY(1), // oauth认证 + COPILOT_TOKEN(2); // copilot token companion object { fun getTokenType(type: Int): String { return when (type) { 0 -> OAUTH.name 1 -> PRIVATE_KEY.name + 2 -> COPILOT_TOKEN.name else -> OAUTH.name } } diff --git a/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/dao/GitTokenDao.kt b/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/dao/GitTokenDao.kt index 2376f6f7ae6..f8a5642dea0 100644 --- a/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/dao/GitTokenDao.kt +++ b/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/dao/GitTokenDao.kt @@ -36,10 +36,14 @@ import java.time.LocalDateTime @Repository class GitTokenDao { - fun getAccessToken(dslContext: DSLContext, userId: String): TRepositoryGitTokenRecord? { + fun getAccessToken( + dslContext: DSLContext, + userId: String, + tokenType: String = DEFAULT_TOKEN_TYPE + ): TRepositoryGitTokenRecord? { with(TRepositoryGitToken.T_REPOSITORY_GIT_TOKEN) { return dslContext.selectFrom(this) - .where(USER_ID.eq(userId)) + .where(USER_ID.eq(userId).and(TOKEN_TYPE.eq(tokenType))) .fetchOne() } } @@ -73,11 +77,20 @@ class GitTokenDao { } } - fun deleteToken(dslContext: DSLContext, userId: String): Int { + fun deleteToken( + dslContext: DSLContext, + userId: String, + tokenType: String = DEFAULT_TOKEN_TYPE + ): Int { with(TRepositoryGitToken.T_REPOSITORY_GIT_TOKEN) { return dslContext.deleteFrom(this) - .where(USER_ID.eq(userId)) + .where(USER_ID.eq(userId).and(TOKEN_TYPE.eq(tokenType))) .execute() } } + + companion object { + // oauth授权后的默认token类型 + const val DEFAULT_TOKEN_TYPE = "bearer" + } } diff --git a/support-files/i18n/repository/message_en_US.properties b/support-files/i18n/repository/message_en_US.properties index a6ebabe38e3..76d84eaab51 100644 --- a/support-files/i18n/repository/message_en_US.properties +++ b/support-files/i18n/repository/message_en_US.properties @@ -47,6 +47,7 @@ 2115044=User [{0}] has not authorized Github Oauth yet. Please authorize first 2115045=({0}) type of code repository does not currently support OAUTH authorization 2100054=User ({0}) does not have permission to {2} repository {3} under project ({1}). +2115048=Failed to get open copilot token, failure details: {0} bkRequestFileSizeLimit=The request file cannot exceed 1m OperationAddCheckRuns=Add a detection task OperationUpdateCheckRuns=Update the detection task diff --git a/support-files/i18n/repository/message_zh_CN.properties b/support-files/i18n/repository/message_zh_CN.properties index 7b08079fde9..acfa170835c 100644 --- a/support-files/i18n/repository/message_zh_CN.properties +++ b/support-files/i18n/repository/message_zh_CN.properties @@ -46,6 +46,7 @@ 2115044=用户[{0}]尚未进行GITHUB OAUTH授权,请先授权 2115045=({0})类型代码库暂不支持OAUTH授权 2115046=用户({0})无权限在工程({1})下{2}代码库{3} +2115048=获取open copilot token 失败, 失败详情: {0} bkRequestFileSizeLimit=请求文件不能超过1M OperationAddCheckRuns=添加检测任务 OperationUpdateCheckRuns=更新检测任务 From bd91889cd929af99144821d357c0102680d0b247 Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Fri, 6 Dec 2024 15:15:21 +0800 Subject: [PATCH 2/8] =?UTF-8?q?feat:=20copilot=20=E7=BC=96=E8=BE=91?= =?UTF-8?q?=E5=99=A8=E6=94=AF=E6=8C=81=E5=85=8D=E7=99=BB=E5=BD=95=20#11290?= =?UTF-8?q?=20=E8=A1=A5=E5=85=85SQL?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sql/1001_ci_repository_ddl_mysql.sql | 2 +- .../2030_ci_repository-update_v3.0_mysql.sql | 35 +++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 support-files/sql/2004_v3.x/2030_ci_repository-update_v3.0_mysql.sql diff --git a/support-files/sql/1001_ci_repository_ddl_mysql.sql b/support-files/sql/1001_ci_repository_ddl_mysql.sql index d76cd4e5c15..ae72de2eb7f 100644 --- a/support-files/sql/1001_ci_repository_ddl_mysql.sql +++ b/support-files/sql/1001_ci_repository_ddl_mysql.sql @@ -144,7 +144,7 @@ CREATE TABLE IF NOT EXISTS `T_REPOSITORY_GIT_TOKEN` ( `EXPIRES_IN` bigint(20) DEFAULT NULL COMMENT '过期时间', `CREATE_TIME` datetime DEFAULT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'token的创建时间', PRIMARY KEY (`ID`), - UNIQUE KEY `USER_ID` (`USER_ID`) + UNIQUE KEY `T_REPOSITORY_GIT_TOKEN_UNIQUE` (`USER_ID`, `TOKEN_TYPE`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='工蜂commit checker表'; diff --git a/support-files/sql/2004_v3.x/2030_ci_repository-update_v3.0_mysql.sql b/support-files/sql/2004_v3.x/2030_ci_repository-update_v3.0_mysql.sql new file mode 100644 index 00000000000..42c292a9913 --- /dev/null +++ b/support-files/sql/2004_v3.x/2030_ci_repository-update_v3.0_mysql.sql @@ -0,0 +1,35 @@ +USE devops_ci_repository; +SET NAMES utf8mb4; + +DROP PROCEDURE IF EXISTS ci_repository_schema_update; + +DELIMITER + +CREATE PROCEDURE ci_repository_schema_update() +BEGIN + DECLARE db VARCHAR(100); + SET AUTOCOMMIT = 0; + SELECT DATABASE() INTO db; + + + IF EXISTS(SELECT 1 + FROM information_schema.statistics + WHERE TABLE_SCHEMA = db + AND TABLE_NAME = 'T_REPOSITORY_GIT_TOKEN' + AND INDEX_NAME = 'USER_ID') THEN + ALTER TABLE T_REPOSITORY_GIT_TOKEN DROP INDEX `USER_ID`; + END IF; + + IF NOT EXISTS(SELECT 1 + FROM information_schema.statistics + WHERE TABLE_SCHEMA = db + AND TABLE_NAME = 'T_REPOSITORY_GIT_TOKEN' + AND INDEX_NAME = 'T_REPOSITORY_GIT_TOKEN_UNIQUE') THEN + ALTER TABLE T_REPOSITORY_GIT_TOKEN ADD INDEX `T_REPOSITORY_GIT_TOKEN_UNIQUE` (`USER_ID`,`TOKEN_TYPE`); + END IF; + + COMMIT; +END +DELIMITER ; +COMMIT; +CALL ci_repository_schema_update(); From add584ef2436445083219dfccfeb5b7ef7716349 Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Fri, 6 Dec 2024 16:54:54 +0800 Subject: [PATCH 3/8] =?UTF-8?q?feat:=20copilot=20=E7=BC=96=E8=BE=91?= =?UTF-8?q?=E5=99=A8=E6=94=AF=E6=8C=81=E5=85=8D=E7=99=BB=E5=BD=95=20#11290?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/pojo/enums/TokenTypeEnum.kt | 4 +- .../pojo/oauth/RepositoryScmToken.kt | 50 +++++++++++ .../devops/repository/dao/GitTokenDao.kt | 21 +---- .../repository/dao/RepositoryScmTokenDao.kt | 87 +++++++++++++++++++ .../sql/1001_ci_repository_ddl_mysql.sql | 21 ++++- .../2030_ci_repository-update_v3.0_mysql.sql | 35 -------- 6 files changed, 162 insertions(+), 56 deletions(-) create mode 100644 src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/pojo/oauth/RepositoryScmToken.kt create mode 100644 src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/dao/RepositoryScmTokenDao.kt delete mode 100644 support-files/sql/2004_v3.x/2030_ci_repository-update_v3.0_mysql.sql diff --git a/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/pojo/enums/TokenTypeEnum.kt b/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/pojo/enums/TokenTypeEnum.kt index fc10f5b70bb..0d66c403582 100644 --- a/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/pojo/enums/TokenTypeEnum.kt +++ b/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/pojo/enums/TokenTypeEnum.kt @@ -29,15 +29,13 @@ package com.tencent.devops.repository.pojo.enums enum class TokenTypeEnum(val type: Int) { OAUTH(0), // oauth认证 - PRIVATE_KEY(1), // oauth认证 - COPILOT_TOKEN(2); // copilot token + PRIVATE_KEY(1); // privateKey认证 companion object { fun getTokenType(type: Int): String { return when (type) { 0 -> OAUTH.name 1 -> PRIVATE_KEY.name - 2 -> COPILOT_TOKEN.name else -> OAUTH.name } } diff --git a/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/pojo/oauth/RepositoryScmToken.kt b/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/pojo/oauth/RepositoryScmToken.kt new file mode 100644 index 00000000000..b0984dfcc41 --- /dev/null +++ b/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/pojo/oauth/RepositoryScmToken.kt @@ -0,0 +1,50 @@ +/* + * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. + * + * A copy of the MIT License is included in this file. + * + * + * Terms of the MIT License: + * --------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT + * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package com.tencent.devops.repository.pojo.oauth + +import com.fasterxml.jackson.annotation.JsonProperty +import io.swagger.v3.oas.annotations.media.Schema + +@Schema(title = "Token模型") +data class RepositoryScmToken( + @get:Schema(title = "鉴权token") + @JsonProperty("access_token") + var userId: String = "", + @get:Schema(title = "代码库类型") + var scmCode: String = "", + @get:Schema(title = "应用类型") + var appType: String = "", + @get:Schema(title = "鉴权token") + var accessToken: String = "", + @get:Schema(title = "刷新token") + var refreshToken: String = "", + @get:Schema(title = "过期时间") + val expiresIn: Long = 0L, + @get:Schema(title = "创建时间") + val createTime: Long? = 0L +) diff --git a/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/dao/GitTokenDao.kt b/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/dao/GitTokenDao.kt index f8a5642dea0..2376f6f7ae6 100644 --- a/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/dao/GitTokenDao.kt +++ b/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/dao/GitTokenDao.kt @@ -36,14 +36,10 @@ import java.time.LocalDateTime @Repository class GitTokenDao { - fun getAccessToken( - dslContext: DSLContext, - userId: String, - tokenType: String = DEFAULT_TOKEN_TYPE - ): TRepositoryGitTokenRecord? { + fun getAccessToken(dslContext: DSLContext, userId: String): TRepositoryGitTokenRecord? { with(TRepositoryGitToken.T_REPOSITORY_GIT_TOKEN) { return dslContext.selectFrom(this) - .where(USER_ID.eq(userId).and(TOKEN_TYPE.eq(tokenType))) + .where(USER_ID.eq(userId)) .fetchOne() } } @@ -77,20 +73,11 @@ class GitTokenDao { } } - fun deleteToken( - dslContext: DSLContext, - userId: String, - tokenType: String = DEFAULT_TOKEN_TYPE - ): Int { + fun deleteToken(dslContext: DSLContext, userId: String): Int { with(TRepositoryGitToken.T_REPOSITORY_GIT_TOKEN) { return dslContext.deleteFrom(this) - .where(USER_ID.eq(userId).and(TOKEN_TYPE.eq(tokenType))) + .where(USER_ID.eq(userId)) .execute() } } - - companion object { - // oauth授权后的默认token类型 - const val DEFAULT_TOKEN_TYPE = "bearer" - } } diff --git a/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/dao/RepositoryScmTokenDao.kt b/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/dao/RepositoryScmTokenDao.kt new file mode 100644 index 00000000000..2f9e334b1d9 --- /dev/null +++ b/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/dao/RepositoryScmTokenDao.kt @@ -0,0 +1,87 @@ +/* + * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. + * + * A copy of the MIT License is included in this file. + * + * + * Terms of the MIT License: + * --------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT + * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package com.tencent.devops.repository.dao + +import com.tencent.devops.model.repository.tables.TRepositoryScmToken +import com.tencent.devops.model.repository.tables.records.TRepositoryScmTokenRecord +import com.tencent.devops.repository.pojo.oauth.RepositoryScmToken +import org.jooq.DSLContext +import org.springframework.stereotype.Repository +import java.time.LocalDateTime + +@Repository +class RepositoryScmTokenDao { + fun getToken( + dslContext: DSLContext, + userId: String, + scmCode: String, + appType: String + ): TRepositoryScmTokenRecord? { + with(TRepositoryScmToken.T_REPOSITORY_SCM_TOKEN) { + return dslContext.selectFrom(this) + .where( + USER_ID.eq(userId) + .and(SCM_CODE.eq(scmCode)) + .and( + APP_TYPE.eq(appType) + ) + ) + .fetchOne() + } + } + + fun saveAccessToken(dslContext: DSLContext, scmToken: RepositoryScmToken): Int { + with(TRepositoryScmToken.T_REPOSITORY_SCM_TOKEN) { + return dslContext.insertInto( + this, + USER_ID, + SCM_CODE, + APP_TYPE, + ACCESS_TOKEN, + REFRESH_TOKEN, + EXPIRES_IN, + CREATE_TIME + ) + .values( + scmToken.userId, + scmToken.scmCode, + scmToken.appType, + scmToken.accessToken, + scmToken.refreshToken, + scmToken.expiresIn, + LocalDateTime.now() + ) + .onDuplicateKeyUpdate() + .set(ACCESS_TOKEN, scmToken.accessToken) + .set(REFRESH_TOKEN, scmToken.refreshToken) + .set(EXPIRES_IN, scmToken.expiresIn) + .set(UPDATE_TIME, LocalDateTime.now()) + .execute() + } + } +} diff --git a/support-files/sql/1001_ci_repository_ddl_mysql.sql b/support-files/sql/1001_ci_repository_ddl_mysql.sql index ae72de2eb7f..76f7fbcf8d3 100644 --- a/support-files/sql/1001_ci_repository_ddl_mysql.sql +++ b/support-files/sql/1001_ci_repository_ddl_mysql.sql @@ -144,7 +144,7 @@ CREATE TABLE IF NOT EXISTS `T_REPOSITORY_GIT_TOKEN` ( `EXPIRES_IN` bigint(20) DEFAULT NULL COMMENT '过期时间', `CREATE_TIME` datetime DEFAULT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'token的创建时间', PRIMARY KEY (`ID`), - UNIQUE KEY `T_REPOSITORY_GIT_TOKEN_UNIQUE` (`USER_ID`, `TOKEN_TYPE`) + UNIQUE KEY `USER_ID` (`USER_ID`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='工蜂commit checker表'; @@ -244,4 +244,23 @@ CREATE TABLE IF NOT EXISTS `T_REPOSITORY_WEBHOOK_REQUEST` PRIMARY KEY (`REQUEST_ID`, `CREATE_TIME`) ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COMMENT ='代码库WEBHOOK请求表'; + +-- ---------------------------- +-- Table structure for T_REPOSITORY_SCM_TOKEN +-- ---------------------------- + +CREATE TABLE IF NOT EXISTS `T_REPOSITORY_SCM_TOKEN` ( + `ID` bigint(20) NOT NULL AUTO_INCREMENT, + `USER_ID` varchar(64) NOT NULL DEFAULT '' COMMENT '用户名', + `SCM_CODE` varchar(64) NOT NULL DEFAULT '' COMMENT '代码库类型', + `APP_TYPE` varchar(64) NOT NULL DEFAULT '' COMMENT 'app类型', + `ACCESS_TOKEN` varchar(256) DEFAULT NULL COMMENT 'access token 密文', + `REFRESH_TOKEN` varchar(256) DEFAULT NULL COMMENT 'access refresh token', + `EXPIRES_IN` bigint(20) DEFAULT NULL COMMENT '过期时间', + `CREATE_TIME` datetime DEFAULT NULL COMMENT '创建时间', + `UPDATE_TIME` datetime DEFAULT NULL COMMENT '更新时间', + PRIMARY KEY (`ID`), + UNIQUE KEY `t_repository_scm_token_unique` (`USER_ID`,`SCM_CODE`,`APP_TYPE`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='代码仓库token表'; + SET FOREIGN_KEY_CHECKS = 1; diff --git a/support-files/sql/2004_v3.x/2030_ci_repository-update_v3.0_mysql.sql b/support-files/sql/2004_v3.x/2030_ci_repository-update_v3.0_mysql.sql deleted file mode 100644 index 42c292a9913..00000000000 --- a/support-files/sql/2004_v3.x/2030_ci_repository-update_v3.0_mysql.sql +++ /dev/null @@ -1,35 +0,0 @@ -USE devops_ci_repository; -SET NAMES utf8mb4; - -DROP PROCEDURE IF EXISTS ci_repository_schema_update; - -DELIMITER - -CREATE PROCEDURE ci_repository_schema_update() -BEGIN - DECLARE db VARCHAR(100); - SET AUTOCOMMIT = 0; - SELECT DATABASE() INTO db; - - - IF EXISTS(SELECT 1 - FROM information_schema.statistics - WHERE TABLE_SCHEMA = db - AND TABLE_NAME = 'T_REPOSITORY_GIT_TOKEN' - AND INDEX_NAME = 'USER_ID') THEN - ALTER TABLE T_REPOSITORY_GIT_TOKEN DROP INDEX `USER_ID`; - END IF; - - IF NOT EXISTS(SELECT 1 - FROM information_schema.statistics - WHERE TABLE_SCHEMA = db - AND TABLE_NAME = 'T_REPOSITORY_GIT_TOKEN' - AND INDEX_NAME = 'T_REPOSITORY_GIT_TOKEN_UNIQUE') THEN - ALTER TABLE T_REPOSITORY_GIT_TOKEN ADD INDEX `T_REPOSITORY_GIT_TOKEN_UNIQUE` (`USER_ID`,`TOKEN_TYPE`); - END IF; - - COMMIT; -END -DELIMITER ; -COMMIT; -CALL ci_repository_schema_update(); From e803d82d2e9ee923af13c3c11909ceb3371cfec3 Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Fri, 6 Dec 2024 18:17:41 +0800 Subject: [PATCH 4/8] =?UTF-8?q?feat:=20copilot=20=E7=BC=96=E8=BE=91?= =?UTF-8?q?=E5=99=A8=E6=94=AF=E6=8C=81=E5=85=8D=E7=99=BB=E5=BD=95=20#11290?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/pojo/enums/TokenAppTypeEnum.kt | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/pojo/enums/TokenAppTypeEnum.kt diff --git a/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/pojo/enums/TokenAppTypeEnum.kt b/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/pojo/enums/TokenAppTypeEnum.kt new file mode 100644 index 00000000000..cf506475ead --- /dev/null +++ b/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/pojo/enums/TokenAppTypeEnum.kt @@ -0,0 +1,36 @@ +/* + * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. + * + * A copy of the MIT License is included in this file. + * + * + * Terms of the MIT License: + * --------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT + * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package com.tencent.devops.repository.pojo.enums + +/** + * token 应用类型 + */ +enum class TokenAppTypeEnum { + OAUTH, // oauth认证 + COPILOT_OPEN_TOKEN; // copilot open token +} From 72e2c491fb6d6bb5791874ca92a294c1409ded6d Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Fri, 6 Dec 2024 18:40:05 +0800 Subject: [PATCH 5/8] =?UTF-8?q?feat:=20copilot=20=E7=BC=96=E8=BE=91?= =?UTF-8?q?=E5=99=A8=E6=94=AF=E6=8C=81=E5=85=8D=E7=99=BB=E5=BD=95=20#11290?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tencent/devops/repository/dao/RepositoryScmTokenDao.kt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/dao/RepositoryScmTokenDao.kt b/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/dao/RepositoryScmTokenDao.kt index 2f9e334b1d9..ab687342ba6 100644 --- a/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/dao/RepositoryScmTokenDao.kt +++ b/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/dao/RepositoryScmTokenDao.kt @@ -57,6 +57,7 @@ class RepositoryScmTokenDao { fun saveAccessToken(dslContext: DSLContext, scmToken: RepositoryScmToken): Int { with(TRepositoryScmToken.T_REPOSITORY_SCM_TOKEN) { + val now = LocalDateTime.now() return dslContext.insertInto( this, USER_ID, @@ -65,7 +66,8 @@ class RepositoryScmTokenDao { ACCESS_TOKEN, REFRESH_TOKEN, EXPIRES_IN, - CREATE_TIME + CREATE_TIME, + UPDATE_TIME ) .values( scmToken.userId, @@ -74,7 +76,8 @@ class RepositoryScmTokenDao { scmToken.accessToken, scmToken.refreshToken, scmToken.expiresIn, - LocalDateTime.now() + now, + now ) .onDuplicateKeyUpdate() .set(ACCESS_TOKEN, scmToken.accessToken) From b0d9adce9d96d379f42446662cc5defb4f91a1fa Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Fri, 6 Dec 2024 18:47:01 +0800 Subject: [PATCH 6/8] =?UTF-8?q?feat:=20copilot=20=E7=BC=96=E8=BE=91?= =?UTF-8?q?=E5=99=A8=E6=94=AF=E6=8C=81=E5=85=8D=E7=99=BB=E5=BD=95=20#11290?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tencent/devops/repository/dao/RepositoryScmTokenDao.kt | 4 +--- support-files/sql/1001_ci_repository_ddl_mysql.sql | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/dao/RepositoryScmTokenDao.kt b/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/dao/RepositoryScmTokenDao.kt index ab687342ba6..e17e9b2df05 100644 --- a/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/dao/RepositoryScmTokenDao.kt +++ b/src/backend/ci/core/repository/biz-repository/src/main/kotlin/com/tencent/devops/repository/dao/RepositoryScmTokenDao.kt @@ -47,9 +47,7 @@ class RepositoryScmTokenDao { .where( USER_ID.eq(userId) .and(SCM_CODE.eq(scmCode)) - .and( - APP_TYPE.eq(appType) - ) + .and(APP_TYPE.eq(appType)) ) .fetchOne() } diff --git a/support-files/sql/1001_ci_repository_ddl_mysql.sql b/support-files/sql/1001_ci_repository_ddl_mysql.sql index 76f7fbcf8d3..67477543e0e 100644 --- a/support-files/sql/1001_ci_repository_ddl_mysql.sql +++ b/support-files/sql/1001_ci_repository_ddl_mysql.sql @@ -261,6 +261,6 @@ CREATE TABLE IF NOT EXISTS `T_REPOSITORY_SCM_TOKEN` ( `UPDATE_TIME` datetime DEFAULT NULL COMMENT '更新时间', PRIMARY KEY (`ID`), UNIQUE KEY `t_repository_scm_token_unique` (`USER_ID`,`SCM_CODE`,`APP_TYPE`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='代码仓库token表'; +) ENGINE=INNODB DEFAULT CHARSET=utf8mb4 COMMENT='代码仓库token表'; SET FOREIGN_KEY_CHECKS = 1; From db67876106ee2cbf9d75e7cf65973ba632f38ea2 Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Mon, 9 Dec 2024 11:03:43 +0800 Subject: [PATCH 7/8] =?UTF-8?q?feat:=20copilot=20=E7=BC=96=E8=BE=91?= =?UTF-8?q?=E5=99=A8=E6=94=AF=E6=8C=81=E5=85=8D=E7=99=BB=E5=BD=95=20#11290?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tencent/devops/repository/pojo/enums/TokenAppTypeEnum.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/pojo/enums/TokenAppTypeEnum.kt b/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/pojo/enums/TokenAppTypeEnum.kt index cf506475ead..28e31c9fd03 100644 --- a/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/pojo/enums/TokenAppTypeEnum.kt +++ b/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/pojo/enums/TokenAppTypeEnum.kt @@ -31,6 +31,6 @@ package com.tencent.devops.repository.pojo.enums * token 应用类型 */ enum class TokenAppTypeEnum { - OAUTH, // oauth认证 + OAUTH2, // oauth2认证 COPILOT_OPEN_TOKEN; // copilot open token } From 31536c77742972226826909b45a3fb034d7d6ff4 Mon Sep 17 00:00:00 2001 From: hejieehe <904696180@qq.com> Date: Mon, 9 Dec 2024 14:12:37 +0800 Subject: [PATCH 8/8] =?UTF-8?q?feat:=20copilot=20=E7=BC=96=E8=BE=91?= =?UTF-8?q?=E5=99=A8=E6=94=AF=E6=8C=81=E5=85=8D=E7=99=BB=E5=BD=95=20#11290?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- support-files/sql/1001_ci_repository_ddl_mysql.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/support-files/sql/1001_ci_repository_ddl_mysql.sql b/support-files/sql/1001_ci_repository_ddl_mysql.sql index 67477543e0e..3d994cb272a 100644 --- a/support-files/sql/1001_ci_repository_ddl_mysql.sql +++ b/support-files/sql/1001_ci_repository_ddl_mysql.sql @@ -260,7 +260,7 @@ CREATE TABLE IF NOT EXISTS `T_REPOSITORY_SCM_TOKEN` ( `CREATE_TIME` datetime DEFAULT NULL COMMENT '创建时间', `UPDATE_TIME` datetime DEFAULT NULL COMMENT '更新时间', PRIMARY KEY (`ID`), - UNIQUE KEY `t_repository_scm_token_unique` (`USER_ID`,`SCM_CODE`,`APP_TYPE`) + UNIQUE KEY `UNIQ_USER_SCM_CODE_APP_TYPE` (`USER_ID`,`SCM_CODE`,`APP_TYPE`) ) ENGINE=INNODB DEFAULT CHARSET=utf8mb4 COMMENT='代码仓库token表'; SET FOREIGN_KEY_CHECKS = 1;