This commit is contained in:
Arya Kiran
2023-05-16 20:28:27 +08:00
19 changed files with 75 additions and 32 deletions
+1 -1
View File
@@ -5,7 +5,7 @@ pipeline:
branch: dev
image: woodpeckerci/plugin-docker-buildx
settings:
dockerfile: Dockerfile
dockerfile: DockerfileDev
registry: https://codeberg.org/v2
repo: codeberg.org/gothub/gothub
platforms: linux/amd64,linux/arm64
+2 -2
View File
@@ -7,7 +7,7 @@ RUN apk --no-cache add git
RUN git clone https://codeberg.org/gothub/gothub .
RUN go mod download
RUN GOOS=linux GOARCH=$TARGETARCH go build -o /src/gothub
RUN GOOS=linux GOARCH=$TARGETARCH go build -o /src/gothub -ldflags="-X codeberg.org/gothub/gothub/utils.Branch=master"
FROM alpine:3.16 as bin
@@ -19,4 +19,4 @@ COPY --from=build /src/public ./public
ENV DOCKER true
EXPOSE 3000
CMD ["/app/gothub", "serve"]
CMD ["/app/gothub", "serve"]
+22
View File
@@ -0,0 +1,22 @@
FROM --platform=$BUILDPLATFORM golang:alpine AS build
ARG TARGETARCH
WORKDIR /src
RUN apk --no-cache add git
RUN git clone https://codeberg.org/gothub/gothub .
RUN go mod download
RUN GOOS=linux GOARCH=$TARGETARCH go build -o /src/gothub -ldflags="-X codeberg.org/gothub/gothub/utils.Branch=dev"
FROM alpine:3.16 as bin
WORKDIR /app
COPY --from=build /src/gothub .
COPY --from=build /src/views ./views
COPY --from=build /src/public ./public
ENV DOCKER true
EXPOSE 3000
CMD ["/app/gothub", "serve"]
+5 -3
View File
@@ -34,15 +34,17 @@ The ``master`` branch runs on the master branch of GotHub. This means that the i
| Link | Cloudflare | Country | ISP | Branch |
| -------- | ---------- | ----------- | ----- | ----- |
| [gh.akisblack.dev](https://gh.akisblack.dev) | No | Germany | OVHcloud | master |
| [gothub.lunar.icu](https://gothub.lunar.icu) | Yes | Germany | Unesty | master |
| [gothub.esmailelbob.xyz](https://gothub.esmailelbob.xyz) | No | Canada | OVHcloud | master |
| [gothub.no-logs.com](https://gothub.no-logs.com/) | No | Sweden | Vultr | master |
| [gh.odyssey346.dev](https://gh.odyssey346.dev) | No | France | OVHcloud (Trolling Solutions) | master |
| [gh.phreedom.club](https://gh.phreedom.club) | No | Iceland | Flokinet | master |
| [gothub.projectsegfau.lt](https://gothub.projectsegfau.lt) | No | GeoDNS (Luxembourg/USA/India) | BuyVM/Digital Ocean/Airtel | master |
| [gh.riverside.rocks](https://gh.riverside.rocks) | No | USA | Comcast | master |
| [gh.fascinated.cc](https://gh.fascinated.cc) | Yes | Germany | Contabo | master |
| [gothub.lunar.icu](https://gothub.lunar.icu) | Yes | Germany | Unesty | master |
| [gothub.xbdm.fun](https://gothub.xbdm.fun) | Yes | Germany | Hetzner | master |
| [dev.gh.akisblack.dev](https://dev.gh.akisblack.dev) | No | Germany | OVHcloud | dev |
| [gh.creller.net](https://gh.creller.net) | No | Finland | Hetzner | dev |
| [gothub.esmailelbob.xyz](https://gothub.esmailelbob.xyz) | No | Canada | OVHcloud | dev |
| [gh.creller.net](https://gh.creller.net) | No | Scotland | British Telecommunications PLC | dev |
| [gh.dev.odyssey346.dev](https://gh.dev.odyssey346.dev) | No | France | OVHcloud (Trolling Solutions) | dev |
| [gothub.dev.projectsegfau.lt](https://gothub.dev.projectsegfau.lt) | No | Luxembourg | BuyVM | dev |
+6 -2
View File
@@ -3,6 +3,7 @@ package gothub
import (
"bytes"
"fmt"
"strings"
"github.com/spf13/cobra"
@@ -30,6 +31,9 @@ func update() {
os.Exit(1)
}
gitPull := exec.Command("git", "pull")
curBranch := exec.Command("git", "rev-parse", "--abbrev-ref", "HEAD")
curBranchOut, _ := curBranch.CombinedOutput()
ldFlags := "-X codeberg.org/gothub/gothub/utils.Branch=" + strings.Replace(string(curBranchOut), "\n", "", -1)
var out bytes.Buffer
gitPull.Stdout = &out
err := gitPull.Run()
@@ -42,7 +46,7 @@ func update() {
os.Exit(1)
}
if runtime.GOOS == "windows" {
err := exec.Command("go", "build", "-o", "gothub.exe").Run()
err := exec.Command("go", "build", "-o", "gothub.exe", ldFlags).Run()
if err != nil {
fmt.Println("Couldn't build GotHub.", err)
os.Exit(1)
@@ -51,7 +55,7 @@ func update() {
os.Exit(0)
}
} else {
err := exec.Command("go", "build").Run()
err := exec.Command("go", "build", "-ldflags", ldFlags).Run()
if err != nil {
fmt.Println("Couldn't build GotHub.", err)
os.Exit(1)
+2 -2
View File
@@ -1,7 +1,7 @@
version: "3"
services:
gothub:
image: codeberg.org/gothub/gothub:latest
image: codeberg.org/gothub/gothub:latest # Master branch
# image: codeberg.org/gothub/gothub:dev # Dev branch
restart: unless-stopped
ports:
@@ -22,4 +22,4 @@ services:
test: wget -nv --tries=1 --spider http://127.0.0.1:3000/api/v1/version || exit 1
interval: 30s
timeout: 5s
retries: 2
retries: 2
+1
View File
@@ -41,6 +41,7 @@ func HandleAbout(c *fiber.Ctx) error {
return c.Render("about", fiber.Map{
"title": "About this instance",
"branch": utils.Branch,
"privacyInformation": privacyInfoArray,
})
}
+1
View File
@@ -88,6 +88,7 @@ func DirView(c *fiber.Ctx) error {
dirArray = append(dirArray, Scrape)
return c.Render("dir", fiber.Map{
"title": "Directory " + c.Params("+") + " | " + c.Params("user") + "/" + c.Params("repo"),
"branch": utils.Branch,
"dir": dirArray,
"files": dirFilesArray,
"readme": string(readmeOutput),
+3 -2
View File
@@ -36,7 +36,8 @@ func HandleExplore(c *fiber.Ctx) error {
}
return c.Render("explore", fiber.Map{
"title": "Explore",
"repos": trendingReposArray,
"title": "Explore",
"branch": utils.Branch,
"repos": trendingReposArray,
})
}
+9 -8
View File
@@ -3,14 +3,14 @@ package pages
import (
"bufio"
"bytes"
"codeberg.org/gothub/gothub/utils"
"context"
"html/template"
htmlfmt "github.com/alecthomas/chroma/v2/formatters/html"
"github.com/alecthomas/chroma/v2/lexers"
"github.com/alecthomas/chroma/v2/styles"
"github.com/carlmjohnson/requests"
"github.com/gofiber/fiber/v2"
"html/template"
)
// FileView is the file view page
@@ -57,11 +57,12 @@ func FileView(c *fiber.Ctx) error {
writer.Flush()
cssw.Flush()
return c.Render("file", fiber.Map{
"title": c.Params("+") + " | " + c.Params("user") + "/" + c.Params("repo"),
"file": template.HTML(buf.String()),
"css": template.CSS(cssbuf.String()),
"fullname": c.Params("user") + "/" + c.Params("repo"),
"name": c.Params("+"),
"branch": c.Params("branch"),
"title": c.Params("+") + " | " + c.Params("user") + "/" + c.Params("repo"),
"branch": utils.Branch,
"file": template.HTML(buf.String()),
"css": template.CSS(cssbuf.String()),
"fullname": c.Params("user") + "/" + c.Params("repo"),
"name": c.Params("+"),
"fileBranch": c.Params("branch"),
})
}
+5 -3
View File
@@ -3,6 +3,7 @@ package pages
import (
"bufio"
"bytes"
"codeberg.org/gothub/gothub/utils"
"context"
htmlfmt "github.com/alecthomas/chroma/v2/formatters/html"
"github.com/alecthomas/chroma/v2/lexers"
@@ -131,8 +132,9 @@ func HandleGist(c *fiber.Ctx) error {
gistArray = append(gistArray, Scrape)
return c.Render("gist", fiber.Map{
"title": "Repository " + c.Params("user") + "/" + c.Params("gistID"),
"gist": gistArray,
"files": gistFilesArray,
"title": "Repository " + c.Params("user") + "/" + c.Params("gistID"),
"branch": utils.Branch,
"gist": gistArray,
"files": gistFilesArray,
})
}
+1
View File
@@ -11,6 +11,7 @@ import (
func HandleIndex(c *fiber.Ctx) error {
return c.Render("index", fiber.Map{
"host": c.Hostname(),
"branch": utils.Branch,
"version": utils.Version(),
"fiberversion": fiber.Version,
"goversion": runtime.Version(),
+1
View File
@@ -121,6 +121,7 @@ func HandleRepo(c *fiber.Ctx) error {
repoArray = append(repoArray, Scrape)
return c.Render("repo", fiber.Map{
"title": c.Params("user") + "/" + repoUrl + branchExists,
"branch": utils.Branch,
"repo": repoArray,
"files": repoFilesArray,
"readme": readmeOutput,
+3 -2
View File
@@ -181,7 +181,8 @@ func HandleUser(c *fiber.Ctx) error {
userArray = append(userArray, Scrape)
return c.Render("user", fiber.Map{
"title": c.Params("user"),
"user": userArray,
"title": c.Params("user"),
"branch": utils.Branch,
"user": userArray,
})
}
+7 -5
View File
@@ -4,8 +4,8 @@ import (
"html/template"
"log"
"os"
"regexp"
"runtime"
"strings"
"time"
"codeberg.org/gothub/gothub/pages"
@@ -45,10 +45,11 @@ func Serve(port string) {
if e, ok := err.(*fiber.Error); ok {
code = e.Code
}
_, link := regexp.MatchString(`\/.*\ `, err.Error())
link := strings.TrimPrefix(err.Error(), "Cannot GET ")
err = ctx.Status(code).Render("error", fiber.Map{
"error": err,
"link": link,
"error": err,
"link": link,
"branch": utils.Branch,
})
if err != nil {
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
@@ -73,7 +74,8 @@ func Serve(port string) {
Expiration: 5 * time.Minute,
LimitReached: func(c *fiber.Ctx) error {
return c.Status(429).Render("ratelimit_gt", fiber.Map{
"Title": "Rate limit exceeded",
"Title": "Rate limit exceeded",
"branch": utils.Branch,
})
},
})
+2
View File
@@ -4,6 +4,8 @@ import (
"runtime/debug"
)
var Branch = "Alpha"
// Version returns the git commit hash of the current build. Taken from https://git.vern.cc/pjals/bestofbot.
func Version() string {
if info, ok := debug.ReadBuildInfo(); ok {
+2
View File
@@ -12,6 +12,8 @@
<a href="https://codeberg.org/gothub/gothub/issues" target="_blank"
>Create an issue on Codeberg.</a
>
{{ if .link }} Or view this page on
<a rel="noreferrer" href="https://github.com{{.link}}">GitHub</a> {{end}}
</h3>
</div>
</main>
+1 -1
View File
@@ -11,7 +11,7 @@
}
</style>
<div class="download-parent">
<a href="/{{.fullname}}/tree/{{.branch}}" class="button"
<a href="/{{.fullname}}/tree/{{.fileBranch}}" class="button"
>Back to {{.fullname}}</a
>
</div>
+1 -1
View File
@@ -20,7 +20,7 @@
height="30"
width="30"
alt=""
><b class="navbar-slogan">GotHub (alpha)</b></a
><b class="navbar-slogan">GotHub ({{.branch}})</b></a
>
<div class="navbar-links">
<a href="/explore">Explore</a>