mirror of https://github.com/nyancrimew/goop.git
Add discord rich status support to goop
This commit is contained in:
parent
497d6132d5
commit
85db3dad84
1
go.mod
1
go.mod
|
@ -7,6 +7,7 @@ require (
|
||||||
github.com/deletescape/jobtracker v0.0.0-20211024175651-68fbc3d60d80
|
github.com/deletescape/jobtracker v0.0.0-20211024175651-68fbc3d60d80
|
||||||
github.com/go-git/go-billy/v5 v5.0.0
|
github.com/go-git/go-billy/v5 v5.0.0
|
||||||
github.com/go-git/go-git/v5 v5.2.0
|
github.com/go-git/go-git/v5 v5.2.0
|
||||||
|
github.com/hugolgst/rich-go v0.0.0-20210925091458-d59fb695d9c0
|
||||||
github.com/phuslu/log v1.0.75
|
github.com/phuslu/log v1.0.75
|
||||||
github.com/spf13/cobra v1.1.1
|
github.com/spf13/cobra v1.1.1
|
||||||
github.com/valyala/fasthttp v1.16.0
|
github.com/valyala/fasthttp v1.16.0
|
||||||
|
|
4
go.sum
4
go.sum
|
@ -119,6 +119,8 @@ github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO
|
||||||
github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0mNTz8vQ=
|
github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0mNTz8vQ=
|
||||||
github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I=
|
github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I=
|
||||||
github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc=
|
github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc=
|
||||||
|
github.com/hugolgst/rich-go v0.0.0-20210925091458-d59fb695d9c0 h1:IkZfZBWufGFLvci1vXLiUu8PWVtG6wlz920CMtHobMo=
|
||||||
|
github.com/hugolgst/rich-go v0.0.0-20210925091458-d59fb695d9c0/go.mod h1:nGaW7CGfNZnhtiFxMpc4OZdqIexGXjUlBnlmpZmjEKA=
|
||||||
github.com/imdario/mergo v0.3.9 h1:UauaLniWCFHWd+Jp9oCEkTBj8VO/9DKg3PV3VCNMDIg=
|
github.com/imdario/mergo v0.3.9 h1:UauaLniWCFHWd+Jp9oCEkTBj8VO/9DKg3PV3VCNMDIg=
|
||||||
github.com/imdario/mergo v0.3.9/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
|
github.com/imdario/mergo v0.3.9/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
|
||||||
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
|
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
|
||||||
|
@ -353,6 +355,8 @@ gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
|
||||||
gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
|
gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
|
||||||
gopkg.in/ini.v1 v1.63.2 h1:tGK/CyBg7SMzb60vP1M03vNZ3VDu3wGQJwn7Sxi9r3c=
|
gopkg.in/ini.v1 v1.63.2 h1:tGK/CyBg7SMzb60vP1M03vNZ3VDu3wGQJwn7Sxi9r3c=
|
||||||
gopkg.in/ini.v1 v1.63.2/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
|
gopkg.in/ini.v1 v1.63.2/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
|
||||||
|
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce h1:+JknDZhAj8YMt7GC73Ei8pv4MzjDUNPHgQWJdtMAaDU=
|
||||||
|
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce/go.mod h1:5AcXVHNjg+BDxry382+8OKon8SEWiKktQR07RKPsv1c=
|
||||||
gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo=
|
gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo=
|
||||||
gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME=
|
gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME=
|
||||||
gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI=
|
gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI=
|
||||||
|
|
|
@ -24,6 +24,7 @@ import (
|
||||||
"github.com/go-git/go-git/v5/plumbing/object"
|
"github.com/go-git/go-git/v5/plumbing/object"
|
||||||
"github.com/go-git/go-git/v5/storage/filesystem"
|
"github.com/go-git/go-git/v5/storage/filesystem"
|
||||||
"github.com/go-git/go-git/v5/storage/filesystem/dotgit"
|
"github.com/go-git/go-git/v5/storage/filesystem/dotgit"
|
||||||
|
"github.com/hugolgst/rich-go/client"
|
||||||
"github.com/phuslu/log"
|
"github.com/phuslu/log"
|
||||||
"github.com/valyala/fasthttp"
|
"github.com/valyala/fasthttp"
|
||||||
"github.com/valyala/fasthttp/fasthttpproxy"
|
"github.com/valyala/fasthttp/fasthttpproxy"
|
||||||
|
@ -99,6 +100,37 @@ func CloneList(listFile, baseDir string, force, keep bool) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var startTime = time.Now()
|
||||||
|
|
||||||
|
func updateStatus(state, baseUrl string) {
|
||||||
|
parsed, _ := url.Parse(baseUrl)
|
||||||
|
|
||||||
|
err := client.SetActivity(client.Activity{
|
||||||
|
State: state,
|
||||||
|
Details: fmt.Sprintf("Dumping %s", parsed.Hostname()),
|
||||||
|
Timestamps: &client.Timestamps{
|
||||||
|
Start: &startTime,
|
||||||
|
},
|
||||||
|
LargeImage: "git-icon",
|
||||||
|
LargeText: "goop house next up",
|
||||||
|
SmallImage: "git-icon",
|
||||||
|
SmallText: "goop house next up",
|
||||||
|
Buttons: []*client.Button{
|
||||||
|
{
|
||||||
|
Label: "View .git/config",
|
||||||
|
Url: utils.Url(baseUrl, ".git/config"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Label: "Download goop",
|
||||||
|
Url: "https://github.com/deletescape/goop",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
log.Error().Err(err).Msg("couldn't publish discord rich status")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func Clone(u, dir string, force, keep bool) error {
|
func Clone(u, dir string, force, keep bool) error {
|
||||||
baseUrl := strings.TrimSuffix(u, "/")
|
baseUrl := strings.TrimSuffix(u, "/")
|
||||||
baseUrl = strings.TrimSuffix(baseUrl, "/HEAD")
|
baseUrl = strings.TrimSuffix(baseUrl, "/HEAD")
|
||||||
|
@ -143,7 +175,12 @@ func Clone(u, dir string, force, keep bool) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func FetchGit(baseUrl, baseDir string) error {
|
func FetchGit(baseUrl, baseDir string) error {
|
||||||
|
err := client.Login("906528897976397834")
|
||||||
|
if err != nil {
|
||||||
|
log.Error().Err(err).Msg("couldn't connect to discord")
|
||||||
|
}
|
||||||
log.Info().Str("base", baseUrl).Msg("testing for .git/HEAD")
|
log.Info().Str("base", baseUrl).Msg("testing for .git/HEAD")
|
||||||
|
updateStatus("testing for .git/HEAD", baseUrl)
|
||||||
code, body, err := c.Get(nil, utils.Url(baseUrl, ".git/HEAD"))
|
code, body, err := c.Get(nil, utils.Url(baseUrl, ".git/HEAD"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -156,6 +193,7 @@ func FetchGit(baseUrl, baseDir string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Info().Str("base", baseUrl).Msg("testing if recursive download is possible")
|
log.Info().Str("base", baseUrl).Msg("testing if recursive download is possible")
|
||||||
|
updateStatus("testing for recursive download", baseUrl)
|
||||||
code, body, err = c.Get(body, utils.Url(baseUrl, ".git/"))
|
code, body, err = c.Get(body, utils.Url(baseUrl, ".git/"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if utils.IgnoreError(err) {
|
if utils.IgnoreError(err) {
|
||||||
|
@ -173,6 +211,7 @@ func FetchGit(baseUrl, baseDir string) error {
|
||||||
}
|
}
|
||||||
if utils.StringsContain(indexedFiles, "HEAD") {
|
if utils.StringsContain(indexedFiles, "HEAD") {
|
||||||
log.Info().Str("base", baseUrl).Msg("fetching .git/ recursively")
|
log.Info().Str("base", baseUrl).Msg("fetching .git/ recursively")
|
||||||
|
updateStatus("fetching .git recursively", baseUrl)
|
||||||
jt := jobtracker.NewJobTracker(workers.RecursiveDownloadWorker, maxConcurrency, jobtracker.DefaultNapper)
|
jt := jobtracker.NewJobTracker(workers.RecursiveDownloadWorker, maxConcurrency, jobtracker.DefaultNapper)
|
||||||
jt.AddJobs(indexedFiles...)
|
jt.AddJobs(indexedFiles...)
|
||||||
jt.StartAndWait(&workers.RecursiveDownloadContext{C: c, BaseUrl: baseUrl, BaseDir: baseDir}, true)
|
jt.StartAndWait(&workers.RecursiveDownloadContext{C: c, BaseUrl: baseUrl, BaseDir: baseDir}, true)
|
||||||
|
@ -187,16 +226,19 @@ func FetchGit(baseUrl, baseDir string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Info().Str("base", baseUrl).Msg("fetching common files")
|
log.Info().Str("base", baseUrl).Msg("fetching common files")
|
||||||
|
updateStatus("fetching common files", baseUrl)
|
||||||
jt := jobtracker.NewJobTracker(workers.DownloadWorker, maxConcurrency, jobtracker.DefaultNapper)
|
jt := jobtracker.NewJobTracker(workers.DownloadWorker, maxConcurrency, jobtracker.DefaultNapper)
|
||||||
jt.AddJobs(commonFiles...)
|
jt.AddJobs(commonFiles...)
|
||||||
jt.StartAndWait(workers.DownloadContext{C: c, BaseDir: baseDir, BaseUrl: baseUrl}, false)
|
jt.StartAndWait(workers.DownloadContext{C: c, BaseDir: baseDir, BaseUrl: baseUrl}, false)
|
||||||
|
|
||||||
log.Info().Str("base", baseUrl).Msg("finding refs")
|
log.Info().Str("base", baseUrl).Msg("finding refs")
|
||||||
|
updateStatus("finding refs", baseUrl)
|
||||||
jt = jobtracker.NewJobTracker(workers.FindRefWorker, maxConcurrency, jobtracker.DefaultNapper)
|
jt = jobtracker.NewJobTracker(workers.FindRefWorker, maxConcurrency, jobtracker.DefaultNapper)
|
||||||
jt.AddJobs(commonRefs...)
|
jt.AddJobs(commonRefs...)
|
||||||
jt.StartAndWait(workers.FindRefContext{C: c, BaseUrl: baseUrl, BaseDir: baseDir}, true)
|
jt.StartAndWait(workers.FindRefContext{C: c, BaseUrl: baseUrl, BaseDir: baseDir}, true)
|
||||||
|
|
||||||
log.Info().Str("base", baseUrl).Msg("finding packs")
|
log.Info().Str("base", baseUrl).Msg("finding packs")
|
||||||
|
updateStatus("finding packs", baseUrl)
|
||||||
infoPacksPath := utils.Url(baseDir, ".git/objects/info/packs")
|
infoPacksPath := utils.Url(baseDir, ".git/objects/info/packs")
|
||||||
if utils.Exists(infoPacksPath) {
|
if utils.Exists(infoPacksPath) {
|
||||||
infoPacks, err := ioutil.ReadFile(infoPacksPath)
|
infoPacks, err := ioutil.ReadFile(infoPacksPath)
|
||||||
|
@ -216,6 +258,7 @@ func FetchGit(baseUrl, baseDir string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Info().Str("base", baseUrl).Msg("finding objects")
|
log.Info().Str("base", baseUrl).Msg("finding objects")
|
||||||
|
updateStatus("finding objects", baseUrl)
|
||||||
objs := make(map[string]bool) // object "set"
|
objs := make(map[string]bool) // object "set"
|
||||||
//var packed_objs [][]byte
|
//var packed_objs [][]byte
|
||||||
|
|
||||||
|
@ -395,6 +438,7 @@ func FetchGit(baseUrl, baseDir string) error {
|
||||||
} */
|
} */
|
||||||
|
|
||||||
log.Info().Str("base", baseUrl).Msg("fetching objects")
|
log.Info().Str("base", baseUrl).Msg("fetching objects")
|
||||||
|
updateStatus("fetching objects", baseUrl)
|
||||||
jt = jobtracker.NewJobTracker(workers.FindObjectsWorker, maxConcurrency, jobtracker.DefaultNapper)
|
jt = jobtracker.NewJobTracker(workers.FindObjectsWorker, maxConcurrency, jobtracker.DefaultNapper)
|
||||||
for obj := range objs {
|
for obj := range objs {
|
||||||
jt.AddJob(obj)
|
jt.AddJob(obj)
|
||||||
|
@ -408,6 +452,7 @@ func FetchGit(baseUrl, baseDir string) error {
|
||||||
|
|
||||||
fetchMissing(baseDir, baseUrl, objStorage)
|
fetchMissing(baseDir, baseUrl, objStorage)
|
||||||
|
|
||||||
|
updateStatus("running git checkout", baseUrl)
|
||||||
// TODO: disable lfs in checkout (for now lfs support depends on lfs NOT being setup on the system you use goop on)
|
// TODO: disable lfs in checkout (for now lfs support depends on lfs NOT being setup on the system you use goop on)
|
||||||
if err := checkout(baseDir); err != nil {
|
if err := checkout(baseDir); err != nil {
|
||||||
log.Error().Str("dir", baseDir).Err(err).Msg("failed to checkout")
|
log.Error().Str("dir", baseDir).Err(err).Msg("failed to checkout")
|
||||||
|
@ -434,6 +479,7 @@ func fetchLfs(baseDir, baseUrl string) {
|
||||||
attrPath := utils.Url(baseDir, ".gitattributes")
|
attrPath := utils.Url(baseDir, ".gitattributes")
|
||||||
if utils.Exists(attrPath) {
|
if utils.Exists(attrPath) {
|
||||||
log.Info().Str("dir", baseDir).Msg("attempting to fetch potential git lfs objects")
|
log.Info().Str("dir", baseDir).Msg("attempting to fetch potential git lfs objects")
|
||||||
|
updateStatus("fetching lfs objects", baseUrl)
|
||||||
f, err := os.Open(attrPath)
|
f, err := os.Open(attrPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Str("dir", baseDir).Err(err).Msg("couldn't read git attributes")
|
log.Error().Str("dir", baseDir).Err(err).Msg("couldn't read git attributes")
|
||||||
|
@ -531,6 +577,7 @@ func fetchMissing(baseDir, baseUrl string, objStorage *filesystem.ObjectStorage)
|
||||||
indexPath := utils.Url(baseDir, ".git/index")
|
indexPath := utils.Url(baseDir, ".git/index")
|
||||||
if utils.Exists(indexPath) {
|
if utils.Exists(indexPath) {
|
||||||
log.Info().Str("base", baseUrl).Str("dir", baseDir).Msg("attempting to fetch potentially missing files")
|
log.Info().Str("base", baseUrl).Str("dir", baseDir).Msg("attempting to fetch potentially missing files")
|
||||||
|
updateStatus("fetching missing files", baseUrl)
|
||||||
|
|
||||||
var missingFiles []string
|
var missingFiles []string
|
||||||
var idx index.Index
|
var idx index.Index
|
||||||
|
@ -569,6 +616,7 @@ func fetchIgnored(baseDir, baseUrl string) error {
|
||||||
ignorePath := utils.Url(baseDir, ".gitignore")
|
ignorePath := utils.Url(baseDir, ".gitignore")
|
||||||
if utils.Exists(ignorePath) {
|
if utils.Exists(ignorePath) {
|
||||||
log.Info().Str("base", baseDir).Msg("atempting to fetch ignored files")
|
log.Info().Str("base", baseDir).Msg("atempting to fetch ignored files")
|
||||||
|
updateStatus("fetching ignored files", baseUrl)
|
||||||
|
|
||||||
ignoreFile, err := os.Open(ignorePath)
|
ignoreFile, err := os.Open(ignorePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue