Skip to content

Commit

Permalink
[Penify]: Setting up Automated AI-Driven Documentation for GitHub! (#232
Browse files Browse the repository at this point in the history
)

* 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 <[email protected]>
Co-authored-by: gstraccini[bot] <51682887+gstraccini[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Aug 3, 2024
1 parent 2e8926d commit d4d447f
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 30 deletions.
13 changes: 13 additions & 0 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"version": 1,
"isRoot": true,
"tools": {
"csharpier": {
"version": "0.28.2",
"commands": [
"dotnet-csharpier"
],
"rollForward": false
}
}
}
19 changes: 19 additions & 0 deletions .github/workflows/snorkell-auto-documentation.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
with:
client_id: ${{ secrets.SNORKELL_CLIENT_ID }}
api_key: ${{ secrets.SNORKELL_API_KEY }}
branch_name: "main"
6 changes: 3 additions & 3 deletions POCUploadStream/Controllers/UploadController.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand All @@ -19,4 +19,4 @@ public async Task<IActionResult> Upload()
return Ok(new { Success = true });
}
}
}
}
7 changes: 3 additions & 4 deletions POCUploadStream/Filters/DisableFormValueModelBinding.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand All @@ -14,7 +14,6 @@ public void OnResourceExecuting(ResourceExecutingContext context)
factories.RemoveType<JQueryFormValueProviderFactory>();
}

public void OnResourceExecuted(ResourceExecutedContext context)
{ }
public void OnResourceExecuted(ResourceExecutedContext context) { }
}
}
22 changes: 14 additions & 8 deletions POCUploadStream/Helpers/MultipartRequestHelper.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Microsoft.Net.Http.Headers;
using System;
using System;
using System.IO;
using Microsoft.Net.Http.Headers;

namespace POCUploadStream.Helpers
{
Expand All @@ -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())
);
}
}
}
25 changes: 17 additions & 8 deletions POCUploadStream/Helpers/UploadHelper.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand All @@ -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)
Expand All @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion POCUploadStream/Models/WeatherForecast.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ public sealed class WeatherForecast
public string Summary { get; set; }
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
}
}
}
2 changes: 1 addition & 1 deletion POCUploadStream/Pages/Error.cshtml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Diagnostics;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using System.Diagnostics;

namespace POCUploadStream.Pages
{
Expand Down
3 changes: 1 addition & 2 deletions POCUploadStream/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ public static void Main(string[] args)
}

public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>();
WebHost.CreateDefaultBuilder(args).UseStartup<Startup>();
}
}
4 changes: 1 addition & 3 deletions POCUploadStream/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =>
Expand Down

0 comments on commit d4d447f

Please sign in to comment.