Skip to content

Commit cd7e109

Browse files
committed
add commits to engagement and add separate call
1 parent 01fbbea commit cd7e109

File tree

9 files changed

+136
-4
lines changed

9 files changed

+136
-4
lines changed

src/main/java/com/redhat/labs/omp/models/Engagement.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import java.util.List;
44

5+
import com.redhat.labs.omp.models.gitlab.Commit;
6+
57
import lombok.AllArgsConstructor;
68
import lombok.Builder;
79
import lombok.Data;
@@ -37,5 +39,6 @@ public class Engagement {
3739
private List<EngagementUser> engagementUsers;
3840

3941
private Status status;
42+
private List<Commit> commits;
4043

4144
}

src/main/java/com/redhat/labs/omp/models/gitlab/Commit.java

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,36 @@
22

33
import javax.json.bind.annotation.JsonbProperty;
44

5-
public class Commit extends File {
65

7-
@JsonbProperty("action")
8-
public FileAction action;
6+
import lombok.AllArgsConstructor;
7+
import lombok.Builder;
8+
import lombok.Data;
9+
import lombok.NoArgsConstructor;
10+
11+
@Data
12+
@Builder
13+
@NoArgsConstructor
14+
@AllArgsConstructor
15+
public class Commit {
16+
17+
private String id;
18+
@JsonbProperty("short_id")
19+
private String shortId;
20+
private String title;
21+
@JsonbProperty("author_name")
22+
private String authorName;
23+
@JsonbProperty("author_email")
24+
private String authorEmail;
25+
@JsonbProperty("committer_name")
26+
private String commiterName;
27+
@JsonbProperty("committer_email")
28+
private String commiterEmail;
29+
@JsonbProperty("authored_date")
30+
private String authoredDate;
31+
@JsonbProperty("committed_date")
32+
private String commitDate;
33+
private String message;
34+
@JsonbProperty("web_url")
35+
private String url;
936

1037
}

src/main/java/com/redhat/labs/omp/resource/EngagementResource.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
import com.redhat.labs.omp.models.Engagement;
2727
import com.redhat.labs.omp.models.Status;
28+
import com.redhat.labs.omp.models.gitlab.Commit;
2829
import com.redhat.labs.omp.models.gitlab.Hook;
2930
import com.redhat.labs.omp.models.gitlab.Project;
3031
import com.redhat.labs.omp.service.EngagementService;
@@ -82,6 +83,16 @@ public Response createProjectHook(Hook hook, @PathParam("customer") String custo
8283
return response;
8384
}
8485

86+
@GET
87+
@Path("/customer/{customer}/{engagement}/commits")
88+
@Counted(name = "get-engagement-commits", description = "Count of get engagement commits")
89+
@Timed(name = "performedEngagementCommitsGet", description = "Time to get engagement commits", unit = MetricUnits.MILLISECONDS)
90+
public Response getEngagementCommits(@PathParam("customer") String customer, @PathParam("engagement") String engagement) {
91+
92+
List<Commit> commitList = engagementService.getCommitLog(customer, engagement);
93+
return Response.ok().entity(commitList).build();
94+
}
95+
8596
@GET
8697
@Path("customer/{customer}/{engagement}/hooks")
8798
@Counted(name = "get-hook", description = "Count of get-hook requests")

src/main/java/com/redhat/labs/omp/rest/client/GitLabService.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;
1818
import org.jboss.resteasy.annotations.jaxrs.PathParam;
1919

20+
import com.redhat.labs.omp.models.gitlab.Commit;
2021
import com.redhat.labs.omp.models.gitlab.CommitMultiple;
2122
import com.redhat.labs.omp.models.gitlab.DeployKey;
2223
import com.redhat.labs.omp.models.gitlab.File;
@@ -175,6 +176,12 @@ File updateFile(@PathParam("id") @Encoded Integer projectId, @PathParam("file_pa
175176
@Path("/projects/{id}/repository/commits")
176177
@Produces("application/json")
177178
Response commitMultipleFiles(@PathParam("id") @Encoded Integer projectId, CommitMultiple commit);
179+
180+
@GET
181+
@Logged
182+
@Path("/projects/{id}/repository/commits")
183+
@Produces("application/json")
184+
List<Commit> getCommitLog(@PathParam("id") @Encoded String projectId);
178185

179186
// Deploy Keys
180187

src/main/java/com/redhat/labs/omp/service/EngagementService.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import com.redhat.labs.omp.models.Engagement;
2020
import com.redhat.labs.omp.models.Status;
2121
import com.redhat.labs.omp.models.gitlab.Action;
22+
import com.redhat.labs.omp.models.gitlab.Commit;
2223
import com.redhat.labs.omp.models.gitlab.CommitMultiple;
2324
import com.redhat.labs.omp.models.gitlab.File;
2425
import com.redhat.labs.omp.models.gitlab.FileAction;
@@ -118,6 +119,11 @@ public Project createEngagement(Engagement engagement, String author, String aut
118119

119120
}
120121

122+
public List<Commit> getCommitLog(String customerName, String engagementName) {
123+
String projectPath = getPath(customerName, engagementName);
124+
return projectService.getCommitLog(projectPath);
125+
}
126+
121127
public List<Hook> getHooks(String customer, String engagment) {
122128
Optional<Project> project = getProject(customer, engagment);
123129

@@ -204,6 +210,9 @@ private Optional<Engagement> getEngagement(Project project, boolean includeStatu
204210
Optional<File> engagementFile = fileService.getFileAllow404(project.getId(), ENGAGEMENT_FILE);
205211
if (engagementFile.isPresent()) {
206212
engagement = json.fromJson(engagementFile.get().getContent(), Engagement.class);
213+
214+
List<Commit> commits = projectService.getCommitLog(String.valueOf(engagement.getProjectId()));
215+
engagement.setCommits(commits);
207216
}
208217

209218
if(includeStatus && engagement != null) {

src/main/java/com/redhat/labs/omp/service/ProjectService.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import org.slf4j.Logger;
1212
import org.slf4j.LoggerFactory;
1313

14+
import com.redhat.labs.omp.models.gitlab.Commit;
1415
import com.redhat.labs.omp.models.gitlab.DeployKey;
1516
import com.redhat.labs.omp.models.gitlab.Project;
1617
import com.redhat.labs.omp.models.gitlab.ProjectSearchResults;
@@ -121,5 +122,9 @@ public void enableDeploymentKeyOnProject(Integer projectId, Integer deployKey) {
121122
gitLabService.enableDeployKey(projectId, deployKey);
122123
gitLabService.updateDeployKey(projectId, deployKey, DeployKey.builder().title("LodeStar DK").canPush(true).build());
123124
}
125+
126+
public List<Commit> getCommitLog(String projectId) {
127+
return gitLabService.getCommitLog(projectId);
128+
}
124129

125130
}

src/test/java/com/redhat/labs/omp/mocks/MockGitLabService.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.redhat.labs.omp.mocks;
22

3+
import java.lang.reflect.ParameterizedType;
4+
import java.lang.reflect.Type;
35
import java.nio.charset.StandardCharsets;
46
import java.util.ArrayList;
57
import java.util.List;
@@ -11,6 +13,9 @@
1113

1214
import org.eclipse.microprofile.rest.client.inject.RestClient;
1315

16+
import com.fasterxml.jackson.core.type.TypeReference;
17+
import com.redhat.labs.omp.config.JsonMarshaller;
18+
import com.redhat.labs.omp.models.gitlab.Commit;
1419
import com.redhat.labs.omp.models.gitlab.CommitMultiple;
1520
import com.redhat.labs.omp.models.gitlab.DeployKey;
1621
import com.redhat.labs.omp.models.gitlab.File;
@@ -32,7 +37,6 @@ public class MockGitLabService implements GitLabService {
3237

3338
@Override
3439
public Response getProjects() {
35-
// TODO Auto-generated method stub
3640
return null;
3741
}
3842

@@ -296,4 +300,14 @@ public Response updateDeployKey(Integer projectId, Integer deployKeyId, DeployKe
296300
return null;
297301
}
298302

303+
@Override
304+
public List<Commit> getCommitLog(String projectId) {
305+
if("top/dog/jello/lemon/iac".equals(projectId)) {
306+
String content = ResourceLoader.load("commits.yaml");
307+
List<Commit> commitList = new JsonMarshaller().fromYaml(content, Commit.class);
308+
return commitList;
309+
}
310+
return null;
311+
}
312+
299313
}

src/test/java/com/redhat/labs/omp/resource/EngagementResourceTest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,25 @@ void testGetProjectSuccess() {
130130
+ "\"status\":{\"messages\":[\"This is message 1\",\"This is message 2\",\"This is message 3\"],\"openshift_api\":\"https://console.s11.core.rht-labs.com/\",\"openshift_web_console\":\"https://console.s11.core.rht-labs.com/\","
131131
+ "\"overall_status\":\"green\"},\"technical_lead_email\":\"[email protected]\",\"technical_lead_name\":\"Wendel Clark\"}"));
132132
}
133+
134+
@Test
135+
void testGetCommitsSuccess() {
136+
given()
137+
.when()
138+
.contentType(ContentType.JSON)
139+
.get("/api/v1/engagements/customer/jello/lemon/commits")
140+
.then()
141+
.statusCode(200)
142+
.body(is("[{\"author_email\":\"[email protected]\",\"author_name\":\"bot\",\"authored_date\":\"2020-06-16T00:12:27.000+00:00\",\"committed_date\":\"2020-06-16T00:12:27.000+00:00\",\"id\":\"551eefc6e367aa2ad3c56bdd7229c7bc525d4f0c\","
143+
+ "\"message\":\"Auto-update generated files\",\"short_id\":\"551eefc6\",\"title\":\"Auto-update generated files\",\"web_url\":\"https://gitlab.example.com/store/jello/lemon/iac/-/commit/551eefc6e367aa2ad3c56bdd7229c7bc525d4f0c\"},"
144+
+ "{\"author_email\":\"[email protected]\",\"author_name\":\"Mitch Marner\",\"authored_date\":\"2020-06-16T00:12:18.000+00:00\",\"committed_date\":\"2020-06-16T00:12:18.000+00:00\","
145+
+ "\"id\":\"5178ffab3566ac591af95c3383d1c5916de4a3a9\",\"message\":\"Update engagement.json\",\"short_id\":\"5178ffab\",\"title\":\"Update engagement.json\","
146+
+ "\"web_url\":\"https://gitlab.example.com/store/jello/lemon/iac/-/commit/5178ffab3566ac591af95c3383d1c5916de4a3a9\"},{\"author_email\":\"[email protected]\",\"author_name\":\"John Tavares\","
147+
+ "\"authored_date\":\"2020-06-11T16:46:19.000+00:00\",\"committed_date\":\"2020-06-11T16:46:19.000+00:00\",\"id\":\"7865570dc63b1463d9fb4d02bd09ff46d244e694\",\"message\":\"Update status.json\","
148+
+ "\"short_id\":\"7865570d\",\"title\":\"Update status.json\",\"web_url\":\"https://gitlab.example.com/store/jello/lemon/iac/-/commit/7865570dc63b1463d9fb4d02bd09ff46d244e694\"},{\"author_email\":\"[email protected]\","
149+
+ "\"author_name\":\"Mitch Marner\",\"authored_date\":\"2020-06-04T22:34:10.000+00:00\",\"committed_date\":\"2020-06-04T22:34:10.000+00:00\",\"id\":\"dd0cc0fa7868210e2eb5a030f07cc0221dd6bc9f\","
150+
+ "\"message\":\"Bump OCP version (jacob test)\",\"short_id\":\"dd0cc0fa\",\"title\":\"Bump OCP version (test)\",\"web_url\":\"https://gitlab.example.com/store/jello/lemon/iac/-/commit/dd0cc0fa7868210e2eb5a030f07cc0221dd6bc9f\"}]"));
151+
}
133152

134153

135154
}

src/test/resources/commits.yaml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
- authorEmail: [email protected]
3+
authorName: bot
4+
authoredDate: '2020-06-16T00:12:27.000+00:00'
5+
commitDate: '2020-06-16T00:12:27.000+00:00'
6+
id: 551eefc6e367aa2ad3c56bdd7229c7bc525d4f0c
7+
message: 'Auto-update generated files'
8+
shortId: 551eefc6
9+
title: Auto-update generated files
10+
url: https://gitlab.example.com/store/jello/lemon/iac/-/commit/551eefc6e367aa2ad3c56bdd7229c7bc525d4f0c
11+
- authorEmail: [email protected]
12+
authorName: Mitch Marner
13+
authoredDate: '2020-06-16T00:12:18.000+00:00'
14+
commitDate: '2020-06-16T00:12:18.000+00:00'
15+
id: 5178ffab3566ac591af95c3383d1c5916de4a3a9
16+
message: Update engagement.json
17+
shortId: 5178ffab
18+
title: Update engagement.json
19+
url: https://gitlab.example.com/store/jello/lemon/iac/-/commit/5178ffab3566ac591af95c3383d1c5916de4a3a9
20+
- authorEmail: [email protected]
21+
authorName: John Tavares
22+
authoredDate: '2020-06-11T16:46:19.000+00:00'
23+
commitDate: '2020-06-11T16:46:19.000+00:00'
24+
id: 7865570dc63b1463d9fb4d02bd09ff46d244e694
25+
message: Update status.json
26+
shortId: 7865570d
27+
title: Update status.json
28+
url: https://gitlab.example.com/store/jello/lemon/iac/-/commit/7865570dc63b1463d9fb4d02bd09ff46d244e694
29+
- authorEmail: [email protected]
30+
authorName: Mitch Marner
31+
authoredDate: '2020-06-04T22:34:10.000+00:00'
32+
commitDate: '2020-06-04T22:34:10.000+00:00'
33+
id: dd0cc0fa7868210e2eb5a030f07cc0221dd6bc9f
34+
message: Bump OCP version (jacob test)
35+
shortId: dd0cc0fa
36+
title: Bump OCP version (test)
37+
url: https://gitlab.example.com/store/jello/lemon/iac/-/commit/dd0cc0fa7868210e2eb5a030f07cc0221dd6bc9f

0 commit comments

Comments
 (0)