Skip to content

Commit b1f28be

Browse files
committed
perf: 优化代码源webhook解析流程 #11694
1 parent 259b610 commit b1f28be

File tree

5 files changed

+123
-142
lines changed

5 files changed

+123
-142
lines changed

buildSrc/src/main/kotlin/Versions.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
object Release {
22
const val Group = "com.tencent.bk.devops.scm"
3-
const val Version = "1.0.2"
3+
const val Version = "1.0.3"
44
}
55

66
object Versions {

devops-scm-api/src/main/java/com/tencent/devops/scm/api/exception/ScmApiException.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
11
package com.tencent.devops.scm.api.exception;
22

3+
import lombok.Data;
4+
import lombok.Getter;
5+
36
/**
47
* scm api异常基类
58
*/
9+
@Getter
610
public class ScmApiException extends RuntimeException {
11+
int code;
12+
13+
public ScmApiException(String message, int code) {
14+
super(message);
15+
this.code = code;
16+
}
717

818
public ScmApiException(String message) {
919
super(message);

devops-scm-provider/devops-scm-provider-git/devops-scm-provider-tgit/src/main/java/com/tencent/devops/scm/provider/git/tgit/TGitApiTemplate.java

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,7 @@ public static <R> R execute(ScmProviderRepository repository, TGitApiFactory api
2525
TGitApi tGitApi = apiFactory.fromAuthProvider(TGitAuthProviderFactory.create(repo.getAuth()));
2626
return apiFunction.apply(repo, tGitApi);
2727
} catch (Throwable t) {
28-
if (t instanceof TGitApiException) {
29-
throw translateException((TGitApiException) t);
30-
} else {
31-
throw new ScmApiException(t);
32-
}
28+
throw handleThrowable(t);
3329
}
3430
}
3531

@@ -38,11 +34,7 @@ public static <R> R execute(IScmAuth auth, TGitApiFactory apiFactory, Function<T
3834
TGitApi tGitApi = apiFactory.fromAuthProvider(TGitAuthProviderFactory.create(auth));
3935
return apiFunction.apply(tGitApi);
4036
} catch (Throwable t) {
41-
if (t instanceof TGitApiException) {
42-
throw translateException((TGitApiException) t);
43-
} else {
44-
throw new ScmApiException(t);
45-
}
37+
throw handleThrowable(t);
4638
}
4739
}
4840

@@ -53,11 +45,7 @@ public static void execute(ScmProviderRepository repository, TGitApiFactory apiF
5345
TGitApi tGitApi = apiFactory.fromAuthProvider(TGitAuthProviderFactory.create(repo.getAuth()));
5446
apiConsumer.accept(repo, tGitApi);
5547
} catch (Throwable t) {
56-
if (t instanceof TGitApiException) {
57-
throw translateException((TGitApiException) t);
58-
} else {
59-
throw new ScmApiException(t);
60-
}
48+
throw handleThrowable(t);
6149
}
6250
}
6351

@@ -66,8 +54,16 @@ private static ScmApiException translateException(TGitApiException e) {
6654
case 404:
6755
return new NotFoundScmApiException(e.getMessage());
6856
default:
69-
return new ScmApiException(e);
57+
return new ScmApiException(e.getMessage(), e.getStatusCode());
7058

7159
}
7260
}
61+
62+
private static ScmApiException handleThrowable(Throwable t) {
63+
if (t instanceof TGitApiException) {
64+
return translateException((TGitApiException) t);
65+
} else {
66+
return new ScmApiException(t);
67+
}
68+
}
7369
}

0 commit comments

Comments
 (0)