From eb0ddbd7293eeefebe954946e1f2ccc605ec6f0c Mon Sep 17 00:00:00 2001 From: VWA Software internet Date: Tue, 19 Apr 2022 14:04:11 +0200 Subject: [PATCH 1/2] =?UTF-8?q?Include=20the=20PluginController=20Area=20w?= =?UTF-8?q?hen=20searching=20for=20matching=20surface=E2=80=A6=20(#12218)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Routing/ControllerActionSearcher.cs | 22 ++++++++++++++++--- .../Routing/IControllerActionSearcher.cs | 6 +++++ .../Routing/UmbracoRouteValueTransformer.cs | 2 +- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/Umbraco.Web.Website/Routing/ControllerActionSearcher.cs b/src/Umbraco.Web.Website/Routing/ControllerActionSearcher.cs index 5c758a948c..bf7c0aff59 100644 --- a/src/Umbraco.Web.Website/Routing/ControllerActionSearcher.cs +++ b/src/Umbraco.Web.Website/Routing/ControllerActionSearcher.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.Linq; using Microsoft.AspNetCore.Http; @@ -31,13 +32,20 @@ namespace Umbraco.Cms.Web.Website.Routing _actionSelector = actionSelector; } + /// /// Determines if a custom controller can hijack the current route /// /// The controller type to find - public ControllerActionDescriptor Find(HttpContext httpContext, string controller, string action) + public ControllerActionDescriptor Find(HttpContext httpContext, string controller, string action) => Find(httpContext, controller, action, null); + + /// + /// Determines if a custom controller can hijack the current route + /// + /// The controller type to find + public ControllerActionDescriptor Find(HttpContext httpContext, string controller, string action, string area) { - IReadOnlyList candidates = FindControllerCandidates(httpContext, controller, action, DefaultActionName); + IReadOnlyList candidates = FindControllerCandidates(httpContext, controller, action, DefaultActionName, area); if (candidates.Count > 0) { @@ -47,6 +55,7 @@ namespace Umbraco.Cms.Web.Website.Routing return null; } + /// /// Return a list of controller candidates that match the custom controller and action names /// @@ -54,7 +63,8 @@ namespace Umbraco.Cms.Web.Website.Routing HttpContext httpContext, string customControllerName, string customActionName, - string defaultActionName) + string defaultActionName, + string area = null) { // Use aspnetcore's IActionSelector to do the finding since it uses an optimized cache lookup var routeValues = new RouteValueDictionary @@ -62,6 +72,12 @@ namespace Umbraco.Cms.Web.Website.Routing [ControllerToken] = customControllerName, [ActionToken] = customActionName, // first try to find the custom action }; + + if (area != null) + { + routeValues[AreaToken] = area; + } + var routeData = new RouteData(routeValues); var routeContext = new RouteContext(httpContext) { diff --git a/src/Umbraco.Web.Website/Routing/IControllerActionSearcher.cs b/src/Umbraco.Web.Website/Routing/IControllerActionSearcher.cs index b272b4afd3..1b50638fff 100644 --- a/src/Umbraco.Web.Website/Routing/IControllerActionSearcher.cs +++ b/src/Umbraco.Web.Website/Routing/IControllerActionSearcher.cs @@ -1,3 +1,4 @@ +using System; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.Controllers; @@ -5,6 +6,11 @@ namespace Umbraco.Cms.Web.Website.Routing { public interface IControllerActionSearcher { + ControllerActionDescriptor Find(HttpContext httpContext, string controller, string action); + + ControllerActionDescriptor Find(HttpContext httpContext, string controller, string action, string area) + => Find(httpContext, controller, action); + } } diff --git a/src/Umbraco.Web.Website/Routing/UmbracoRouteValueTransformer.cs b/src/Umbraco.Web.Website/Routing/UmbracoRouteValueTransformer.cs index 60384de752..bb00f958cf 100644 --- a/src/Umbraco.Web.Website/Routing/UmbracoRouteValueTransformer.cs +++ b/src/Umbraco.Web.Website/Routing/UmbracoRouteValueTransformer.cs @@ -240,7 +240,7 @@ namespace Umbraco.Cms.Web.Website.Routing [ActionToken] = postedInfo.ActionName }; - ControllerActionDescriptor surfaceControllerDescriptor = _controllerActionSearcher.Find(httpContext, postedInfo.ControllerName, postedInfo.ActionName); + ControllerActionDescriptor surfaceControllerDescriptor = _controllerActionSearcher.Find(httpContext, postedInfo.ControllerName, postedInfo.ActionName, postedInfo.Area); if (surfaceControllerDescriptor == null) { From 16a02e08273d901b8c253ee6ef6742f7c14f3dad Mon Sep 17 00:00:00 2001 From: Sebastiaan Janssen Date: Thu, 21 Apr 2022 14:36:19 +0200 Subject: [PATCH 2/2] Update pr-first-response.yml --- .github/workflows/pr-first-response.yml | 52 ++++++++++++++++++------- 1 file changed, 38 insertions(+), 14 deletions(-) diff --git a/.github/workflows/pr-first-response.yml b/.github/workflows/pr-first-response.yml index f54c8b91ba..b2161c0d79 100644 --- a/.github/workflows/pr-first-response.yml +++ b/.github/workflows/pr-first-response.yml @@ -8,19 +8,43 @@ jobs: send-response: runs-on: ubuntu-latest steps: - - name: Fetch random comment 🗣️ - uses: JamesIves/fetch-api-data-action@v2.1.0 - with: - ENDPOINT: https://collaboratorsv2.euwest01.umbraco.io/umbraco/api/comments/PostComment - CONFIGURATION: '{ "method": "POST", "headers": {"Authorization": "Bearer ${{ secrets.OUR_BOT_API_TOKEN }}", "Content-Type": "application/json" }, "body": { "repo": "${{ github.repository }}", "number": "${{ github.event.number }}", "actor": "${{ github.actor }}", "commentType": "opened-pr-first-comment"} }' - - name: Add PR comment - if: "${{ env.fetch-api-data != '' }}" - uses: actions/github-script@v5 + - name: Install dependencies + run: | + npm install node-fetch@2 + - name: Fetch random comment 🗣️ and add it to the PR + uses: actions/github-script@v6 with: script: | - github.rest.issues.createComment({ - issue_number: context.issue.number, - owner: context.repo.owner, - repo: context.repo.repo, - body: `${{ env.fetch-api-data }}` - }) \ No newline at end of file + const fetch = require('node-fetch') + + const response = await fetch('https://collaboratorsv2.euwest01.umbraco.io/umbraco/api/comments/PostComment', { + method: 'post', + body: JSON.stringify({ + repo: '${{ github.repository }}', + number: '${{ github.event.number }}', + actor: '${{ github.actor }}', + commentType: 'opened-pr-first-comment' + }), + headers: { + 'Authorization': 'Bearer ${{ secrets.OUR_BOT_API_TOKEN }}', + 'Content-Type': 'application/json' + } + }); + + try { + const data = await response.text(); + + if(response.status === 200 && data !== '') { + github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: data + }); + } else { + console.log("Status code did not indicate success:", response.status); + console.log("Returned data:", data); + } + } catch(error) { + console.log(error); + }