1
1
package com .dabsquared .gitlabjenkins .util ;
2
2
3
-
4
3
import com .dabsquared .gitlabjenkins .cause .CauseData ;
5
4
import com .dabsquared .gitlabjenkins .cause .GitLabWebHookCause ;
6
5
import com .dabsquared .gitlabjenkins .connection .GitLabConnection ;
@@ -42,10 +41,9 @@ public class CommitStatusUpdater {
42
41
43
42
private final static Logger LOGGER = Logger .getLogger (CommitStatusUpdater .class .getName ());
44
43
45
-
46
44
public static void updateCommitStatus (Run <?, ?> build , TaskListener listener , BuildState state , String name , List <GitLabBranchBuild > gitLabBranchBuilds , GitLabConnectionProperty connection ) {
47
45
GitLabClient client ;
48
- if (connection != null ) {
46
+ if (connection != null ) {
49
47
client = connection .getClient ();
50
48
} else {
51
49
client = getClient (build );
@@ -65,36 +63,38 @@ public static void updateCommitStatus(Run<?, ?> build, TaskListener listener, Bu
65
63
}
66
64
67
65
final String buildUrl = getBuildUrl (build );
68
- for (final GitLabBranchBuild gitLabBranchBuild : gitLabBranchBuilds ) {
69
- try {
70
- GitLabClient current_client = client ;
71
- if (gitLabBranchBuild .getConnection () != null ) {
72
- GitLabClient build_specific_client = gitLabBranchBuild .getConnection ().getClient ();
73
- if (build_specific_client != null ) {
74
- current_client = build_specific_client ;
66
+ if (gitLabBranchBuilds != null ) {
67
+ for (final GitLabBranchBuild gitLabBranchBuild : gitLabBranchBuilds ) {
68
+ try {
69
+ GitLabClient current_client = client ;
70
+ if (gitLabBranchBuild .getConnection () != null ) {
71
+ GitLabClient build_specific_client = gitLabBranchBuild .getConnection ().getClient ();
72
+ if (build_specific_client != null ) {
73
+ current_client = build_specific_client ;
74
+ }
75
75
}
76
- }
77
76
78
- String current_build_name = name ;
79
- if (gitLabBranchBuild .getName () != null ) {
80
- current_build_name = gitLabBranchBuild .getName ();
81
- }
77
+ String current_build_name = name ;
78
+ if (gitLabBranchBuild .getName () != null ) {
79
+ current_build_name = gitLabBranchBuild .getName ();
80
+ }
82
81
83
- if (existsCommit (current_client , gitLabBranchBuild .getProjectId (), gitLabBranchBuild .getRevisionHash ())) {
84
- LOGGER .log (Level .INFO , String .format ("Updating build '%s' to '%s'" , gitLabBranchBuild .getProjectId (),state ));
85
- current_client .changeBuildStatus (gitLabBranchBuild .getProjectId (), gitLabBranchBuild .getRevisionHash (), state , getBuildBranchOrTag (build ), current_build_name , buildUrl , state .name ());
82
+ if (existsCommit (current_client , gitLabBranchBuild .getProjectId (), gitLabBranchBuild .getRevisionHash ())) {
83
+ LOGGER .log (Level .INFO , String .format ("Updating build '%s' to '%s'" , gitLabBranchBuild .getProjectId (), state ));
84
+ current_client .changeBuildStatus (gitLabBranchBuild .getProjectId (), gitLabBranchBuild .getRevisionHash (), state , getBuildBranchOrTag (build ), current_build_name , buildUrl , state .name ());
85
+ }
86
+ } catch (WebApplicationException | ProcessingException e ) {
87
+ printf (listener , "Failed to update Gitlab commit status for project '%s': %s%n" , gitLabBranchBuild .getProjectId (), e .getMessage ());
88
+ LOGGER .log (Level .SEVERE , String .format ("Failed to update Gitlab commit status for project '%s'" , gitLabBranchBuild .getProjectId ()), e );
86
89
}
87
- } catch (WebApplicationException | ProcessingException e ) {
88
- printf (listener , "Failed to update Gitlab commit status for project '%s': %s%n" , gitLabBranchBuild .getProjectId (), e .getMessage ());
89
- LOGGER .log (Level .SEVERE , String .format ("Failed to update Gitlab commit status for project '%s'" , gitLabBranchBuild .getProjectId ()), e );
90
90
}
91
91
}
92
92
}
93
93
94
94
95
95
public static void updateCommitStatus (Run <?, ?> build , TaskListener listener , BuildState state , String name ) {
96
96
try {
97
- updateCommitStatus (build ,listener ,state ,name ,null ,null );
97
+ updateCommitStatus (build , listener , state , name , null , null );
98
98
} catch (IllegalStateException e ) {
99
99
printf (listener , "Failed to update Gitlab commit status: %s%n" , e .getMessage ());
100
100
}
@@ -271,6 +271,4 @@ private static List<GitLabBranchBuild> findBuildsFromUpstreamCauses(List<Cause>
271
271
}
272
272
return Collections .emptyList ();
273
273
}
274
-
275
-
276
274
}
0 commit comments