7
7
8
8
import javax .enterprise .context .ApplicationScoped ;
9
9
import javax .inject .Inject ;
10
- import javax .json .bind .JsonbBuilder ;
11
- import javax .json .bind .JsonbConfig ;
12
- import javax .json .bind .config .PropertyNamingStrategy ;
13
10
14
11
import org .eclipse .microprofile .config .inject .ConfigProperty ;
15
12
import org .slf4j .Logger ;
@@ -58,7 +55,7 @@ public class EngagementService {
58
55
JsonMarshaller json ;
59
56
60
57
// create an engagement
61
- public Project createEngagement (Engagement engagement ) {
58
+ public Project createEngagement (Engagement engagement , String author , String authorEmail ) {
62
59
63
60
// create project structure
64
61
Project project = createProjectStucture (engagement );
@@ -68,15 +65,15 @@ public Project createEngagement(Engagement engagement) {
68
65
List <File > templateFiles = new ArrayList <>();
69
66
templateFiles .add (createEngagmentFile (engagement ));
70
67
71
- if (LOGGER .isDebugEnabled ()) {
68
+ if (LOGGER .isDebugEnabled ()) {
72
69
templateFiles .stream ().forEach (file -> LOGGER .debug ("File path :: " + file .getFilePath ()));
73
70
}
74
71
75
72
// create actions for multiple commit
76
- CommitMultiple commit = createCommitMultiple (templateFiles , project .getId (), DEFAULT_BRANCH ,
77
- engagement . getEngagementLeadName (), engagement . getEngagementLeadEmail () , project .isFirst ());
73
+ CommitMultiple commit = createCommitMultiple (templateFiles , project .getId (), DEFAULT_BRANCH , author ,
74
+ authorEmail , project .isFirst ());
78
75
79
- if (LOGGER .isDebugEnabled ()) {
76
+ if (LOGGER .isDebugEnabled ()) {
80
77
commit .getActions ().stream ().forEach (file -> LOGGER .debug ("Action File path :: " + file .getFilePath ()));
81
78
}
82
79
@@ -90,14 +87,11 @@ public Project createEngagement(Engagement engagement) {
90
87
}
91
88
92
89
/**
93
- * Gets all engagements from the base group
94
- * Structure is
95
- * BaseGroup
96
- * - customer group
97
- * - engagement group
98
- * - project (repo)
99
- * - engagement file
100
- * This is search for all projects named 'iac' that our bot has access to. Then looking for the config data
90
+ * Gets all engagements from the base group Structure is BaseGroup - customer
91
+ * group - engagement group - project (repo) - engagement file This is search
92
+ * for all projects named 'iac' that our bot has access to. Then looking for the
93
+ * config data
94
+ *
101
95
* @return A list or engagements
102
96
*/
103
97
public List <Engagement > getAllEngagements () {
@@ -106,10 +100,10 @@ public List<Engagement> getAllEngagements() {
106
100
107
101
List <Engagement > engagementFiles = new ArrayList <>();
108
102
109
- for (ProjectSearchResults project : projects ) {
103
+ for (ProjectSearchResults project : projects ) {
110
104
LOGGER .debug ("project id {}" , project .getId ());
111
105
Optional <File > engagementFile = fileService .getFileAllow404 (project .getId (), "engagement.json" );
112
- if (engagementFile .isPresent ()) {
106
+ if (engagementFile .isPresent ()) {
113
107
engagementFiles .add (json .fromJson (engagementFile .get ().getContent (), Engagement .class ));
114
108
}
115
109
}
@@ -137,8 +131,8 @@ private Project createProjectStucture(Engagement engagement) {
137
131
.parentId (customerGroup .getId ()).build ());
138
132
139
133
// create project under project name group
140
- Project project = getOrCreateProject (projectGroup .getId (), ENGAGEMENT_PROJECT_NAME ,
141
- Project . builder () .name (ENGAGEMENT_PROJECT_NAME ).visibility ("private" ).namespaceId (projectGroup .getId ()).build ());
134
+ Project project = getOrCreateProject (projectGroup .getId (), ENGAGEMENT_PROJECT_NAME , Project . builder ()
135
+ .name (ENGAGEMENT_PROJECT_NAME ).visibility ("private" ).namespaceId (projectGroup .getId ()).build ());
142
136
143
137
// enable deployment key on project
144
138
projectService .enableDeploymentKeyOnProject (project .getId (), deployKey );
@@ -191,7 +185,8 @@ private CommitMultiple createCommitMultiple(List<File> filesToCommit, Integer pr
191
185
192
186
List <Action > actions = new ArrayList <>();
193
187
194
- // convert each file to action - parallelStream was bringing inconsistent results
188
+ // convert each file to action - parallelStream was bringing inconsistent
189
+ // results
195
190
filesToCommit .stream ().forEach (file -> actions .add (createAction (file , isNew )));
196
191
197
192
return CommitMultiple .builder ().id (projectId ).branch (branch ).commitMessage (commitMessage ()).actions (actions )
@@ -215,15 +210,16 @@ private String stripPrefix(String in) {
215
210
216
211
private String commitMessage () {
217
212
String COMMIT_MSG = "%s engagement update by git-api %s " ;
218
- return String .format (COMMIT_MSG , getEmoji (),getEmoji ());
213
+ return String .format (COMMIT_MSG , getEmoji (), getEmoji ());
219
214
}
220
215
221
216
private String getEmoji () {
222
217
String bear = "\ud83d \udc3b " ;
223
218
224
219
int bearCodePoint = bear .codePointAt (bear .offsetByCodePoints (0 , 0 ));
225
220
int mysteryAnimalCodePoint = bearCodePoint + new Random ().nextInt (144 );
226
- char mysteryEmoji [] = {Character .highSurrogate (mysteryAnimalCodePoint ), Character .lowSurrogate (mysteryAnimalCodePoint )};
221
+ char mysteryEmoji [] = { Character .highSurrogate (mysteryAnimalCodePoint ),
222
+ Character .lowSurrogate (mysteryAnimalCodePoint ) };
227
223
228
224
return String .valueOf (mysteryEmoji );
229
225
}
0 commit comments