Skip to content

Commit 648bd57

Browse files
committed
feat(pr-page): support inner git platform
1 parent 957225e commit 648bd57

3 files changed

Lines changed: 16 additions & 2 deletions

File tree

src/crates/core/src/service/review_platform/mod.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ pub enum ReviewPlatformError {
4040
pub enum ReviewPlatformKind {
4141
Github,
4242
Gitlab,
43+
Codehub,
4344
Gitcode,
4445
Unknown,
4546
}
@@ -49,6 +50,7 @@ impl ReviewPlatformKind {
4950
match self {
5051
Self::Github => "github",
5152
Self::Gitlab => "gitlab",
53+
Self::Codehub => "codehub",
5254
Self::Gitcode => "gitcode",
5355
Self::Unknown => "unknown",
5456
}
@@ -498,6 +500,7 @@ fn provider_for(platform: ReviewPlatformKind) -> &'static dyn ReviewProvider {
498500
match platform {
499501
ReviewPlatformKind::Github => &GithubProvider,
500502
ReviewPlatformKind::Gitlab => &GitlabProvider,
503+
ReviewPlatformKind::Codehub => &GitlabProvider,
501504
ReviewPlatformKind::Gitcode => &GitcodeProvider,
502505
ReviewPlatformKind::Unknown => &UnsupportedProvider,
503506
}
@@ -1124,6 +1127,7 @@ fn provider_context(
11241127
let api_base_url = match remote.platform {
11251128
ReviewPlatformKind::Github => "https://api.github.com".to_string(),
11261129
ReviewPlatformKind::Gitlab => format!("https://{}/api/v4", remote.host),
1130+
ReviewPlatformKind::Codehub => "https://codehub-y.huawei.com/api/v4".to_string(),
11271131
ReviewPlatformKind::Gitcode => "https://api.gitcode.com/api/v5".to_string(),
11281132
ReviewPlatformKind::Unknown => {
11291133
return Err(ReviewPlatformError::UnsupportedPlatform(remote.host));
@@ -1151,6 +1155,7 @@ fn env_token_for_platform(platform: ReviewPlatformKind) -> Option<String> {
11511155
let names: &[&str] = match platform {
11521156
ReviewPlatformKind::Github => &["GITHUB_TOKEN", "GH_TOKEN"],
11531157
ReviewPlatformKind::Gitlab => &["GITLAB_TOKEN", "GITLAB_PRIVATE_TOKEN"],
1158+
ReviewPlatformKind::Codehub => &["CODEHUB_TOKEN"],
11541159
ReviewPlatformKind::Gitcode => &["GITCODE_TOKEN"],
11551160
ReviewPlatformKind::Unknown => &[],
11561161
};
@@ -1353,7 +1358,11 @@ fn capabilities_for_remote(remote: &ReviewPlatformRemote) -> ReviewPlatformCapab
13531358
ReviewPlatformCapabilities {
13541359
can_create_review: has_token,
13551360
can_reply_to_thread: has_token,
1356-
can_resolve_thread: has_token && remote.platform == ReviewPlatformKind::Gitlab,
1361+
can_resolve_thread: has_token
1362+
&& matches!(
1363+
remote.platform,
1364+
ReviewPlatformKind::Gitlab | ReviewPlatformKind::Codehub
1365+
),
13571366
can_merge: false,
13581367
supports_draft_review: remote.platform == ReviewPlatformKind::Github,
13591368
}
@@ -1363,6 +1372,7 @@ fn platform_label(platform: ReviewPlatformKind) -> &'static str {
13631372
match platform {
13641373
ReviewPlatformKind::Github => "GitHub",
13651374
ReviewPlatformKind::Gitlab => "GitLab",
1375+
ReviewPlatformKind::Codehub => "CodeHub",
13661376
ReviewPlatformKind::Gitcode => "GitCode",
13671377
ReviewPlatformKind::Unknown => "Git",
13681378
}
@@ -1377,6 +1387,8 @@ fn parse_remote(
13771387
let host_lower = parsed.host.to_ascii_lowercase();
13781388
let platform = if host_lower.contains("github.com") {
13791389
ReviewPlatformKind::Github
1390+
} else if host_lower.contains("-y") && host_lower.contains("codehub") {
1391+
ReviewPlatformKind::Codehub
13801392
} else if host_lower.contains("gitlab") {
13811393
ReviewPlatformKind::Gitlab
13821394
} else if host_lower.contains("gitcode") {

src/web-ui/src/app/components/panels/review-platform/ReviewPlatformPanel.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,8 @@ function providerLabel(remote: ReviewPlatformRemote | ReviewPlatformAccount | nu
216216
return 'GitHub';
217217
case 'gitlab':
218218
return 'GitLab';
219+
case 'codehub':
220+
return 'CodeHub';
219221
case 'gitcode':
220222
return 'GitCode';
221223
default:

src/web-ui/src/infrastructure/api/service-api/ReviewPlatformAPI.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { createLogger } from '@/shared/utils/logger';
44

55
const log = createLogger('ReviewPlatformAPI');
66

7-
export type ReviewPlatformKind = 'github' | 'gitlab' | 'gitcode' | 'unknown';
7+
export type ReviewPlatformKind = 'github' | 'gitlab' | 'codehub' | 'gitcode' | 'unknown';
88
export type ReviewAuthState = 'not_connected' | 'not_required' | 'connected' | 'expired' | 'error' | 'unsupported';
99
export type ReviewAuthSource = 'env' | 'stored' | 'none' | 'unsupported';
1010
export type ReviewItemState = 'open' | 'merged' | 'closed' | 'draft';

0 commit comments

Comments
 (0)