mirror of https://git.jolheiser.com/ugit.git
Compare commits
1 Commits
590777dea0
...
285640256e
Author | SHA1 | Date |
---|---|---|
jolheiser | 285640256e |
|
@ -11,7 +11,7 @@ import (
|
||||||
"github.com/go-git/go-git/v5"
|
"github.com/go-git/go-git/v5"
|
||||||
)
|
)
|
||||||
|
|
||||||
func maine() error {
|
func main() {
|
||||||
repoDir, ok := os.LookupEnv("UGIT_REPODIR")
|
repoDir, ok := os.LookupEnv("UGIT_REPODIR")
|
||||||
if !ok {
|
if !ok {
|
||||||
panic("UGIT_REPODIR not set")
|
panic("UGIT_REPODIR not set")
|
||||||
|
@ -31,38 +31,30 @@ func maine() error {
|
||||||
|
|
||||||
repo, err := git.PlainOpen(repoDir)
|
repo, err := git.PlainOpen(repoDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("could not open git dir %q: %w", repoDir, err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
tree, err := repo.Worktree()
|
tree, err := repo.Worktree()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("could not get worktree: %w", err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
fi, err := tree.Filesystem.Open(*manifestFlag)
|
fi, err := tree.Filesystem.Open(*manifestFlag)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("could not open manifest %q: %w", *manifestFlag, err)
|
panic(err)
|
||||||
}
|
}
|
||||||
defer fi.Close()
|
defer fi.Close()
|
||||||
|
|
||||||
data, err := io.ReadAll(fi)
|
data, err := io.ReadAll(fi)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("could not read manifest: %w", err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := http.Post(*urlFlag, "application/jsonnet", bytes.NewReader(data))
|
resp, err := http.Post(*urlFlag, "applicaiton/jsonnet", bytes.NewReader(data))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("could not post manifest: %w", err)
|
panic(err)
|
||||||
}
|
}
|
||||||
if resp.StatusCode != http.StatusOK {
|
if resp.StatusCode != http.StatusOK {
|
||||||
return fmt.Errorf("non-ok response: %s", resp.Status)
|
panic(fmt.Sprintf("non-ok response: %s", resp.Status))
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
if err := maine(); err != nil {
|
|
||||||
fmt.Println(err)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@ package markup
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
||||||
"path/filepath"
|
|
||||||
|
|
||||||
"github.com/alecthomas/chroma/v2"
|
"github.com/alecthomas/chroma/v2"
|
||||||
"github.com/alecthomas/chroma/v2/formatters/html"
|
"github.com/alecthomas/chroma/v2/formatters/html"
|
||||||
|
@ -27,17 +26,10 @@ var (
|
||||||
|
|
||||||
type code struct{}
|
type code struct{}
|
||||||
|
|
||||||
var customReg = map[string]string{
|
|
||||||
".hujson": "json",
|
|
||||||
}
|
|
||||||
|
|
||||||
func setup(source []byte, fileName string) (chroma.Iterator, *chroma.Style, error) {
|
func setup(source []byte, fileName string) (chroma.Iterator, *chroma.Style, error) {
|
||||||
lexer := lexers.Match(fileName)
|
lexer := lexers.Match(fileName)
|
||||||
if lexer == nil {
|
if lexer == nil {
|
||||||
lexer = lexers.Fallback
|
lexer = lexers.Fallback
|
||||||
if name, ok := customReg[filepath.Ext(fileName)]; ok {
|
|
||||||
lexer = lexers.Get(name)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
lexer = chroma.Coalesce(lexer)
|
lexer = chroma.Coalesce(lexer)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue