Source:
private void handleBitbucketServerEvent(Event event, Map postedEvent) { String repoProject = ""; String slug = ""; String hash = ""; String branch = ""; if (!event.content.containsKey("event_type")) { return; } String eventType = event.content.get("event_type").toString(); if (eventType == "repo:refs_changed") { BitbucketServerRefsChangedEvent refsChangedEvent = objectMapper.convertValue(event.content, BitbucketServerRefsChangedEvent.class); if (refsChangedEvent.repository != null) { repoProject = emptyOrDefault(refsChangedEvent.repository.name, ""); slug = emptyOrDefault(refsChangedEvent.repository.slug, ""); } if (refsChangedEvent.changes.size() > 0) { BitbucketServerRefsChangedEvent.Change change = refsChangedEvent.changes.get(0); hash = emptyOrDefault(change.toHash, ""); if (change.ref != null) { branch = emptyOrDefault(change.ref.id, ""); } } } else if (eventType == "pr:merged") { BitbucketServerPrMergedEvent prMergedEvent = objectMapper.convertValue(event.content, BitbucketServerPrMergedEvent.class); if (prMergedEvent.pullRequest != null && prMergedEvent.pullRequest.toRef != null) { BitbucketServerPrMergedEvent.Ref toRef = prMergedEvent.pullRequest.toRef; branch = emptyOrDefault(toRef.id,""); if (toRef.repository != null) { repoProject = emptyOrDefault(toRef.repository.name, ""); slug = emptyOrDefault(toRef.repository.slug, ""); } } if (prMergedEvent.pullRequest != null && prMergedEvent.pullRequest.properties != null) { BitbucketServerPrMergedEvent.Properties properties = prMergedEvent.pullRequest.properties; if (properties.mergeCommit != null) { hash = emptyOrDefault(properties.mergeCommit.id, ""); } } } event.content.put("repoProject", repoProject); event.content.put("slug", slug); event.content.put("hash", hash); event.content.put("branch", branch); }

Target:
private void handleBitbucketServerEvent(Event event, Map postedEvent) { String repoProject = ""; String slug = ""; String hash = ""; String branch = ""; if (!event.content.containsKey("event_type")) { return; } String eventType = event.content.get("event_type").toString(); if (eventType == "repo:refs_changed") { BitbucketServerRefsChangedEvent refsChangedEvent = objectMapper.convertValue(event.content, BitbucketServerRefsChangedEvent.class); if (refsChangedEvent.repository != null) { repoProject = emptyOrDefault(refsChangedEvent.repository.project.key, ""); slug = emptyOrDefault(refsChangedEvent.repository.slug, ""); } if (!refsChangedEvent.changes.isEmpty()) { BitbucketServerRefsChangedEvent.Change change = refsChangedEvent.changes.get(0); hash = emptyOrDefault(change.toHash, ""); if (change.ref != null) { branch = emptyOrDefault(change.ref.id, "").replace("refs/heads/", ""); } } } else if (eventType == "pr:merged") { BitbucketServerPrMergedEvent prMergedEvent = objectMapper.convertValue(event.content, BitbucketServerPrMergedEvent.class); if (prMergedEvent.pullRequest != null && prMergedEvent.pullRequest.toRef != null) { BitbucketServerPrMergedEvent.Ref toRef = prMergedEvent.pullRequest.toRef; branch = emptyOrDefault(toRef.id,"").replace("refs/heads/", ""); if (toRef.repository != null) { repoProject = emptyOrDefault(toRef.repository.project.key, ""); slug = emptyOrDefault(toRef.repository.slug, ""); } } if (prMergedEvent.pullRequest != null && prMergedEvent.pullRequest.properties != null) { BitbucketServerPrMergedEvent.Properties properties = prMergedEvent.pullRequest.properties; if (properties.mergeCommit != null) { hash = emptyOrDefault(properties.mergeCommit.id, ""); } } } event.content.put("repoProject", repoProject); event.content.put("slug", slug); event.content.put("hash", hash); event.content.put("branch", branch); }