11package com .tencent .devops .scm .api .pojo .webhook .git ;
22
3+ import static com .tencent .devops .scm .api .constant .WebhookI18Code .GIT_PUSH_CREATE_EVENT_DESC ;
4+ import static com .tencent .devops .scm .api .constant .WebhookI18Code .GIT_PUSH_DELETE_EVENT_DESC ;
5+ import static com .tencent .devops .scm .api .constant .WebhookI18Code .GIT_PUSH_EVENT_DESC ;
36import static com .tencent .devops .scm .api .constant .WebhookOutputCode .BK_REPO_GIT_WEBHOOK_BRANCH ;
47import static com .tencent .devops .scm .api .constant .WebhookOutputCode .BK_REPO_GIT_WEBHOOK_COMMIT_ID ;
58import static com .tencent .devops .scm .api .constant .WebhookOutputCode .BK_REPO_GIT_WEBHOOK_PUSH_AFTER_COMMIT ;
2932import static com .tencent .devops .scm .api .constant .WebhookOutputCode .PIPELINE_WEBHOOK_COMMIT_MESSAGE ;
3033import static com .tencent .devops .scm .api .constant .WebhookOutputCode .PIPELINE_WEBHOOK_EVENT_TYPE ;
3134import static com .tencent .devops .scm .api .constant .WebhookOutputCode .PIPELINE_WEBHOOK_REVISION ;
35+ import static com .tencent .devops .scm .api .enums .EventAction .DELETE ;
3236
33- import com .tencent .devops .scm .api .constant .WebhookI18Code ;
3437import com .tencent .devops .scm .api .enums .EventAction ;
3538import com .tencent .devops .scm .api .pojo .Change ;
3639import com .tencent .devops .scm .api .pojo .Commit ;
@@ -70,6 +73,7 @@ public class GitPushHook implements Webhook {
7073 private String before ;
7174 private String after ;
7275 private Commit commit ;
76+ private String link ;
7377 private User sender ;
7478 private List <Commit > commits ;
7579 // 变更的文件路径
@@ -94,18 +98,14 @@ public String getUserName() {
9498
9599 @ Override
96100 public ScmI18Variable getEventDesc () {
97- String code = WebhookI18Code .GIT_PUSH_EVENT_DESC ;
98- if (action == EventAction .DELETE ) {
99- code = WebhookI18Code .GIT_PUSH_DELETE_EVENT_DESC ;
100- }
101101 List <String > params = Arrays .asList (
102102 GitUtils .trimRef (ref ),
103- commit . getLink () ,
103+ link ,
104104 GitUtils .getShortSha (commit .getSha ()),
105105 sender .getName ()
106106 );
107107 return ScmI18Variable .builder ()
108- .code (code )
108+ .code (getI18Code () )
109109 .params (params )
110110 .build ();
111111 }
@@ -137,7 +137,7 @@ public Map<String, Object> outputs() {
137137 outputParams .put (PIPELINE_GIT_REPO_URL , repo .getHttpUrl ());
138138 outputParams .put (PIPELINE_GIT_REF , "refs/heads/" + ref );
139139 outputParams .put (CI_BRANCH , ref );
140- if (action == EventAction . DELETE ) {
140+ if (action == DELETE ) {
141141 outputParams .put (PIPELINE_GIT_EVENT , "delete" );
142142 } else {
143143 outputParams .put (PIPELINE_GIT_EVENT , "push" );
@@ -169,4 +169,19 @@ public Map<String, Object> outputs() {
169169 public Boolean skipCi () {
170170 return skipCi ;
171171 }
172+
173+ private String getI18Code () {
174+ String code ;
175+ switch (action ) {
176+ case NEW_BRANCH :
177+ code = GIT_PUSH_CREATE_EVENT_DESC ;
178+ break ;
179+ case DELETE :
180+ code = GIT_PUSH_DELETE_EVENT_DESC ;
181+ break ;
182+ default :
183+ code = GIT_PUSH_EVENT_DESC ;
184+ }
185+ return code ;
186+ }
172187}
0 commit comments