From 59efd9e011d3c11d18ee5d8c32f6981600133c52 Mon Sep 17 00:00:00 2001 From: Chris Tremblay Date: Thu, 26 Sep 2024 23:10:56 -0400 Subject: [PATCH] updates --- .../PetStoreAssistantBot.java | 8 +++- .../petstoreassistant/service/AzureDemo.java | 39 ++++++++++++++++++- .../petstoreassistant/service/IAzureDemo.java | 2 +- 3 files changed, 45 insertions(+), 4 deletions(-) diff --git a/petstore/petstoreassistant/src/main/java/com/chtrembl/petstoreassistant/PetStoreAssistantBot.java b/petstore/petstoreassistant/src/main/java/com/chtrembl/petstoreassistant/PetStoreAssistantBot.java index 819deac7..0f9dc7dc 100644 --- a/petstore/petstoreassistant/src/main/java/com/chtrembl/petstoreassistant/PetStoreAssistantBot.java +++ b/petstore/petstoreassistant/src/main/java/com/chtrembl/petstoreassistant/PetStoreAssistantBot.java @@ -201,9 +201,15 @@ protected CompletableFuture onMessageActivity(TurnContext turnContext) { dpResponse = this.azureDemo.getAzureResources(this.at1, azurePetStoreSessionInfo); } break; + case DISPLAY_ADO_PIPELINES_DEMO: + if (azurePetStoreSessionInfo != null) { + return turnContext.sendActivity( + MessageFactory.text("There is 1 Azure DevOps Pipeline, azure-petstoreautomation-regression-tests")).thenApply(sendResult -> null); + } case EXECUTE_ADO_PIPELINES_DEMO: if (azurePetStoreSessionInfo != null) { - dpResponse = this.azureDemo.executeDevopsPipeline(azurePetStoreSessionInfo); + //typically if this wasnt a quick demo we would find the right pipeline to execute based on verbal/text command + dpResponse = this.azureDemo.executeDevopsPipeline(at2, azurePetStoreSessionInfo); } break; case UPDATE_SHOPPING_CART: diff --git a/petstore/petstoreassistant/src/main/java/com/chtrembl/petstoreassistant/service/AzureDemo.java b/petstore/petstoreassistant/src/main/java/com/chtrembl/petstoreassistant/service/AzureDemo.java index 246c157b..ceed5a6d 100644 --- a/petstore/petstoreassistant/src/main/java/com/chtrembl/petstoreassistant/service/AzureDemo.java +++ b/petstore/petstoreassistant/src/main/java/com/chtrembl/petstoreassistant/service/AzureDemo.java @@ -103,9 +103,44 @@ public DPResponse getAzureResources(String at1, AzurePetStoreSessionInfo azurePe } @Override - public DPResponse executeDevopsPipeline(AzurePetStoreSessionInfo azurePetStoreSessionInfo) { + public DPResponse executeDevopsPipeline(String at2, AzurePetStoreSessionInfo azurePetStoreSessionInfo) { + LOGGER.info("executeDevopsPipeline invoked, text: {}", azurePetStoreSessionInfo.getNewText()); + DPResponse dpResponse = new DPResponse(); - dpResponse.setDpResponseText("I'm sorry, I wasn't able to execute the DevOps pipeline."); + try { + String adoResponse = this.adoClient.post() + .header("Content-Type", "application/json") + .header("Authorization", "Bearer " + at2) + .bodyValue("{\n" + // + " \"resources\": {\n" + // + " \"repositories\": {\n" + // + " \"self\": {\n" + // + " \"refName\": \"refs/heads/main\"\n" + // + " }\n" + // + " }\n" + // + " }\n" + // + "}") + .retrieve() + .bodyToMono(String.class) + .block(); + + dpResponse.setDpResponseText("Azure DevOps Pipeline executed successfully"); + + + LOGGER.info("executeDevopsPipeline response for text "); + } + catch (WebClientException webClientException) { + LOGGER.error("Error parsing getAzureResources response ", webClientException); + if(webClientException.getMessage().contains("429")) + { + dpResponse.setRateLimitExceeded(true); + } + + dpResponse.setDpResponseText("I'm sorry, I wasn't able to execute the Azure DevOps Pipeline, check at."); + } + catch (Exception e) { + LOGGER.error("Error parsing executeDevopsPipeline response azure " + azurePetStoreSessionInfo != null ? "session id: " + azurePetStoreSessionInfo.getId() + " id: " + azurePetStoreSessionInfo.getId() : "session id: null", e); + } return dpResponse; } } diff --git a/petstore/petstoreassistant/src/main/java/com/chtrembl/petstoreassistant/service/IAzureDemo.java b/petstore/petstoreassistant/src/main/java/com/chtrembl/petstoreassistant/service/IAzureDemo.java index 0f0fdf83..da0eb830 100644 --- a/petstore/petstoreassistant/src/main/java/com/chtrembl/petstoreassistant/service/IAzureDemo.java +++ b/petstore/petstoreassistant/src/main/java/com/chtrembl/petstoreassistant/service/IAzureDemo.java @@ -5,5 +5,5 @@ public interface IAzureDemo { public DPResponse getAzureResources(String at1, AzurePetStoreSessionInfo azurePetStoreSessionInfo); - public DPResponse executeDevopsPipeline(AzurePetStoreSessionInfo azurePetStoreSessionInfo); + public DPResponse executeDevopsPipeline(String at2, AzurePetStoreSessionInfo azurePetStoreSessionInfo); }