aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRunxi Yu <me@runxiyu.org>2025-02-11 19:04:05 +0800
committerRunxi Yu <me@runxiyu.org>2025-02-11 19:04:05 +0800
commitcac176daa985b032f08758ae54c83eea659f9bc3 (patch)
treecc581bbeaf0ff1f0affcb33a18e19cac12abf2d8
parentgit_misc: Sanitize paths (diff)
downloadforge-cac176daa985b032f08758ae54c83eea659f9bc3.tar.gz
forge-cac176daa985b032f08758ae54c83eea659f9bc3.tar.zst
forge-cac176daa985b032f08758ae54c83eea659f9bc3.zip
repo_commit: Add a commit info page
-rw-r--r--handle_repo_commit.go53
-rw-r--r--main.go1
-rw-r--r--static/style.css7
-rw-r--r--templates/repo_commit.html.tmpl44
4 files changed, 105 insertions, 0 deletions
diff --git a/handle_repo_commit.go b/handle_repo_commit.go
new file mode 100644
index 0000000..c7bdf9f
--- /dev/null
+++ b/handle_repo_commit.go
@@ -0,0 +1,53 @@
+package main
+
+import (
+ "net/http"
+
+ "github.com/go-git/go-git/v5/plumbing"
+)
+
+func handle_repo_commit(w http.ResponseWriter, r *http.Request) {
+ data := make(map[string]any)
+ // TODO: Sanitize path values
+ group_name, repo_name, commit_id_string := r.PathValue("group_name"), r.PathValue("repo_name"), r.PathValue("commit_id")
+ data["group_name"], data["repo_name"], data["commit_id"] = group_name, repo_name, commit_id_string
+ repo, err := open_git_repo(group_name, repo_name)
+ if err != nil {
+ _, _ = w.Write([]byte("Error opening repo: " + err.Error()))
+ return
+ }
+ commit_id := plumbing.NewHash(commit_id_string)
+ commit_object, err := repo.CommitObject(commit_id)
+ if err != nil {
+ _, _ = w.Write([]byte("Error getting commit object: " + err.Error()))
+ return
+ }
+ data["commit_object"] = commit_object
+
+ parent_commit_object, err := commit_object.Parent(0)
+ if err != nil {
+ _, _ = w.Write([]byte("Error getting parent commit object: " + err.Error()))
+ return
+ }
+ data["parent_commit_object"] = parent_commit_object
+
+ patch, err := parent_commit_object.Patch(commit_object)
+ if err != nil {
+ _, _ = w.Write([]byte("Error getting patch of commit: " + err.Error()))
+ return
+ }
+ data["patch"] = patch
+
+ /*
+ for _, file_patch := range patch.FilePatches() {
+ for _, chunk := range file_patch.Chunks() {
+ }
+ }
+ */
+
+ err = templates.ExecuteTemplate(w, "repo_commit", data)
+ if err != nil {
+ _, _ = w.Write([]byte("Error rendering template: " + err.Error()))
+ return
+ }
+}
diff --git a/main.go b/main.go
index e8456fb..02e48a3 100644
--- a/main.go
+++ b/main.go
@@ -39,6 +39,7 @@ func main() {
http.HandleFunc("/g/{group_name}/repos/{repo_name}/tree/{ref}/{rest...}", handle_repo_tree)
http.HandleFunc("/g/{group_name}/repos/{repo_name}/raw/{ref}/{rest...}", handle_repo_raw)
http.HandleFunc("/g/{group_name}/repos/{repo_name}/log/{ref}/", handle_repo_log)
+ http.HandleFunc("/g/{group_name}/repos/{repo_name}/commit/{commit_id}/", handle_repo_commit)
listener, err := net.Listen(config.HTTP.Net, config.HTTP.Addr)
if err != nil {
diff --git a/static/style.css b/static/style.css
index 94084dc..a57fad7 100644
--- a/static/style.css
+++ b/static/style.css
@@ -49,6 +49,10 @@ footer a:link, footer a:visited {
.padding-wrapper > * {
width: 100%;
}
+.padding-wrapper > table {
+ width: auto;
+ max-width: 100%;
+}
a:link, a:visited {
text-decoration-color: var(--text-decoration-color);
color: var(--link-color);
@@ -70,6 +74,9 @@ td, th {
th {
background-color: var(--lighter-box-background-color);
}
+th[scope=row] {
+ text-align: left;
+}
tr.title-row > th {
background-color: var(--darker-box-background-color);
}
diff --git a/templates/repo_commit.html.tmpl b/templates/repo_commit.html.tmpl
new file mode 100644
index 0000000..03625aa
--- /dev/null
+++ b/templates/repo_commit.html.tmpl
@@ -0,0 +1,44 @@
+{{- define "repo_commit" -}}
+<!DOCTYPE html>
+<html lang="en">
+ <head>
+ {{ template "head_common" . }}
+ <title>{{ .group_name }}/repos/{{ .repo_name }} &ndash; Lindenii Forge</title>
+ </head>
+ <body class="repo-commit">
+ <div class="padding-wrapper">
+ <table id="commit-info-table">
+ <thead>
+ <tr class="title-row">
+ <th colspan="2">Commit {{ .commit_id }}</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <th scope="row">Author</th>
+ <td>{{ .commit_object.Author.Name }} &lt;<a href="mailto:{{ .commit_object.Author.Email }}">{{ .commit_object.Author.Email }}</a>&gt;</td>
+ </tr>
+ <tr>
+ <th scope="row">Author Date</th>
+ <td>{{ .commit_object.Author.When.Format "Mon, 02 Jan 2006 15:04:05 -0700" }}</td>
+ </tr>
+ <tr>
+ <th scope="row">Committer</th>
+ <td>{{ .commit_object.Committer.Name }} &lt;<a href="mailto:{{ .commit_object.Committer.Email }}">{{ .commit_object.Committer.Email }}</a>&gt;</td>
+ </tr>
+ <tr>
+ <th scope="row">Committer Date</th>
+ <td>{{ .commit_object.Committer.When.Format "Mon, 02 Jan 2006 15:04:05 -0700" }}</td>
+ </tr>
+ </tbody>
+ </table>
+ <pre>{{ .patch }}</pre>
+ <p>
+ </p>
+ </div>
+ <footer>
+ {{ template "footer" . }}
+ </footer>
+ </body>
+</html>
+{{- end -}}