Skip to content

Commit

Permalink
Updated github-app
Browse files Browse the repository at this point in the history
  • Loading branch information
aashimodi14 committed Oct 17, 2023
1 parent fbd57af commit 49c21f1
Show file tree
Hide file tree
Showing 42 changed files with 74,460 additions and 1 deletion.
1 change: 0 additions & 1 deletion github-app
Submodule github-app deleted from 18c274
25 changes: 25 additions & 0 deletions github-app/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
**/.classpath
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/azds.yaml
**/bin
**/charts
**/docker-compose*
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
LICENSE
README.md
21 changes: 21 additions & 0 deletions github-app/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.

FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base
WORKDIR /app
EXPOSE 80

FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
WORKDIR /src
COPY ["ScalableRazor.csproj", "."]
RUN dotnet restore "./ScalableRazor.csproj"
COPY . .
WORKDIR "/src/."
RUN dotnet build "ScalableRazor.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "ScalableRazor.csproj" -c Release -o /app/publish /p:UseAppHost=false

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "ScalableRazor.dll"]
16 changes: 16 additions & 0 deletions github-app/GitHubRepo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System.Text.Json.Serialization;

namespace ScalableRazor
{
public class GitHubRepo
{
[JsonPropertyName("name")]
public string Name { get; set; }

[JsonPropertyName("description")]
public string Description { get; set; }

[JsonPropertyName("html_url")]
public string HtmlUrl { get; set; }
}
}
26 changes: 26 additions & 0 deletions github-app/Pages/Error.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
@page
@model ErrorModel
@{
ViewData["Title"] = "Error";
}

<h1 class="text-danger">Error.</h1>
<h2 class="text-danger">An error occurred while processing your request.</h2>

@if (Model.ShowRequestId)
{
<p>
<strong>Request ID:</strong> <code>@Model.RequestId</code>
</p>
}

<h3>Development Mode</h3>
<p>
Swapping to the <strong>Development</strong> environment displays detailed information about the error that occurred.
</p>
<p>
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
It can result in displaying sensitive information from exceptions to end users.
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
and restarting the app.
</p>
27 changes: 27 additions & 0 deletions github-app/Pages/Error.cshtml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System.Diagnostics;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace ScalableRazor.Pages
{
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
[IgnoreAntiforgeryToken]
public class ErrorModel : PageModel
{
public string? RequestId { get; set; }

public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);

private readonly ILogger<ErrorModel> _logger;

public ErrorModel(ILogger<ErrorModel> logger)
{
_logger = logger;
}

public void OnGet()
{
RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
}
}
}
33 changes: 33 additions & 0 deletions github-app/Pages/Index.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
@page
@model IndexModel
@{
ViewData["Title"] = "Home page";
}

<h1 class="display-6">Welcome to the GitHub searcher!</h1>
<p class="mb-3">Enter the name of a GitHub organization such as "Microsoft" or "Azure" or "acorn-io" to browse its repositories.</p>

<form method="post" class="form mb-5">
<div class="form-group mb-3">
<input type="text" class="form-control" asp-for="@Model.SearchTerm" />
</div>
<input class="btn btn-success" type="submit" value="Search" />
</form>

<table class="table table-striped table-bordered">
<thead>
<tr>
<td>Name</td>
<td>Description</td>
<td>Link</td>
</tr>
</thead>
@foreach (var item in Model.Repos)
{
<tr>
<td>@item.Name</td>
<td>@Html.Raw(item.Description)</td>
<td><a class="btn btn-secondary" href="@item.HtmlUrl">Browse</a></td>
</tr>
}
</table>
58 changes: 58 additions & 0 deletions github-app/Pages/Index.cshtml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.Net.Http.Headers;
using System.Text.Json;


