|
1 | 1 | package io.mixeway.mixewayflowapi.api.webhook.controller; |
2 | 2 |
|
3 | 3 | import ch.qos.logback.core.spi.ScanException; |
| 4 | +import com.fasterxml.jackson.databind.ObjectMapper; |
4 | 5 | import io.mixeway.mixewayflowapi.api.webhook.dto.GHMergeEventDTO; |
5 | 6 | import io.mixeway.mixewayflowapi.api.webhook.dto.GHPushEventDTO; |
6 | | -import io.mixeway.mixewayflowapi.api.webhook.dto.GLMergeEventDTO; |
7 | | -import io.mixeway.mixewayflowapi.api.webhook.dto.GLPushEventDTO; |
8 | 7 | import io.mixeway.mixewayflowapi.api.webhook.service.GitHubWebhookService; |
9 | 8 | import lombok.RequiredArgsConstructor; |
10 | 9 | import lombok.extern.log4j.Log4j2; |
11 | | -import org.springframework.http.HttpStatus; |
| 10 | +import org.springframework.http.MediaType; |
12 | 11 | import org.springframework.http.ResponseEntity; |
13 | 12 | import org.springframework.validation.annotation.Validated; |
14 | | -import org.springframework.web.bind.annotation.PostMapping; |
15 | | -import org.springframework.web.bind.annotation.RequestBody; |
16 | | -import org.springframework.web.bind.annotation.RestController; |
| 13 | +import org.springframework.web.bind.annotation.*; |
17 | 14 |
|
18 | 15 | import java.io.IOException; |
19 | | -import java.util.List; |
20 | 16 |
|
21 | 17 | @RestController |
22 | 18 | @RequiredArgsConstructor |
23 | 19 | @Validated |
24 | 20 | @Log4j2 |
25 | 21 | public class GitHubWebhookController { |
| 22 | + |
26 | 23 | private final GitHubWebhookService gitHubWebhookService; |
| 24 | + private final ObjectMapper objectMapper; |
| 25 | + |
| 26 | + @PostMapping(value = "/api/v1/webhook/github/push", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE) |
| 27 | + public ResponseEntity<?> pushEventGH(@RequestParam("payload") String payload) |
| 28 | + throws ScanException, IOException, InterruptedException { |
27 | 29 |
|
28 | | - @PostMapping("/api/v1/webhook/github/push") |
29 | | - public ResponseEntity<?> pushEventGH(@RequestBody List<GHPushEventDTO> ghPushEventDTOS) throws ScanException, IOException, InterruptedException { |
30 | | - gitHubWebhookService.processPush(ghPushEventDTOS); |
31 | | - return new ResponseEntity<>(HttpStatus.OK); |
| 30 | + GHPushEventDTO ghPushEventDTO = objectMapper.readValue(payload, GHPushEventDTO.class); |
| 31 | + gitHubWebhookService.processPush(ghPushEventDTO); |
| 32 | + return ResponseEntity.ok().build(); |
32 | 33 | } |
33 | 34 |
|
34 | | - @PostMapping("/api/v1/webhook/github/merge") |
35 | | - public ResponseEntity<?> mergeEventGH( @RequestBody GHMergeEventDTO ghMergeEventDTO) throws ScanException, IOException, InterruptedException { |
| 35 | + @PostMapping(value = "/api/v1/webhook/github/merge", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE) |
| 36 | + public ResponseEntity<?> mergeEventGH(@RequestParam("payload") String payload) |
| 37 | + throws ScanException, IOException, InterruptedException { |
| 38 | + |
| 39 | + GHMergeEventDTO ghMergeEventDTO = objectMapper.readValue(payload, GHMergeEventDTO.class); |
36 | 40 | log.info("[GitHub Merge] Merge event for {}", ghMergeEventDTO.getRepository().getId()); |
37 | 41 | gitHubWebhookService.processMerge(ghMergeEventDTO); |
38 | | - return new ResponseEntity<>(HttpStatus.OK); |
| 42 | + return ResponseEntity.ok().build(); |
39 | 43 | } |
40 | 44 | } |
0 commit comments