-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from mcanoy/webhooks
Webhooks + reload on configmap change
- Loading branch information
Showing
25 changed files
with
373 additions
and
188 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
24 changes: 24 additions & 0 deletions
24
src/main/java/com/redhat/labs/lodestar/config/rest/client/EngagementApiRestClient.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,24 @@ | ||
package com.redhat.labs.lodestar.config.rest.client; | ||
|
||
import com.redhat.labs.lodestar.model.GitlabHook; | ||
import org.apache.http.NoHttpResponseException; | ||
import org.eclipse.microprofile.faulttolerance.Retry; | ||
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient; | ||
|
||
import javax.ws.rs.PUT; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.WebApplicationException; | ||
import javax.ws.rs.core.Response; | ||
import java.util.List; | ||
|
||
@Retry(maxRetries = 5, delay = 1200, retryOn = NoHttpResponseException.class, abortOn = WebApplicationException.class) | ||
@RegisterRestClient(configKey = "engagements.api") | ||
@Produces("application/json") | ||
public interface EngagementApiRestClient { | ||
|
||
@PUT | ||
@Path("/api/v1/engagements/gitlab-webhooks") | ||
Response updateWebhooks(List<GitlabHook> webhooks); | ||
|
||
} |
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
23 changes: 23 additions & 0 deletions
23
src/main/java/com/redhat/labs/lodestar/model/GitlabHook.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,23 @@ | ||
package com.redhat.labs.lodestar.model; | ||
|
||
import lombok.*; | ||
import lombok.experimental.SuperBuilder; | ||
|
||
@Data | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@EqualsAndHashCode | ||
public class GitlabHook { | ||
private String name; | ||
private String baseUrl; | ||
private boolean pushEvent; | ||
private String pushEventsBranchFilter; | ||
private String token; | ||
|
||
/** | ||
* Should the webhook be enabled after an engagement is archived | ||
*/ | ||
private boolean enabledAfterArchive; | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/com/redhat/labs/lodestar/model/GitlabHookConfiguration.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,21 @@ | ||
package com.redhat.labs.lodestar.model; | ||
|
||
import com.redhat.labs.lodestar.utils.MarshalUtils; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.experimental.SuperBuilder; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@SuperBuilder | ||
@Getter | ||
public class GitlabHookConfiguration extends ConfigMap { | ||
|
||
@Builder.Default | ||
private List<GitlabHook> hooks = new ArrayList<>(); | ||
|
||
public void loadFromConfigMap() { | ||
hooks = MarshalUtils.convertToHookList(getContent()); | ||
} | ||
} |
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
28 changes: 28 additions & 0 deletions
28
src/main/java/com/redhat/labs/lodestar/resource/GitlabHookConfigResource.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,28 @@ | ||
package com.redhat.labs.lodestar.resource; | ||
|
||
import com.redhat.labs.lodestar.model.GitlabHook; | ||
import com.redhat.labs.lodestar.service.GitlabHookService; | ||
|
||
import javax.inject.Inject; | ||
import javax.ws.rs.Consumes; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.core.MediaType; | ||
import javax.ws.rs.core.Response; | ||
import java.util.List; | ||
|
||
@Path("/api/v1/configs/webhooks") | ||
@Produces(MediaType.APPLICATION_JSON) | ||
@Consumes(MediaType.APPLICATION_JSON) | ||
public class GitlabHookConfigResource { | ||
|
||
@Inject | ||
GitlabHookService gitlabHookService; | ||
|
||
@GET | ||
public Response get() { | ||
List<GitlabHook> webhooks = gitlabHookService.getWebhooks(); | ||
return Response.ok(webhooks).header("x-total-webhooks", webhooks.size()).build(); | ||
} | ||
} |
Oops, something went wrong.