namespace ScalableRazor.Pages
{
public class IndexModel : PageModel
{
private readonly IConfiguration _env;
private readonly IHttpClientFactory _httpFactory;

public IndexModel(IConfiguration env, IHttpClientFactory httpFactory)
{
_env = env;
_httpFactory = httpFactory;
}

[BindProperty]
public string SearchTerm { get; set; }

public IEnumerable<GitHubRepo> Repos { get; set; } = new List<GitHubRepo>();

public IActionResult OnGet()
{
return Page();
}

public async Task<IActionResult> OnPost()
{
var client = _httpFactory.CreateClient();

var gitHubUrl = $"{_env["GitHubUrl"]}/orgs/{SearchTerm}/repos";

// GitHub API wants a UserAgent specified
var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, gitHubUrl)
{
Headers =
{
{ HeaderNames.UserAgent, "dotnet" }
}
};

var httpResponseMessage = await client.SendAsync(httpRequestMessage);

if (httpResponseMessage.IsSuccessStatusCode)
{
using var contentStream =
await httpResponseMessage.Content.ReadAsStreamAsync();

Repos = await JsonSerializer.DeserializeAsync<IEnumerable<GitHubRepo>>(contentStream);
}

return Page();
}
}
}
8 changes: 8 additions & 0 deletions github-app/Pages/Privacy.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@page
@model PrivacyModel
@{
ViewData["Title"] = "Privacy Policy";
}
<h1>@ViewData["Title"]</h1>

<p>Use this page to detail your site's privacy policy.</p>
19 changes: 19 additions & 0 deletions github-app/Pages/Privacy.cshtml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace ScalableRazor.Pages
{
public class PrivacyModel : PageModel
{
private readonly ILogger<PrivacyModel> _logger;

public PrivacyModel(ILogger<PrivacyModel> logger)
{
_logger = logger;
}

public void OnGet()
{
}
}
}
51 changes: 51 additions & 0 deletions github-app/Pages/Shared/_Layout.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>@ViewData["Title"] - Scalable Razor</title>
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.css" />
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
<link rel="stylesheet" href="~/ScalableRazor.styles.css" asp-append-version="true" />
</head>
<body>
<header>
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
<div class="container">
<a class="navbar-brand" asp-area="" asp-page="/Index">GitHub Browser</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target=".navbar-collapse" aria-controls="navbarSupportedContent"
aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="navbar-collapse collapse d-sm-inline-flex justify-content-between">
<ul class="navbar-nav flex-grow-1">
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-page="/Index">Home</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-page="/Privacy">Privacy</a>
</li>
</ul>
</div>
</div>
</nav>
</header>
<div class="container">
<main role="main" class="pb-3">
@RenderBody()
</main>
</div>

<footer class="border-top footer text-muted">
<div class="container">
&copy; 2022 - GitHubBrowser - <a asp-area="" asp-page="/Privacy">Privacy</a>
</div>
</footer>

<script src="~/lib/jquery/dist/jquery.min.js"></script>
<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
<script src="~/js/site.js" asp-append-version="true"></script>

@await RenderSectionAsync("Scripts", required: false)
</body>
</html>
48 changes: 48 additions & 0 deletions github-app/Pages/Shared/_Layout.cshtml.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/* Please see documentation at https://docs.microsoft.com/aspnet/core/client-side/bundling-and-minification
for details on configuring this project to bundle and minify static web assets. */

a.navbar-brand {
white-space: normal;
text-align: center;
word-break: break-all;
}

a {
color: #0077cc;
}

.btn-primary {
color: #fff;
background-color: #1b6ec2;
border-color: #1861ac;
}

.nav-pills .nav-link.active, .nav-pills .show > .nav-link {
color: #fff;
background-color: #1b6ec2;
border-color: #1861ac;
}

.border-top {
border-top: 1px solid #e5e5e5;
}
.border-bottom {
border-bottom: 1px solid #e5e5e5;
}

.box-shadow {
box-shadow: 0 .25rem .75rem rgba(0, 0, 0, .05);
}

button.accept-policy {
font-size: 1rem;
line-height: inherit;
}

.footer {
position: absolute;
bottom: 0;
width: 100%;
white-space: nowrap;
line-height: 60px;
}
2 changes: 2 additions & 0 deletions github-app/Pages/Shared/_ValidationScriptsPartial.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<script src="~/lib/jquery-validation/dist/jquery.validate.min.js"></script>
<script src="~/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.min.js"></script>
3 changes: 3 additions & 0 deletions github-app/Pages/_ViewImports.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@using ScalableRazor
@namespace ScalableRazor.Pages
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
3 changes: 3 additions & 0 deletions github-app/Pages/_ViewStart.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@{
Layout = "_Layout";
}
Loading

0 comments on commit 49c21f1

Please sign in to comment.