Skip to content

Commit

Permalink
Merge pull request #27 from kaypee90/add-ui
Browse files Browse the repository at this point in the history
Add UI for configuring dependabot
  • Loading branch information
kaypee90 authored Nov 2, 2024
2 parents 8aa1212 + ff6aca5 commit 97f6372
Show file tree
Hide file tree
Showing 54 changed files with 29,511 additions and 1 deletion.
26 changes: 26 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# If you prefer the allow list template instead of the deny list, see community template:

# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
#
# Binaries for programs and plugins
Expand All @@ -25,3 +26,28 @@ dependabot.yml

# Don't ignore github dependabot configuration
!/.github/dependabot.yml

# dependencies
*/node_modules
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
*/build

# misc
*/.DS_Store
*/.env.local
*/.env.development.local
*/.env.test.local
*/.env.production.local
**/.idea

*/npm-debug.log*
*/yarn-debug.log*
*/yarn-error.log*
/.vscode
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ run:
$(LAUNCH)
version:
$(LAUNCH) --version
web:
$(LAUNCH) --web
build:
$(GOBUILD) -o $(BINARY_NAME) $$(ls -1 cmd/depbot/*.go | grep -v _test.go)
test:
Expand Down
6 changes: 5 additions & 1 deletion cmd/depbot/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"os"
)

const version = "0.5.0"
const version = "1.0.0"

func displayAppVersion() {
fmt.Printf("Depbot %s\n", version)
Expand Down Expand Up @@ -92,9 +92,13 @@ func launchApplicaton() {

func main() {
showVersion := flag.Bool("version", false, "Display app version")
startWebApp := flag.Bool("web", false, "Start web application")

flag.Parse()
if *showVersion {
displayAppVersion()
} else if *startWebApp {
startWebApplication()
} else {
launchApplicaton()
}
Expand Down
67 changes: 67 additions & 0 deletions cmd/depbot/server.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package main

import (
"embed"
"encoding/json"
"fmt"
"io"
"net/http"
)

//go:embed static/*
var staticFiles embed.FS

type ConfigurationRequest struct {
Configuration string `json:"configuration"`
}

func saveConfigurationHandler(w http.ResponseWriter, r *http.Request) {
decoder := json.NewDecoder(r.Body)
var config ConfigurationRequest
if err := decoder.Decode(&config); err != nil {
if err == io.EOF {
http.Error(w, "Empty request body", http.StatusBadRequest)
return
}
http.Error(w, "Invalid request body", http.StatusBadRequest)
return
}

createDependabotYamlFile([]byte(config.Configuration))
}

func healthCheckHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
w.Write([]byte("{\"message\": \"Healthy\"}"))
}

func enableCORS(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// Set the necessary CORS headers
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS")
w.Header().Set("Access-Control-Allow-Headers", "Content-Type, Authorization")

// Handle preflight request
if r.Method == http.MethodOptions {
w.WriteHeader(http.StatusNoContent)
return
}

next.ServeHTTP(w, r)
})
}

func startWebApplication() {
mux := http.NewServeMux()

fs := http.FileServer(http.FS(staticFiles))
mux.Handle("/static/", http.StripPrefix("/static/", fs))

mux.HandleFunc("/", healthCheckHandler)
mux.HandleFunc("/api/configurations", saveConfigurationHandler)

port := ":3001"
fmt.Println("Serving on http://localhost" + port)
http.ListenAndServe(port, enableCORS(mux))
}
15 changes: 15 additions & 0 deletions cmd/depbot/static/asset-manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"files": {
"main.css": "/static/css/main.e6c13ad2.css",
"main.js": "/static/js/main.535bdf8e.js",
"static/js/453.6adcfb1c.chunk.js": "/static/js/453.6adcfb1c.chunk.js",
"index.html": "/index.html",
"main.e6c13ad2.css.map": "/static/css/main.e6c13ad2.css.map",
"main.535bdf8e.js.map": "/static/js/main.535bdf8e.js.map",
"453.6adcfb1c.chunk.js.map": "/static/js/453.6adcfb1c.chunk.js.map"
},
"entrypoints": [
"static/css/main.e6c13ad2.css",
"static/js/main.535bdf8e.js"
]
}
Binary file added cmd/depbot/static/favicon.ico
Binary file not shown.
1 change: 1 addition & 0 deletions cmd/depbot/static/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/static/static/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Depbot wizard for dependabot"/><link rel="apple-touch-icon" href="/static/static/logo192.png"/><link rel="manifest" href="/static/static/manifest.json"/><title>Depbot</title><script defer="defer" src="/static/static/static/js/main.535bdf8e.js"></script><link href="/static/static/static/css/main.e6c13ad2.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
Binary file added cmd/depbot/static/logo192.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added cmd/depbot/static/logo512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions cmd/depbot/static/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"short_name": "React App",
"name": "Create React App Sample",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
},
{
"src": "logo192.png",
"type": "image/png",
"sizes": "192x192"
},
{
"src": "logo512.png",
"type": "image/png",
"sizes": "512x512"
}
],
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}
3 changes: 3 additions & 0 deletions cmd/depbot/static/robots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# https://www.robotstxt.org/robotstxt.html
User-agent: *
Disallow:
2 changes: 2 additions & 0 deletions cmd/depbot/static/static/css/main.e6c13ad2.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions cmd/depbot/static/static/css/main.e6c13ad2.css.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions cmd/depbot/static/static/js/453.6adcfb1c.chunk.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 97f6372

Please sign in to comment.