Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【PAC】feat:代码库支持重置授权 #8145 #9525

Merged
merged 27 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
a9fd003
【PAC】feat:代码库支持重置授权 #8145
mingshewhe Aug 14, 2023
6a73443
【PAC】feat:代码库支持重置授权 #8145
hejieehe Jun 5, 2023
c34042a
【PAC】feat:代码库支持重置授权 #8145
hejieehe Jun 7, 2023
5215f8b
【PAC】feat:代码库支持重置授权 #8145
mingshewhe Aug 14, 2023
f3ad01f
【PAC】feat:代码库支持重置授权 #8145
hejieehe Jun 9, 2023
f28727e
【PAC】feat:代码库支持重置授权 #8145
mingshewhe Aug 18, 2023
e6f5599
Merge branch 'master' of https://github.com/TencentBlueKing/bk-ci int…
hejieehe Aug 25, 2023
a13a46c
【PAC】feat:代码库支持重置授权 #8145
hejieehe Sep 12, 2023
3c8bd76
【PAC】feat:代码库支持重置授权 #8145
hejieehe Sep 19, 2023
8d4a387
【PAC】feat:代码库支持重置授权 #8145
hejieehe Oct 10, 2023
df23f2c
【PAC】feat:代码库支持重置授权 #8145
hejieehe Oct 16, 2023
18d03b3
【PAC】feat:代码库支持重置授权 #8145
hejieehe Oct 16, 2023
082dc11
【PAC】feat:代码库支持重置授权 #8145
hejieehe Oct 16, 2023
002a31b
【PAC】feat:代码库支持重置授权 #8145
hejieehe Oct 16, 2023
499c86e
【PAC】feat:代码库支持重置授权 #8145
hejieehe Oct 23, 2023
ae897c2
【PAC】feat:代码库支持重置授权 #8145
hejieehe Oct 23, 2023
e2e1787
【PAC】feat:代码库支持重置授权 #8145
hejieehe Oct 23, 2023
a652d07
【PAC】feat:代码库支持重置授权 #8145
hejieehe Nov 3, 2023
ab7ab2b
【PAC】feat:代码库支持重置授权 #8145
hejieehe Nov 3, 2023
760b1b4
Merge branch 'master' of https://github.com/TencentBlueKing/bk-ci int…
hejieehe Nov 9, 2023
bbc9f0e
【PAC】feat:代码库支持重置授权 TencentBlueKing#8145
hejieehe Nov 9, 2023
5303a8d
Merge remote-tracking branch 'mingshewhe/feat_8145' into feat_8145
hejieehe Nov 10, 2023
7bc2e83
【PAC】feat:代码库支持重置授权 TencentBlueKing#8145
hejieehe Nov 13, 2023
7ec0b14
Merge branch 'feat_8145' of https://github.com/mingshewhe/bk-ci into …
hejieehe Nov 13, 2023
578d460
Merge branch 'master' of https://github.com/TencentBlueKing/bk-ci int…
hejieehe Nov 13, 2023
5495519
【PAC】feat:代码库支持重置授权 #8145
hejieehe Nov 20, 2023
ed979ce
【PAC】feat:代码库支持重置授权 #8145
hejieehe Nov 20, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ object CommonMessageCode {

const val GET_PROJECT_INFO = "bkGetProjectInfo" // 获取项目详情
const val GET_COMMIT_REVIEW_INFO = "bkGetCommitReviewInfo" // 获取Commit Review详情
const val GET_SESSION_INFO = "bkGetSessionInfo" // 获取会话详情

const val OPERATION_BRANCH = "bkOperationBranch" // 拉分支
const val OPERATION_TAG = "bkOperationTag" // 拉标签
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import com.tencent.devops.scm.pojo.GitMrChangeInfo
import com.tencent.devops.scm.pojo.GitMrInfo
import com.tencent.devops.scm.pojo.GitMrReviewInfo
import com.tencent.devops.scm.pojo.GitProjectInfo
import com.tencent.devops.scm.pojo.GitSession
import com.tencent.devops.scm.pojo.RevisionInfo

@Suppress("ALL")
Expand Down Expand Up @@ -90,4 +91,6 @@ interface IScm {
fun getProjectInfo(projectName: String): GitProjectInfo? = null

fun getCommitReviewInfo(crId: Long): GitCommitReviewInfo? = null

fun getGitSession(): GitSession? = null
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import com.tencent.devops.scm.pojo.GitMrChangeInfo
import com.tencent.devops.scm.pojo.GitMrInfo
import com.tencent.devops.scm.pojo.GitMrReviewInfo
import com.tencent.devops.scm.pojo.GitProjectInfo
import com.tencent.devops.scm.pojo.GitSession
import com.tencent.devops.scm.pojo.RevisionInfo
import com.tencent.devops.scm.utils.code.git.GitUtils.urlEncode
import org.eclipse.jgit.api.Git
Expand Down Expand Up @@ -320,6 +321,16 @@ class CodeGitScmImpl constructor(
)
}

override fun getGitSession(): GitSession? {
val url = "session"
return gitApi.getGitSession(
host = apiUrl,
url = url,
username = privateKey!!,
password = passPhrase!!
)
}

companion object {
private val logger = LoggerFactory.getLogger(CodeGitScmImpl::class.java)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import com.tencent.devops.scm.pojo.GitMrChangeInfo
import com.tencent.devops.scm.pojo.GitMrInfo
import com.tencent.devops.scm.pojo.GitMrReviewInfo
import com.tencent.devops.scm.pojo.GitProjectInfo
import com.tencent.devops.scm.pojo.GitSession
import com.tencent.devops.scm.pojo.RevisionInfo
import com.tencent.devops.scm.utils.code.git.GitUtils
import com.tencent.devops.scm.utils.code.git.GitUtils.urlEncode
Expand Down Expand Up @@ -301,6 +302,16 @@ class CodeTGitScmImpl constructor(
)
}

override fun getGitSession(): GitSession? {
val url = "session"
return gitApi.getGitSession(
host = apiUrl,
url = url,
username = privateKey!!,
password = passPhrase!!
)
}

companion object {
private val logger = LoggerFactory.getLogger(CodeTGitScmImpl::class.java)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import com.tencent.devops.scm.pojo.GitMrChangeInfo
import com.tencent.devops.scm.pojo.GitMrInfo
import com.tencent.devops.scm.pojo.GitMrReviewInfo
import com.tencent.devops.scm.pojo.GitProjectInfo
import com.tencent.devops.scm.pojo.GitSession
import com.tencent.devops.scm.pojo.TapdWorkItem
import io.micrometer.core.instrument.MeterRegistry
import io.micrometer.core.instrument.Tag
Expand Down Expand Up @@ -659,4 +660,28 @@ open class GitApi {
)
)
}

fun getGitSession(
host: String,
url: String,
username: String,
password: String
): GitSession? {
val body = JsonUtil.toJson(
mapOf(
"login" to username,
"password" to password
),
false
)
val request = post(host, "", url, body)
val responseBody = getBody(
getMessageByLocale(CommonMessageCode.GET_SESSION_INFO),
request
).ifBlank {
logger.warn("get session is blank, please check the username and password")
return null
}
return JsonUtil.getObjectMapper().readValue(responseBody)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* 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.scm.pojo

import com.fasterxml.jackson.annotation.JsonProperty
import io.swagger.annotations.ApiModel
import io.swagger.annotations.ApiModelProperty

@ApiModel("工蜂会话信息")
data class GitSession(
val id: String,
@ApiModelProperty("邮箱地址")
val email: String,
@ApiModelProperty("用户名")
val username: String,
@JsonProperty("private_token")
val privateToken: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* 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.scm.pojo

import com.tencent.devops.common.api.enums.ScmType
import io.swagger.annotations.ApiParam

data class RepoSessionRequest(
@ApiParam("仓库类型", required = true)
val type: ScmType,
@ApiParam("username", required = true)
val username: String,
@ApiParam("password", required = true)
val password: String,
@ApiParam("url", required = true)
val url: String
)
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,17 @@ object GitUtils {
commitId.substring(0, 8)
}
}

/**
* 校验代码库url
*/
fun diffRepoUrl(
sourceRepoUrl: String,
targetRepoUrl: String
): Boolean {
val sourceRepoInfo = GitUtils.getDomainAndRepoName(sourceRepoUrl)
val targetRepoInfo = GitUtils.getDomainAndRepoName(targetRepoUrl)
return sourceRepoInfo.first != targetRepoInfo.first ||
sourceRepoInfo.second != targetRepoInfo.second
}
}
Loading