@@ -37,7 +37,7 @@ public class EngagementService {
37
37
private static final String DEFAULT_BRANCH = "master" ;
38
38
private static final String ENGAGEMENT_FILE = "engagement.json" ;
39
39
private static final String STATUS_FILE = "status.json" ;
40
-
40
+
41
41
private String engagementPathPrefix ;
42
42
43
43
@ ConfigProperty (name = "engagements.repository.id" )
@@ -54,7 +54,7 @@ public class EngagementService {
54
54
55
55
@ Inject
56
56
FileService fileService ;
57
-
57
+
58
58
@ Inject
59
59
HookService hookService ;
60
60
@@ -63,15 +63,15 @@ public class EngagementService {
63
63
64
64
@ Inject
65
65
JsonMarshaller json ;
66
-
66
+
67
67
@ Inject
68
68
ConfigService configService ;
69
-
69
+
70
70
@ PostConstruct
71
71
public void setPathPrefix () {
72
72
Optional <Group > groupOption = groupService .getGitLabGroupByById (engagementRepositoryId );
73
-
74
- if (groupOption .isPresent ()) {
73
+
74
+ if (groupOption .isPresent ()) {
75
75
engagementPathPrefix = groupOption .get ().getFullPath ();
76
76
LOGGER .info ("Engagement repo set- to {}" , engagementPathPrefix );
77
77
} else {
@@ -94,8 +94,8 @@ public Project createEngagement(Engagement engagement, String author, String aut
94
94
repoFiles .add (createEngagmentFile (engagement ));
95
95
96
96
// create actions for multiple commit
97
- CommitMultiple commit = createCommitMultiple (repoFiles , project .getId (), DEFAULT_BRANCH , author ,
98
- authorEmail , project .isFirst (), commitMessageOptional );
97
+ CommitMultiple commit = createCommitMultiple (repoFiles , project .getId (), DEFAULT_BRANCH , author , authorEmail ,
98
+ project .isFirst (), commitMessageOptional );
99
99
100
100
if (LOGGER .isDebugEnabled ()) {
101
101
commit .getActions ().stream ().forEach (file -> LOGGER .debug ("Action File path :: {}" , file .getFilePath ()));
@@ -105,12 +105,12 @@ public Project createEngagement(Engagement engagement, String author, String aut
105
105
if (!fileService .createFiles (project .getId (), commit )) {
106
106
throw new UnexpectedGitLabResponseException ("failed to commit files for engagement creation." );
107
107
}
108
-
108
+
109
109
List <HookConfig > hookConfigs = configService .getHookConfig ();
110
110
hookConfigs .stream ().forEach (hookC -> {
111
- Hook hook = Hook .builder ().projectId (engagement .getProjectId ()).pushEvents (true )
112
- .url ( hookC . getBaseUrl ()). token (hookC .getToken ()).build ();
113
- if (project .isFirst ()) { //No need to check for existing hooks first time
111
+ Hook hook = Hook .builder ().projectId (engagement .getProjectId ()).pushEvents (true ). url ( hookC . getBaseUrl ())
112
+ .token (hookC .getToken ()).build ();
113
+ if (project .isFirst ()) { // No need to check for existing hooks first time
114
114
hookService .createProjectHook (engagement .getProjectId (), hook );
115
115
} else {
116
116
hookService .createOrUpdateProjectHook (engagement .getProjectId (), hook );
@@ -120,54 +120,55 @@ public Project createEngagement(Engagement engagement, String author, String aut
120
120
return project ;
121
121
122
122
}
123
-
123
+
124
124
public List <Commit > getCommitLog (String customerName , String engagementName ) {
125
125
String projectPath = GitLabPathUtils .getPath (engagementPathPrefix , customerName , engagementName );
126
126
return projectService .getCommitLog (projectPath );
127
127
}
128
-
128
+
129
129
public List <Hook > getHooks (String customer , String engagment ) {
130
130
Optional <Project > project = getProject (customer , engagment );
131
-
132
- if (project .isPresent ()) {
131
+
132
+ if (project .isPresent ()) {
133
133
return hookService .getProjectHooks (project .get ().getId ());
134
134
}
135
-
135
+
136
136
return new ArrayList <>();
137
137
}
138
-
138
+
139
139
public Response createHook (String customerName , String engagementName , Hook hook ) {
140
- Response created = Response .status (javax .ws .rs .core .Response .Status .BAD_REQUEST ).entity ("project doesn't exist" ).build ();
140
+ Response created = Response .status (javax .ws .rs .core .Response .Status .BAD_REQUEST ).entity ("project doesn't exist" )
141
+ .build ();
141
142
Optional <Project > optional = getProject (customerName , engagementName );
142
-
143
- if (optional .isPresent ()) {
143
+
144
+ if (optional .isPresent ()) {
144
145
List <Hook > hooks = hookService .getProjectHooks (optional .get ().getId ());
145
146
boolean hookExists = hooks .stream ().anyMatch (h -> h .getUrl ().equals (hook .getUrl ()));
146
- if (!hookExists ) {
147
+ if (!hookExists ) {
147
148
created = hookService .createProjectHook (optional .get ().getId (), hook );
148
149
}
149
150
}
150
-
151
+
151
152
return created ;
152
153
}
153
-
154
+
154
155
public Status getProjectStatus (String customerName , String engagementName ) {
155
156
Status status = null ;
156
- Optional <File > file = fileService .getFile (GitLabPathUtils .getPath (engagementPathPrefix , customerName , engagementName ), STATUS_FILE );
157
- if (file .isPresent ()) {
157
+ Optional <File > file = fileService
158
+ .getFile (GitLabPathUtils .getPath (engagementPathPrefix , customerName , engagementName ), STATUS_FILE );
159
+ if (file .isPresent ()) {
158
160
status = json .fromJson (file .get ().getContent (), Status .class );
159
161
}
160
-
162
+
161
163
return status ;
162
164
}
163
-
165
+
164
166
public Optional <Project > getProject (String customerName , String engagementName ) {
165
167
String fullPath = GitLabPathUtils .getPath (engagementPathPrefix , customerName , engagementName );
166
-
168
+
167
169
LOGGER .debug ("Full path {}" , fullPath );
168
170
return projectService .getProjectByIdOrPath (fullPath );
169
171
}
170
-
171
172
172
173
/**
173
174
* Gets all engagements from the base group Structure is BaseGroup - customer
@@ -181,17 +182,11 @@ public List<Engagement> getAllEngagements() {
181
182
182
183
List <Project > projects = projectService .getProjectsByGroup (engagementRepositoryId , true );
183
184
184
- return
185
- projects
186
- .parallelStream ()
187
- .map (project -> {
188
- return getEngagement (project , true );
189
- })
190
- .filter (optional -> optional .isPresent ())
191
- .map (optional -> {
192
- return optional .get ();
193
- })
194
- .collect (Collectors .toList ());
185
+ return projects .parallelStream ().map (project -> {
186
+ return getEngagement (project , true );
187
+ }).filter (optional -> optional .isPresent ()).map (optional -> {
188
+ return optional .get ();
189
+ }).collect (Collectors .toList ());
195
190
196
191
}
197
192
@@ -200,48 +195,48 @@ public Engagement getEngagement(String namespaceOrId, boolean includeStatus) {
200
195
201
196
Optional <Project > project = projectService .getProjectByIdOrPath (namespaceOrId );
202
197
203
- if (project .isPresent ()) {
198
+ if (project .isPresent ()) {
204
199
engagement = getEngagement (project .get (), includeStatus ).orElse (null );
205
200
}
206
201
207
202
return engagement ;
208
203
}
209
-
204
+
210
205
public Engagement getEngagement (String customerName , String engagementName , boolean includeStatus ) {
211
206
Engagement engagement = null ;
212
-
207
+
213
208
Optional <Project > project = getProject (customerName , engagementName );
214
-
215
- if (project .isPresent ()) {
209
+
210
+ if (project .isPresent ()) {
216
211
engagement = getEngagement (project .get (), includeStatus ).orElse (null );
217
212
}
218
-
213
+
219
214
return engagement ;
220
215
}
221
-
216
+
222
217
private Optional <Engagement > getEngagement (Project project , boolean includeStatus ) {
223
218
Engagement engagement = null ;
224
-
219
+
225
220
Optional <File > engagementFile = fileService .getFileAllow404 (project .getId (), ENGAGEMENT_FILE );
226
221
if (engagementFile .isPresent ()) {
227
222
engagement = json .fromJson (engagementFile .get ().getContent (), Engagement .class );
228
-
223
+
229
224
List <Commit > commits = projectService .getCommitLog (String .valueOf (engagement .getProjectId ()));
230
225
engagement .setCommits (commits );
231
226
}
232
-
233
- if (includeStatus && engagement != null ) {
227
+
228
+ if (includeStatus && engagement != null ) {
234
229
Optional <File > statusFile = fileService .getFileAllow404 (project .getId (), STATUS_FILE );
235
- if (statusFile .isPresent ()) {
230
+ if (statusFile .isPresent ()) {
236
231
engagement .setStatus (json .fromJson (statusFile .get ().getContent (), Status .class ));
237
232
}
238
233
}
239
-
234
+
240
235
return Optional .ofNullable (engagement );
241
236
}
242
237
243
238
private File createEngagmentFile (Engagement engagement ) {
244
- //Git api is read only here.
239
+ // Git api is read only here.
245
240
engagement .setCommits (null );
246
241
engagement .setStatus (null );
247
242
engagement .setCommitMessage (null );
@@ -259,7 +254,7 @@ private CommitMultiple createCommitMultiple(List<File> filesToCommit, Integer pr
259
254
// results
260
255
filesToCommit .stream ().forEach (file -> actions .add (createAction (file , isNew )));
261
256
262
- // use message if provided. otherwise, defaults
257
+ // use message if provided. otherwise, defaults
263
258
String commitMessage = commitMessageOptional
264
259
.orElse (isNew ? commitMessage ("Engagement created" ) : commitMessage ("Engagement updated" ));
265
260
@@ -281,7 +276,7 @@ private String stripPrefix(String in) {
281
276
}
282
277
return in ;
283
278
}
284
-
279
+
285
280
private String commitMessage (String message ) {
286
281
return String .format ("%s %s %s" , message , getEmoji (), getEmoji ());
287
282
}
0 commit comments