Search in sources :

Example 1 with Payload

use of com.walmartlabs.concord.server.events.github.Payload in project concord by walmartlabs.

the class GithubEventResource method onEvent.

@POST
@ApiOperation("Handles GitHub repository level events")
@Path("/webhook")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.TEXT_PLAIN)
@WithTimer
public String onEvent(@ApiParam Map<String, Object> data, @HeaderParam("X-GitHub-Delivery") String deliveryId, @HeaderParam("X-GitHub-Event") String eventName, @Context UriInfo uriInfo) {
    log.info("onEvent ['{}', '{}'] -> processing...", deliveryId, eventName);
    if ("ping".equalsIgnoreCase(eventName)) {
        return "ok";
    }
    if (executor.isDisabled(eventName)) {
        log.warn("event ['{}', '{}'] -> disabled", deliveryId, eventName);
        return "ok";
    }
    if (githubCfg.isLogEvents()) {
        auditLog.add(AuditObject.EXTERNAL_EVENT, AuditAction.ACCESS).field("source", EVENT_SOURCE).field("eventId", deliveryId).field("githubEvent", eventName).field("payload", data).log();
    }
    Payload payload = Payload.from(eventName, data);
    if (payload == null) {
        log.warn("event ['{}', '{}'] -> can't parse payload", deliveryId, eventName);
        return "ok";
    }
    List<GithubTriggerProcessor.Result> results = new ArrayList<>();
    processors.forEach(p -> p.process(eventName, payload, uriInfo, results));
    Supplier<UserEntry> initiatorSupplier = memo(new GithubEventInitiatorSupplier(userManager, ldapManager, payload));
    int startedProcesses = 0;
    for (GithubTriggerProcessor.Result r : results) {
        Event e = Event.builder().id(deliveryId).name(EVENT_SOURCE).attributes(r.event()).initiator(initiatorSupplier).build();
        List<PartialProcessKey> processes = executor.execute(e, r.triggers(), initiatorResolver, (t, cfg) -> {
            // if `useEventCommitId` is true then the process is forced to use the specified commit ID
            String commitId = MapUtils.getString(r.event(), COMMIT_ID_KEY);
            if (commitId != null && TriggerUtils.isUseEventCommitId(t)) {
                cfg.put(Constants.Request.REPO_COMMIT_ID, commitId);
                cfg.put(Constants.Request.REPO_BRANCH_OR_TAG, payload.getHead());
            }
            return cfg;
        }, new GithubExclusiveParamsResolver(payload));
        startedProcesses += processes.size();
    }
    startedProcessesPerEvent.update(startedProcesses);
    log.info("onEvent ['{}', '{}'] -> done, started process count: {}", deliveryId, eventName, startedProcesses);
    return "ok";
}
Also used : PartialProcessKey(com.walmartlabs.concord.server.sdk.PartialProcessKey) GithubTriggerProcessor(com.walmartlabs.concord.server.events.github.GithubTriggerProcessor) Payload(com.walmartlabs.concord.server.events.github.Payload) UserEntry(com.walmartlabs.concord.server.user.UserEntry) WithTimer(com.walmartlabs.concord.server.sdk.metrics.WithTimer) ApiOperation(io.swagger.annotations.ApiOperation)

Aggregations

GithubTriggerProcessor (com.walmartlabs.concord.server.events.github.GithubTriggerProcessor)1 Payload (com.walmartlabs.concord.server.events.github.Payload)1 PartialProcessKey (com.walmartlabs.concord.server.sdk.PartialProcessKey)1 WithTimer (com.walmartlabs.concord.server.sdk.metrics.WithTimer)1 UserEntry (com.walmartlabs.concord.server.user.UserEntry)1 ApiOperation (io.swagger.annotations.ApiOperation)1