-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4d9adbb
commit 24c9269
Showing
90 changed files
with
2,065 additions
and
656 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
escalation/jira-listener/src/main/java/io/rhdhorchestrator/jiralistener/EventNotifier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package io.rhdhorchestrator.jiralistener; | ||
|
||
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient; | ||
|
||
import io.cloudevents.CloudEvent; | ||
import io.cloudevents.jackson.JsonFormat; | ||
import jakarta.ws.rs.POST; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.Produces; | ||
|
||
@Path("/") | ||
@RegisterRestClient(configKey="ce-emitter") | ||
public interface EventNotifier { | ||
|
||
@POST | ||
@Produces(JsonFormat.CONTENT_TYPE) | ||
void emit(CloudEvent event); | ||
} |
66 changes: 66 additions & 0 deletions
66
...on/jira-listener/src/main/java/io/rhdhorchestrator/jiralistener/JiraListenerResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package io.rhdhorchestrator.jiralistener; | ||
|
||
import java.io.IOException; | ||
import java.lang.System.Logger; | ||
import java.lang.System.Logger.Level; | ||
import java.util.Map; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
import io.rhdhorchestrator.jiralistener.JiraListenerService.OnEventResponse; | ||
import io.rhdhorchestrator.jiralistener.model.JiraIssue; | ||
import io.rhdhorchestrator.jiralistener.model.WebhookEvent; | ||
import jakarta.inject.Inject; | ||
import jakarta.ws.rs.Consumes; | ||
import jakarta.ws.rs.POST; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.core.MediaType; | ||
import jakarta.ws.rs.core.Response; | ||
import jakarta.ws.rs.core.Response.Status; | ||
|
||
@Path("/") | ||
public class JiraListenerResource { | ||
private Logger logger = System.getLogger(JiraListenerResource.class.getName()); | ||
|
||
@Inject | ||
ObjectMapper mapper; | ||
|
||
@Inject | ||
JiraListenerService jiraListenerService; | ||
|
||
// Test endpoint used in dev mode when not specifying a K_SINK variable | ||
@POST | ||
@Consumes(MediaType.APPLICATION_JSON) | ||
@Path("/") | ||
public void test(Object any) { | ||
logger.log(Level.INFO, "RECEIVED " + any); | ||
} | ||
|
||
@POST | ||
@Consumes(MediaType.APPLICATION_JSON) | ||
@Path("/webhook/jira") | ||
public Response onEvent(Map<String, Object> requestBody) { | ||
logger.log(Level.INFO, "Received " + requestBody); | ||
|
||
try { | ||
WebhookEvent webhookEvent = mapper.readValue(mapper.writeValueAsBytes(requestBody), WebhookEvent.class); | ||
logger.log(Level.INFO, "Received " + webhookEvent); | ||
if (webhookEvent.getIssue() == null) { | ||
logger.log(Level.WARNING, "Discarded because of missing field: issue"); | ||
return Response.noContent().build(); | ||
} | ||
JiraIssue jiraIssue = webhookEvent.getIssue(); | ||
|
||
OnEventResponse response = jiraListenerService.onEvent(jiraIssue); | ||
if (response.eventAccepted) { | ||
return Response.ok(response.jiraTicketEventData).build(); | ||
} | ||
return Response.noContent().build(); | ||
} catch (IOException e) { | ||
return Response | ||
.status(Status.BAD_REQUEST.getStatusCode(), | ||
"Not a valid webhook event for a Jira issue: " + e.getMessage()) | ||
.build(); | ||
} | ||
} | ||
} |
Oops, something went wrong.