From d4d447ff19308e729f9a3248e6b6f9278492a902 Mon Sep 17 00:00:00 2001 From: "penify-dev[bot]" <146478655+penify-dev[bot]@users.noreply.github.com> Date: Sat, 3 Aug 2024 01:36:41 +0100 Subject: [PATCH] [Penify]: Setting up Automated AI-Driven Documentation for GitHub! (#232) * Penify config file * CSharpier format --------- Co-authored-by: penify-dev[bot] <146478655+penify-dev[bot]@users.noreply.github.com> Co-authored-by: Guilherme Branco Stracini Co-authored-by: gstraccini[bot] <51682887+gstraccini[bot]@users.noreply.github.com> --- .config/dotnet-tools.json | 13 ++++++++++ .../workflows/snorkell-auto-documentation.yml | 19 ++++++++++++++ .../Controllers/UploadController.cs | 6 ++--- .../Filters/DisableFormValueModelBinding.cs | 7 +++--- .../Helpers/MultipartRequestHelper.cs | 22 ++++++++++------ POCUploadStream/Helpers/UploadHelper.cs | 25 +++++++++++++------ POCUploadStream/Models/WeatherForecast.cs | 2 +- POCUploadStream/Pages/Error.cshtml.cs | 2 +- POCUploadStream/Program.cs | 3 +-- POCUploadStream/Startup.cs | 4 +-- 10 files changed, 73 insertions(+), 30 deletions(-) create mode 100644 .config/dotnet-tools.json create mode 100644 .github/workflows/snorkell-auto-documentation.yml diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json new file mode 100644 index 0000000..155e425 --- /dev/null +++ b/.config/dotnet-tools.json @@ -0,0 +1,13 @@ +{ + "version": 1, + "isRoot": true, + "tools": { + "csharpier": { + "version": "0.28.2", + "commands": [ + "dotnet-csharpier" + ], + "rollForward": false + } + } +} \ No newline at end of file diff --git a/.github/workflows/snorkell-auto-documentation.yml b/.github/workflows/snorkell-auto-documentation.yml new file mode 100644 index 0000000..926c7e5 --- /dev/null +++ b/.github/workflows/snorkell-auto-documentation.yml @@ -0,0 +1,19 @@ +# This workflow will improvise current file with AI genereated documentation and Create new PR + +name: Penify - Revolutionizing Documentation on GitHub + +on: + push: + branches: ["main"] + workflow_dispatch: + +jobs: + Documentation: + runs-on: ubuntu-latest + steps: + - name: Penify DocGen Client + uses: SingularityX-ai/snorkell-documentation-client@v1.0.0 + with: + client_id: ${{ secrets.SNORKELL_CLIENT_ID }} + api_key: ${{ secrets.SNORKELL_API_KEY }} + branch_name: "main" \ No newline at end of file diff --git a/POCUploadStream/Controllers/UploadController.cs b/POCUploadStream/Controllers/UploadController.cs index f0ecbac..7b2b441 100644 --- a/POCUploadStream/Controllers/UploadController.cs +++ b/POCUploadStream/Controllers/UploadController.cs @@ -1,8 +1,8 @@ -using Microsoft.AspNetCore.Http.Features; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Mvc; using POCUploadStream.Filters; using POCUploadStream.Helpers; -using System.Threading.Tasks; namespace POCUploadStream.Controllers { @@ -19,4 +19,4 @@ public async Task Upload() return Ok(new { Success = true }); } } -} \ No newline at end of file +} diff --git a/POCUploadStream/Filters/DisableFormValueModelBinding.cs b/POCUploadStream/Filters/DisableFormValueModelBinding.cs index ce769b8..50ede4b 100644 --- a/POCUploadStream/Filters/DisableFormValueModelBinding.cs +++ b/POCUploadStream/Filters/DisableFormValueModelBinding.cs @@ -1,6 +1,6 @@ -using Microsoft.AspNetCore.Mvc.Filters; +using System; +using Microsoft.AspNetCore.Mvc.Filters; using Microsoft.AspNetCore.Mvc.ModelBinding; -using System; namespace POCUploadStream.Filters { @@ -14,7 +14,6 @@ public void OnResourceExecuting(ResourceExecutingContext context) factories.RemoveType(); } - public void OnResourceExecuted(ResourceExecutedContext context) - { } + public void OnResourceExecuted(ResourceExecutedContext context) { } } } diff --git a/POCUploadStream/Helpers/MultipartRequestHelper.cs b/POCUploadStream/Helpers/MultipartRequestHelper.cs index d950c5d..73e8dd2 100644 --- a/POCUploadStream/Helpers/MultipartRequestHelper.cs +++ b/POCUploadStream/Helpers/MultipartRequestHelper.cs @@ -1,6 +1,6 @@ -using Microsoft.Net.Http.Headers; -using System; +using System; using System.IO; +using Microsoft.Net.Http.Headers; namespace POCUploadStream.Helpers { @@ -14,23 +14,29 @@ public static string GetBoundary(MediaTypeHeaderValue contentType, int lengthLim if (string.IsNullOrWhiteSpace(boundary)) throw new InvalidDataException("Missing content-type boundary."); if (boundary.Length > lengthLimit) - throw new InvalidDataException($"Multipart boundary length limit {lengthLimit} exceeded."); + throw new InvalidDataException( + $"Multipart boundary length limit {lengthLimit} exceeded." + ); return boundary; } public static bool IsMultipartContentType(string contentType) { return !string.IsNullOrEmpty(contentType) - && contentType.IndexOf("multipart/", StringComparison.OrdinalIgnoreCase) >= 0; + && contentType.IndexOf("multipart/", StringComparison.OrdinalIgnoreCase) >= 0; } - public static bool HasFileContentDisposition(ContentDispositionHeaderValue contentDisposition) + public static bool HasFileContentDisposition( + ContentDispositionHeaderValue contentDisposition + ) { // Content-Disposition: form-data; name="anyName"; filename="someFile.jpg" return contentDisposition != null - && contentDisposition.DispositionType.Equals("form-data") - && (!string.IsNullOrEmpty(contentDisposition.FileName.ToString()) - || !string.IsNullOrEmpty(contentDisposition.FileNameStar.ToString())); + && contentDisposition.DispositionType.Equals("form-data") + && ( + !string.IsNullOrEmpty(contentDisposition.FileName.ToString()) + || !string.IsNullOrEmpty(contentDisposition.FileNameStar.ToString()) + ); } } } diff --git a/POCUploadStream/Helpers/UploadHelper.cs b/POCUploadStream/Helpers/UploadHelper.cs index ab79d16..5cf73ff 100644 --- a/POCUploadStream/Helpers/UploadHelper.cs +++ b/POCUploadStream/Helpers/UploadHelper.cs @@ -1,10 +1,10 @@ -using Microsoft.AspNetCore.Http; +using System; +using System.IO; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.WebUtilities; using Microsoft.Net.Http.Headers; -using System; -using System.IO; -using System.Threading.Tasks; namespace POCUploadStream.Helpers { @@ -15,10 +15,13 @@ public static class UploadHelper public static async Task Process(HttpRequest request) { if (!MultipartRequestHelper.IsMultipartContentType(request.ContentType)) - throw new InvalidOperationException($"Expected a multipart request, but got {request.ContentType}"); + throw new InvalidOperationException( + $"Expected a multipart request, but got {request.ContentType}" + ); var boundary = MultipartRequestHelper.GetBoundary( MediaTypeHeaderValue.Parse(request.ContentType), - DefaultFormOptions.MultipartBoundaryLengthLimit); + DefaultFormOptions.MultipartBoundaryLengthLimit + ); var reader = new MultipartReader(boundary, request.Body); var section = await reader.ReadNextSectionAsync(); while (section != null) @@ -30,8 +33,14 @@ public static async Task Process(HttpRequest request) private static async Task Upload(MultipartSection section) { - var hasContentDispositionHeader = ContentDispositionHeaderValue.TryParse(section.ContentDisposition, out var contentDisposition); - if (!hasContentDispositionHeader || !MultipartRequestHelper.HasFileContentDisposition(contentDisposition)) + var hasContentDispositionHeader = ContentDispositionHeaderValue.TryParse( + section.ContentDisposition, + out var contentDisposition + ); + if ( + !hasContentDispositionHeader + || !MultipartRequestHelper.HasFileContentDisposition(contentDisposition) + ) return; var targetFilePath = Path.GetTempFileName(); using (var targetStream = File.Create(targetFilePath)) diff --git a/POCUploadStream/Models/WeatherForecast.cs b/POCUploadStream/Models/WeatherForecast.cs index a2c5372..29b28f5 100644 --- a/POCUploadStream/Models/WeatherForecast.cs +++ b/POCUploadStream/Models/WeatherForecast.cs @@ -7,4 +7,4 @@ public sealed class WeatherForecast public string Summary { get; set; } public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); } -} \ No newline at end of file +} diff --git a/POCUploadStream/Pages/Error.cshtml.cs b/POCUploadStream/Pages/Error.cshtml.cs index b83b4ca..0898649 100644 --- a/POCUploadStream/Pages/Error.cshtml.cs +++ b/POCUploadStream/Pages/Error.cshtml.cs @@ -1,6 +1,6 @@ +using System.Diagnostics; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; -using System.Diagnostics; namespace POCUploadStream.Pages { diff --git a/POCUploadStream/Program.cs b/POCUploadStream/Program.cs index 454517f..8556f29 100644 --- a/POCUploadStream/Program.cs +++ b/POCUploadStream/Program.cs @@ -11,7 +11,6 @@ public static void Main(string[] args) } public static IWebHostBuilder CreateWebHostBuilder(string[] args) => - WebHost.CreateDefaultBuilder(args) - .UseStartup(); + WebHost.CreateDefaultBuilder(args).UseStartup(); } } diff --git a/POCUploadStream/Startup.cs b/POCUploadStream/Startup.cs index a178313..0a2a72e 100644 --- a/POCUploadStream/Startup.cs +++ b/POCUploadStream/Startup.cs @@ -39,9 +39,7 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env) app.UseSpaStaticFiles(); app.UseMvc(routes => { - routes.MapRoute( - name: "default", - template: "{controller}/{action=Index}/{id?}"); + routes.MapRoute(name: "default", template: "{controller}/{action=Index}/{id?}"); }); app.UseSpa(spa =>