Rewrite it in Rust 🦀

This commit is contained in:
Luke Street
2024-09-06 19:45:36 -06:00
parent e40e258805
commit 4deabfa8b2
64 changed files with 8666 additions and 2730 deletions
+4 -2
View File
@@ -1,4 +1,6 @@
/tmp /node_modules
/target
/.idea /.idea
objdiff-* db.sqlite*
config.yml config.yml
.env
@@ -0,0 +1,20 @@
{
"db_name": "SQLite",
"query": "\n SELECT EXISTS (\n SELECT 1\n FROM reports JOIN projects ON reports.project_id = projects.id\n WHERE projects.owner = ? COLLATE NOCASE AND projects.repo = ? COLLATE NOCASE\n AND git_commit = ? COLLATE NOCASE\n ) AS \"exists!\"\n ",
"describe": {
"columns": [
{
"name": "exists!",
"ordinal": 0,
"type_info": "Integer"
}
],
"parameters": {
"Right": 3
},
"nullable": [
false
]
},
"hash": "21108206934d9a3b1e895e8413c319da09b55b6667b0d12efa7422babd5ec584"
}
@@ -0,0 +1,32 @@
{
"db_name": "SQLite",
"query": "\n SELECT git_commit, timestamp, version\n FROM reports\n WHERE project_id = ? AND git_commit = ? COLLATE NOCASE\n ORDER BY version\n ",
"describe": {
"columns": [
{
"name": "git_commit",
"ordinal": 0,
"type_info": "Text"
},
{
"name": "timestamp",
"ordinal": 1,
"type_info": "Datetime"
},
{
"name": "version",
"ordinal": 2,
"type_info": "Text"
}
],
"parameters": {
"Right": 2
},
"nullable": [
false,
false,
false
]
},
"hash": "364ea7a0b23d5edfbf4810659d41b0ceaeaa4fb6fd200dacf15030063ec7909d"
}
@@ -0,0 +1,12 @@
{
"db_name": "SQLite",
"query": "\n INSERT INTO report_report_units (report_id, report_unit_id, unit_index)\n VALUES (?, ?, ?)\n ON CONFLICT DO NOTHING\n ",
"describe": {
"columns": [],
"parameters": {
"Right": 3
},
"nullable": []
},
"hash": "3a14bed95e5b640c97da2b6d3458ab0cc6b5dcc96d1a62db6d763117a3cc5f5e"
}
@@ -0,0 +1,26 @@
{
"db_name": "SQLite",
"query": "\n SELECT id, data\n FROM report_units\n WHERE name IS NULL\n ",
"describe": {
"columns": [
{
"name": "id",
"ordinal": 0,
"type_info": "Blob"
},
{
"name": "data",
"ordinal": 1,
"type_info": "Blob"
}
],
"parameters": {
"Right": 0
},
"nullable": [
true,
false
]
},
"hash": "3eb7ed522f01e36e0969b09ca8b9c6984b1d02dc7b9515584be46e79b3793b1b"
}
@@ -0,0 +1,32 @@
{
"db_name": "SQLite",
"query": "\n SELECT git_commit, timestamp, version\n FROM reports\n WHERE project_id = ? AND timestamp = (\n SELECT MAX(timestamp)\n FROM reports\n WHERE project_id = ?\n )\n ORDER BY version\n ",
"describe": {
"columns": [
{
"name": "git_commit",
"ordinal": 0,
"type_info": "Text"
},
{
"name": "timestamp",
"ordinal": 1,
"type_info": "Datetime"
},
{
"name": "version",
"ordinal": 2,
"type_info": "Text"
}
],
"parameters": {
"Right": 2
},
"nullable": [
false,
false,
false
]
},
"hash": "4f3b7670e663abfba2a3c1b41f11293425d9701e3583fb1ce5851092dae89f10"
}
@@ -0,0 +1,20 @@
{
"db_name": "SQLite",
"query": "\n INSERT INTO reports (project_id, version, git_commit, timestamp, data)\n VALUES (?, ?, ?, ?, ?)\n ON CONFLICT (project_id, version COLLATE NOCASE, git_commit COLLATE NOCASE) DO UPDATE\n SET timestamp = EXCLUDED.timestamp\n RETURNING id\n ",
"describe": {
"columns": [
{
"name": "id",
"ordinal": 0,
"type_info": "Integer"
}
],
"parameters": {
"Right": 5
},
"nullable": [
false
]
},
"hash": "56c994f1c82f796c9924b571d5442a2694c3a1dbf469c88dfb8df8f283e18a3d"
}
@@ -0,0 +1,20 @@
{
"db_name": "SQLite",
"query": "\n SELECT git_commit\n FROM reports\n WHERE project_id = ? AND timestamp > ?\n ORDER BY timestamp\n LIMIT 1\n ",
"describe": {
"columns": [
{
"name": "git_commit",
"ordinal": 0,
"type_info": "Text"
}
],
"parameters": {
"Right": 2
},
"nullable": [
false
]
},
"hash": "6550bd96a82a16800fe801be26a52297907c2c3de6ea88951495175e81094343"
}
@@ -0,0 +1,20 @@
{
"db_name": "SQLite",
"query": "\n SELECT git_commit\n FROM reports\n WHERE project_id = ? AND timestamp < ?\n ORDER BY timestamp DESC\n LIMIT 1\n ",
"describe": {
"columns": [
{
"name": "git_commit",
"ordinal": 0,
"type_info": "Text"
}
],
"parameters": {
"Right": 2
},
"nullable": [
false
]
},
"hash": "7418a824fbb682e0044774c586a14643065ae66bc008a649cf6669988c738f04"
}
@@ -0,0 +1,68 @@
{
"db_name": "SQLite",
"query": "\n SELECT\n projects.id AS \"project_id!\",\n owner AS \"owner!\",\n repo AS \"repo!\",\n name,\n short_name,\n default_version,\n git_commit AS \"git_commit!\",\n MAX(timestamp) AS \"timestamp: chrono::NaiveDateTime\",\n JSON_GROUP_ARRAY(version ORDER BY version) AS versions\n FROM projects JOIN reports ON projects.id = reports.project_id\n WHERE timestamp = (\n SELECT MAX(timestamp)\n FROM reports\n WHERE project_id = projects.id\n )\n GROUP BY projects.id\n ORDER BY MAX(timestamp) DESC\n ",
"describe": {
"columns": [
{
"name": "project_id!",
"ordinal": 0,
"type_info": "Integer"
},
{
"name": "owner!",
"ordinal": 1,
"type_info": "Text"
},
{
"name": "repo!",
"ordinal": 2,
"type_info": "Text"
},
{
"name": "name",
"ordinal": 3,
"type_info": "Text"
},
{
"name": "short_name",
"ordinal": 4,
"type_info": "Text"
},
{
"name": "default_version",
"ordinal": 5,
"type_info": "Text"
},
{
"name": "git_commit!",
"ordinal": 6,
"type_info": "Text"
},
{
"name": "timestamp: chrono::NaiveDateTime",
"ordinal": 7,
"type_info": "Text"
},
{
"name": "versions",
"ordinal": 8,
"type_info": "Text"
}
],
"parameters": {
"Right": 0
},
"nullable": [
true,
true,
true,
true,
true,
true,
true,
false,
false
]
},
"hash": "76fc00ee61f9d0761931936dc4cc5cc533b79d79f78389b4642c03837b264733"
}
@@ -0,0 +1,12 @@
{
"db_name": "SQLite",
"query": "\n INSERT INTO report_units (id, data, name)\n VALUES (?, ?, ?)\n ON CONFLICT (id) DO NOTHING\n ",
"describe": {
"columns": [],
"parameters": {
"Right": 3
},
"nullable": []
},
"hash": "79bbdf8acb97c4826c8ef1c0e51b9f6be24b0e71c35ae1798d30c852ca160f32"
}
@@ -0,0 +1,12 @@
{
"db_name": "SQLite",
"query": "\n UPDATE report_units\n SET name = ?\n WHERE id = ?\n ",
"describe": {
"columns": [],
"parameters": {
"Right": 2
},
"nullable": []
},
"hash": "a4a5a6ff35d886c5f80a8973e2556a67ddcedae6be782be5a7357dbd1628b4e0"
}
@@ -0,0 +1,12 @@
{
"db_name": "SQLite",
"query": "\n INSERT INTO projects (id, owner, repo, name, short_name, default_version, created_at, updated_at)\n VALUES (?, ?, ?, ?, ?, ?, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)\n ON CONFLICT (id) DO NOTHING\n ",
"describe": {
"columns": [],
"parameters": {
"Right": 6
},
"nullable": []
},
"hash": "c0adc5fae9d742173927a8f48d01d02add2ea3b8abae862a144c4607a62cc196"
}
@@ -0,0 +1,32 @@
{
"db_name": "SQLite",
"query": "\n SELECT ru.id AS \"id!\", ru.data, rru.unit_index\n FROM report_report_units rru JOIN report_units ru ON rru.report_unit_id = ru.id\n WHERE rru.report_id = ?\n ORDER BY rru.unit_index\n ",
"describe": {
"columns": [
{
"name": "id!",
"ordinal": 0,
"type_info": "Blob"
},
{
"name": "data",
"ordinal": 1,
"type_info": "Blob"
},
{
"name": "unit_index",
"ordinal": 2,
"type_info": "Integer"
}
],
"parameters": {
"Right": 1
},
"nullable": [
true,
false,
false
]
},
"hash": "d2268044470d7a0c539ccbae97e55256cbeb4d2c46e38521fe7c553fc02c861f"
}
@@ -0,0 +1,80 @@
{
"db_name": "SQLite",
"query": "\n SELECT\n reports.id as \"report_id!\",\n git_commit,\n timestamp,\n version,\n data,\n projects.id as \"project_id!\",\n owner,\n repo,\n name,\n short_name,\n default_version\n FROM reports JOIN projects ON reports.project_id = projects.id\n WHERE projects.owner = ? COLLATE NOCASE AND projects.repo = ? COLLATE NOCASE\n AND version = ? COLLATE NOCASE AND git_commit = ? COLLATE NOCASE\n ",
"describe": {
"columns": [
{
"name": "report_id!",
"ordinal": 0,
"type_info": "Integer"
},
{
"name": "git_commit",
"ordinal": 1,
"type_info": "Text"
},
{
"name": "timestamp",
"ordinal": 2,
"type_info": "Datetime"
},
{
"name": "version",
"ordinal": 3,
"type_info": "Text"
},
{
"name": "data",
"ordinal": 4,
"type_info": "Blob"
},
{
"name": "project_id!",
"ordinal": 5,
"type_info": "Integer"
},
{
"name": "owner",
"ordinal": 6,
"type_info": "Text"
},
{
"name": "repo",
"ordinal": 7,
"type_info": "Text"
},
{
"name": "name",
"ordinal": 8,
"type_info": "Text"
},
{
"name": "short_name",
"ordinal": 9,
"type_info": "Text"
},
{
"name": "default_version",
"ordinal": 10,
"type_info": "Text"
}
],
"parameters": {
"Right": 4
},
"nullable": [
true,
false,
false,
false,
false,
true,
false,
false,
true,
true,
true
]
},
"hash": "d38ee2d117fd8d6e0628c790c138ef596317748a42165c899b81ab63b84ff819"
}
@@ -0,0 +1,50 @@
{
"db_name": "SQLite",
"query": "\n SELECT id AS \"id!\", owner, repo, name, short_name, default_version\n FROM projects\n WHERE owner = ? COLLATE NOCASE AND repo = ? COLLATE NOCASE\n ",
"describe": {
"columns": [
{
"name": "id!",
"ordinal": 0,
"type_info": "Integer"
},
{
"name": "owner",
"ordinal": 1,
"type_info": "Text"
},
{
"name": "repo",
"ordinal": 2,
"type_info": "Text"
},
{
"name": "name",
"ordinal": 3,
"type_info": "Text"
},
{
"name": "short_name",
"ordinal": 4,
"type_info": "Text"
},
{
"name": "default_version",
"ordinal": 5,
"type_info": "Text"
}
],
"parameters": {
"Right": 2
},
"nullable": [
true,
false,
false,
true,
true,
true
]
},
"hash": "d4de02659c86068320c310dc8c6262c0086a2348ff8726e522aaee6999e61cad"
}
Generated
+5524
View File
File diff suppressed because it is too large Load Diff
+41
View File
@@ -0,0 +1,41 @@
[package]
name = "decompal-rs"
version = "0.1.0"
edition = "2021"
[dependencies]
anyhow = "1.0"
axum = "0.7"
blake3 = "1.5"
bytes = "1.7"
chrono = "0.4"
grass = "0.13"
image = "0.25"
lightningcss = "1.0.0-alpha"
mime = "0.3"
minijinja = { version = "2.2", features = ["loader"] }
minijinja-autoreload = "2.2"
moka = { version = "0.12", features = ["future"] }
objdiff-core = { git = "https://github.com/encounter/objdiff", tag = "v2.0.0-beta.6", features = ["bindings"] }
#objdiff-core = { path = "../objdiff/objdiff-core", features = ["bindings"] }
octocrab = "0.39"
oxc = { version = "0.27", features = ["codegen", "minifier", "transformer", "semantic"] }
palette = "0.7"
prost = "0.13"
regex = "1.10"
resvg = "0.43"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
serde_yaml = "0.9"
sqlx = { version = "0.8", features = ["runtime-tokio", "sqlite", "chrono"] }
streemap = "0.1"
timeago = { version = "0.4.2", default-features = false, features = ["chrono"] }
tokio = { version = "1.40", features = ["full"] }
tokio-cron-scheduler = "0.11"
tower = { version = "0.4", features = ["full"] }
tower-http = { version = "0.5", features = ["full"] }
tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
treemap = "0.3"
zip = { version = "2.2", default-features = false, features = ["deflate-flate2"] }
zstd = "0.13"
+3
View File
@@ -0,0 +1,3 @@
fn main() {
println!("cargo:rerun-if-changed=migrations");
}
-56
View File
@@ -1,56 +0,0 @@
package main
import (
"context"
"github.com/encounter/decompal/config"
"github.com/encounter/decompal/handlers"
"github.com/gregjones/httpcache"
"github.com/palantir/go-baseapp/baseapp"
"github.com/palantir/go-githubapp/githubapp"
"github.com/pkg/errors"
"github.com/rs/zerolog"
"goji.io/pat"
"time"
)
func main() {
// Load configuration from a file
cfg, err := config.ReadConfig("config.yml")
if err != nil {
panic(errors.Wrap(err, "failed to read config"))
}
logger := baseapp.NewLogger(cfg.Logging)
zerolog.DefaultContextLogger = &logger
// Create the server
serverParams := baseapp.DefaultParams(logger, "decompal.")
server, err := baseapp.NewServer(cfg.Server, serverParams...)
if err != nil {
logger.Fatal().Err(err).Msg("failed to create server")
}
// Create GitHub app client
cc, err := githubapp.NewDefaultCachingClientCreator(
cfg.GitHub,
githubapp.WithClientUserAgent("decompal/1.0.0"),
githubapp.WithClientTimeout(5*time.Second),
githubapp.WithClientCaching(false, func() httpcache.Cache { return httpcache.NewMemoryCache() }),
)
if err != nil {
logger.Fatal().Err(err).Msg("failed to create GitHub app client")
}
// Register GitHub webhook handlers
taskCtx, taskCancel := context.WithCancel(context.Background())
defer taskCancel()
server.Mux().Handle(pat.Post(githubapp.DefaultWebhookRoute), githubapp.NewDefaultEventDispatcher(
cfg.GitHub,
handlers.NewPullRequestHandler(cc, &cfg.App, taskCtx),
handlers.NewWorkflowRunHandler(cc, &cfg.App, taskCtx),
))
// Start the server (blocking)
if err = server.Start(); err != nil {
logger.Fatal().Err(err).Msg("server failed")
}
}

Some files were not shown because too many files have changed in this diff Show More