1
0
forked from x/icebergs
This commit is contained in:
IT 老营长 @云轩领航-创始人 2023-04-16 22:36:19 +08:00
parent 83c959a14e
commit fa23808cba
8 changed files with 139 additions and 149 deletions

View File

@ -20,7 +20,7 @@ func (m *Message) TryCatch(msg *Message, catch bool, cb ...func(msg *Message)) {
default:
fileline := m.FormatStack(2, 1)
m.Log(LOG_WARN, "catch: %s %s", e, fileline).Log("chain", msg.FormatChain())
m.Log(LOG_WARN, "catch: %s %s", e, fileline).Log("stack", m.FormatStack(2, 100))
m.Log(LOG_WARN, "catch: %s %s", e, kit.FileLine(4, 10)).Log("stack", m.FormatStack(2, 100))
m.Log(LOG_WARN, "catch: %s %s", e, fileline).Result(ErrWarn, e, SP, m.FormatStack(2, 5))
if len(cb) > 1 {
m.TryCatch(msg, catch, cb[1:]...)

View File

@ -12,7 +12,7 @@ import (
)
func _count_count(m *ice.Message, arg []string, cb func(string)) {
if m.Warn(len(arg) == 0 || arg[0] == "usr/", ice.ErrNotValid, nfs.DIR, "to many files, please select sub dir") {
if m.Warn(len(arg) == 0 || arg[0] == nfs.USR, ice.ErrNotValid, nfs.DIR, "to many files, please select sub dir") {
return
}
nfs.DirDeepAll(m, "", arg[0], func(value ice.Maps) {
@ -36,18 +36,17 @@ func init() {
Index.MergeCommands(ice.Commands{
COUNT: {Name: "count path auto count order tags", Help: "代码行", Actions: ice.Actions{
COUNT: {Help: "计数", Hand: func(m *ice.Message, arg ...string) {
files := map[string]int{}
lines := map[string]int{}
files, lines := map[string]int{}, map[string]int{}
_count_count(m, arg, func(file string) {
files[mdb.TOTAL]++
files[kit.Ext(file)]++
m.Cmdy(nfs.CAT, file, func(text string) {
if kit.Ext(file) == code.GO {
switch {
case strings.HasPrefix(text, "func "):
lines["_func"]++
case strings.HasPrefix(text, "type "):
lines["_type"]++
case strings.HasPrefix(text, "func "):
lines["_func"]++
}
}
lines[mdb.TOTAL]++
@ -55,7 +54,7 @@ func init() {
})
})
kit.For(lines, func(k string, v int) { m.Push(mdb.TYPE, k).Push("files", files[k]).Push("lines", lines[k]) })
m.StatusTimeCount().SortIntR("lines")
m.SortIntR("lines").StatusTimeCount()
}},
"order": {Help: "排行", Hand: func(m *ice.Message, arg ...string) {
files := map[string]int{}
@ -63,7 +62,7 @@ func init() {
m.Cmdy(nfs.CAT, file, func(text string) { files[strings.TrimPrefix(file, arg[0])]++ })
})
kit.For(files, func(k string, v int) { m.Push("files", k).Push("lines", v) })
m.StatusTimeCount().SortIntR("lines")
m.SortIntR("lines").StatusTimeCount()
}},
"tags": {Help: "索引", Hand: func(m *ice.Message, arg ...string) {
count := map[string]int{}
@ -77,7 +76,7 @@ func init() {
}
})
kit.For(count, func(k string, v int) { m.Push(mdb.TYPE, k).Push(mdb.COUNT, v) })
m.StatusTimeCount().SortIntR(mdb.COUNT)
m.SortIntR(mdb.COUNT).StatusTimeCount()
}},
}, Hand: func(m *ice.Message, arg ...string) { m.Cmdy(nfs.DIR, arg) }},
})

View File

@ -5,6 +5,7 @@ import (
"net/url"
"path"
"strings"
"time"
git "shylinux.com/x/go-git/v5"
"shylinux.com/x/go-git/v5/plumbing"
@ -22,27 +23,15 @@ import (
kit "shylinux.com/x/toolkits"
)
func _repos_cmd(m *ice.Message, name string, arg ...string) *ice.Message {
return m.Copy(_git_cmd(m.Options(cli.CMD_DIR, _repos_path(m, name)), arg...))
}
func _repos_path(m *ice.Message, p string, arg ...string) string {
if p == path.Base(kit.Path("")) {
return kit.Path("", arg...)
}
return path.Join(nfs.USR, p, path.Join(arg...))
}
func _repos_open(m *ice.Message, p string) *git.Repository {
return mdb.HashSelectTarget(m, p, nil).(*git.Repository)
}
func _repos_init(m *ice.Message, p string) {
m.Debug("what %v", p)
git.PlainInit(p, true)
func _repos_cmd(m *ice.Message, p string, arg ...string) *ice.Message {
return m.Copy(_git_cmd(m.Options(cli.CMD_DIR, _repos_path(m, p)), arg...))
}
func _repos_init(m *ice.Message, p string) { git.PlainInit(p, true) }
func _repos_insert(m *ice.Message, p string) {
if repos, err := git.PlainOpen(p); err == nil {
args := []string{REPOS, path.Base(p), nfs.PATH, p}
if refer, err := repos.Head(); err == nil {
args = append(args, BRANCH, refer.Name().String())
args = append(args, BRANCH, strings.TrimPrefix(refer.Name().String(), "refs/heads/"))
if commit, err := repos.CommitObject(refer.Hash()); err == nil {
args = append(args, mdb.TIME, commit.Author.When.Format(ice.MOD_TIME), COMMIT, commit.Message)
}
@ -53,9 +42,18 @@ func _repos_insert(m *ice.Message, p string) {
mdb.HashCreate(m.Options(mdb.TARGET, repos), args)
}
}
func _repos_path(m *ice.Message, p string, arg ...string) string {
if p == path.Base(kit.Path("")) {
return kit.Path("", arg...)
}
return path.Join(nfs.USR, p, path.Join(arg...))
}
func _repos_open(m *ice.Message, p string) *git.Repository {
return mdb.HashSelectTarget(m, p, nil).(*git.Repository)
}
func _repos_each(m *ice.Message, title string, cb func(*git.Repository, ice.Maps) error) {
msg := m.Cmd("")
web.GoToast(m, title, func(toast func(string, int, int)) {
web.GoToast(m, kit.Select(m.CommandKey()+ice.SP+m.ActionKey(), title), func(toast func(string, int, int)) {
list, count, total := []string{}, 0, msg.Length()
msg.Table(func(value ice.Maps) {
toast(value[REPOS], count, total)
@ -81,8 +79,7 @@ func _repos_log(m *ice.Message, repos *git.Repository) error {
}
limit := 30
defer m.StatusTimeCount()
m.Push(mdb.TIME, m.Time())
m.Push(COMMIT, INDEX)
m.Push(mdb.TIME, m.Time()).Push(COMMIT, INDEX)
m.Push(aaa.USERNAME, m.Option(ice.MSG_USERNAME))
m.Push(mdb.TEXT, "add some")
m.Push("files", 0).Push("adds", 0).Push("dels", 0)
@ -119,7 +116,7 @@ func _repos_stats(m *ice.Message, repos *git.Repository, h string) error {
}
return nil
}
func _repos_status(m *ice.Message, repos *git.Repository) error {
func _repos_status(m *ice.Message, p string, repos *git.Repository) error {
work, err := repos.Worktree()
if err != nil {
return err
@ -130,12 +127,10 @@ func _repos_status(m *ice.Message, repos *git.Repository) error {
}
defer m.StatusTimeCount()
for k, v := range status {
switch kit.Ext(k) {
case "swp", "swo":
if kit.IsIn(kit.Ext(k), "swp", "swo") {
continue
}
m.Push(nfs.FILE, k).Push(STATUS, string(v.Worktree)+string(v.Staging))
switch v.Worktree {
switch m.Push(REPOS, p).Push(STATUS, string(v.Worktree)+string(v.Staging)).Push(nfs.FILE, k); v.Worktree {
case git.Untracked:
m.PushButton(ADD, nfs.TRASH)
case git.Modified:
@ -146,12 +141,39 @@ func _repos_status(m *ice.Message, repos *git.Repository) error {
}
return nil
}
func _repos_total(m *ice.Message, p string, repos *git.Repository, stats map[string]int) *time.Time {
iter, err := repos.Log(&git.LogOptions{})
if err != nil {
return nil
}
from, cmts, adds, dels := time.Now(), 0, 0, 0
iter.ForEach(func(commit *object.Commit) error {
from, cmts = commit.Author.When, cmts+1
if stats, err := commit.Stats(); err == nil {
for _, stat := range stats {
adds, dels = adds+stat.Addition, dels+stat.Deletion
}
}
return nil
})
days := kit.Int(time.Now().Sub(from) / time.Hour / 24)
m.Push(REPOS, p).Push("from", from.Format(ice.MOD_TIME)).Push("days", days)
m.Push("commits", cmts).Push("adds", adds).Push("dels", dels).Push("rest", adds-dels)
stats["cmts"] += cmts
stats["adds"] += adds
stats["dels"] += dels
stats["rest"] += adds - dels
if days > stats["days"] {
stats["days"] = days
return &from
}
return nil
}
func _repos_vimer(m *ice.Message, _repos_path func(m *ice.Message, p string, arg ...string) string, arg ...string) {
if len(arg) == 0 || arg[0] != ice.RUN {
arg = []string{path.Join(arg[:2]...), kit.Select("README.md", arg, 2)}
} else if kit.Select("", arg, 1) != ctx.ACTION {
ls := kit.Split(kit.Select(arg[1], m.Option(nfs.DIR_ROOT)), nfs.PS)
if ls[1] == INDEX {
if ls := kit.Split(path.Join(m.Option(nfs.DIR_ROOT), arg[1]), nfs.PS); ls[1] == INDEX {
if len(arg) < 3 {
m.Cmdy(nfs.DIR, nfs.PWD, kit.Dict(nfs.DIR_ROOT, _repos_path(m, ls[0])))
} else {
@ -184,8 +206,8 @@ const (
PULL = "pull"
PUSH = "push"
LOG = "log"
ADD = "add"
TAG = "tag"
ADD = "add"
STASH = "stash"
COMMIT = "commit"
@ -198,7 +220,7 @@ const REPOS = "repos"
func init() {
web.Index.MergeCommands(ice.Commands{
web.PP(ice.REQUIRE): {Name: "/require/shylinux.com/x/volcanos/proto.js", Help: "代码库", Hand: func(m *ice.Message, arg ...string) {
web.PP(ice.REQUIRE): {Name: "/require/shylinux.com/x/volcanos/proto.js", Hand: func(m *ice.Message, arg ...string) {
if len(arg) < 4 {
m.RenderStatusBadRequest()
} else if path.Join(arg[:3]...) == ice.Info.Make.Module && nfs.Exists(m, path.Join(arg[3:]...)) {
@ -226,12 +248,12 @@ func init() {
CLONE: {Name: "clone origin* branch name path", Hand: func(m *ice.Message, arg ...string) {
m.OptionDefault(mdb.NAME, path.Base(m.Option(ORIGIN)))
m.OptionDefault(nfs.PATH, path.Join(path.Join(nfs.USR, m.Option(mdb.NAME))))
_, err := git.PlainClone(m.Option(nfs.PATH), false, &git.CloneOptions{URL: m.Option(ORIGIN)})
m.Warn(err)
_repos_insert(m, m.Option(nfs.PATH))
if _, err := git.PlainClone(m.Option(nfs.PATH), false, &git.CloneOptions{URL: m.Option(ORIGIN)}); m.Warn(err) {
_repos_insert(m, m.Option(nfs.PATH))
}
}},
PULL: {Hand: func(m *ice.Message, arg ...string) {
_repos_each(m, "repos pull", func(repos *git.Repository, value ice.Maps) error {
_repos_each(m, "", func(repos *git.Repository, value ice.Maps) error {
if value[ORIGIN] == "" {
return nil
} else if work, err := repos.Worktree(); err != nil {
@ -247,7 +269,7 @@ func init() {
u := kit.ParseURL(line)
list[u.Host] = u
})
_repos_each(m, "repos push", func(repos *git.Repository, value ice.Maps) error {
_repos_each(m, "", func(repos *git.Repository, value ice.Maps) error {
if value[ORIGIN] == "" {
return nil
}
@ -262,12 +284,21 @@ func init() {
LOG: {Hand: func(m *ice.Message, arg ...string) {
_repos_log(m, _repos_open(m, kit.Select(m.Option(REPOS), arg, 0)))
}},
TAG: {Name: "tag version", Hand: func(m *ice.Message, arg ...string) {
kit.If(m.Option(VERSION) == "", func() { m.Option(VERSION, _status_tag(m, m.Option(TAGS))) })
repos := _repos_open(m, m.Option(REPOS))
if refer, err := repos.Head(); !m.Warn(err) {
_, err := repos.CreateTag(m.Option(VERSION), refer.Hash(), &git.CreateTagOptions{})
m.Warn(err)
}
}},
ADD: {Hand: func(m *ice.Message, arg ...string) {
if work, err := _repos_open(m, m.Option(REPOS)).Worktree(); !m.Warn(err) {
_, err := work.Add(m.Option(nfs.FILE))
m.Warn(err)
}
}},
STASH: {Hand: func(m *ice.Message, arg ...string) { _repos_cmd(m, kit.Select(m.Option(REPOS), arg, 0), STASH) }},
COMMIT: {Name: "commit actions=add,opt,fix comment*=some", Hand: func(m *ice.Message, arg ...string) {
if work, err := _repos_open(m, m.Option(REPOS)).Worktree(); !m.Warn(err) {
_, err := work.Commit(m.Option("actions")+ice.SP+m.Option("comment"), &git.CommitOptions{})
@ -275,34 +306,63 @@ func init() {
}
}},
STATUS: {Hand: func(m *ice.Message, arg ...string) {
_repos_each(m, "repos status", func(repos *git.Repository, value ice.Maps) error { return _repos_status(m, repos) })
if repos := kit.Select(m.Option(REPOS), arg, 0); repos != "" {
_repos_status(m, repos, _repos_open(m, repos))
} else {
_repos_each(m, "", func(repos *git.Repository, value ice.Maps) error {
return _repos_status(m, value[REPOS], repos)
})
}
}},
STASH: {Help: "缓存", Hand: func(m *ice.Message, arg ...string) { _repos_cmd(m, kit.Select(m.Option(REPOS), arg, 0), STASH) }},
TAG: {Name: "tag version", Help: "标签", Hand: func(m *ice.Message, arg ...string) {
kit.If(m.Option(VERSION) == "", func() { m.Option(VERSION, _status_tag(m, m.Option(TAGS))) })
_repos_cmd(m, m.Option(REPOS), TAG, m.Option(VERSION))
_repos_cmd(m, m.Option(REPOS), PUSH, "--tags")
ctx.ProcessRefresh(m)
TOTAL: {Hand: func(m *ice.Message, arg ...string) {
stats := map[string]int{}
if repos := kit.Select(m.Option(REPOS), arg, 0); repos == "" {
var from *time.Time
_repos_each(m, "", func(repos *git.Repository, value ice.Maps) error {
if kit.IsIn(value[REPOS], "go-git", "go-qrcode", "websocket") {
return nil
}
t := _repos_total(m, value[REPOS], repos, stats)
kit.If(t != nil, func() { from = t })
return nil
})
m.Push(REPOS, TOTAL)
m.Push("from", from.Format(ice.MOD_TIME))
m.Push("days", stats["days"])
m.Push("commits", stats["cmts"])
m.Push("adds", stats["adds"])
m.Push("dels", stats["dels"])
m.Push("rest", stats["rest"])
m.SortIntR("rest")
} else {
_repos_total(m, repos, _repos_open(m, repos), stats)
}
m.StatusTimeCount()
}},
code.VIMER: {Hand: func(m *ice.Message, arg ...string) { _repos_vimer(m, _repos_path, arg...) }},
nfs.TRASH: {Hand: func(m *ice.Message, arg ...string) {
m.Assert(m.Option(REPOS) != "" && m.Option(nfs.FILE) != "")
nfs.Trash(m, _repos_path(m, m.Option(REPOS), m.Option(nfs.FILE)))
}},
mdb.REMOVE: {Hand: func(m *ice.Message, arg ...string) {
m.Assert(m.Option(REPOS) != "")
mdb.HashRemove(m, m.Option(REPOS))
nfs.Trash(m, _repos_path(m, m.Option(REPOS), m.Option(nfs.FILE)))
nfs.Trash(m, _repos_path(m, m.Option(REPOS)))
}},
web.DREAM_CREATE: {Hand: func(m *ice.Message, arg ...string) {
kit.If(m.Option(REPOS), func(p string) {
m.Cmd("", CLONE, ORIGIN, p, nfs.PATH, m.Option(cli.CMD_DIR), ice.Maps{cli.CMD_DIR: ""})
})
}},
code.VIMER: {Hand: func(m *ice.Message, arg ...string) { _repos_vimer(m, _repos_path, arg...) }},
}, mdb.HashAction(mdb.SHORT, REPOS, mdb.FIELD, "time,repos,branch,commit,origin"), mdb.ClearOnExitHashAction()), Hand: func(m *ice.Message, arg ...string) {
if len(arg) == 0 {
mdb.HashSelect(m, arg...).Action(CLONE, PULL, PUSH, STATUS)
mdb.HashSelect(m, arg...).Sort(REPOS).Action(CLONE, PULL, PUSH, STATUS, TOTAL)
} else if len(arg) == 1 {
_repos_log(m, _repos_open(m, arg[0]))
m.Action(TOTAL)
} else if len(arg) == 2 {
if repos := _repos_open(m, arg[0]); arg[1] == INDEX {
_repos_status(m, repos)
_repos_status(m, arg[0], repos)
} else {
_repos_stats(m, repos, arg[1])
}

View File

@ -122,7 +122,7 @@ func init() {
mdb.REMOVE: {Hand: func(m *ice.Message, arg ...string) {
m.Assert(m.Option(REPOS) != "")
mdb.HashRemove(m, m.Option(REPOS))
nfs.Trash(m, _service_path(m, m.Option(REPOS), m.Option(nfs.FILE)))
nfs.Trash(m, _service_path(m, m.Option(REPOS)))
}},
RECEIVE_PACK: {Hand: func(m *ice.Message, arg ...string) {
if err := file.ServeReceivePack(arg[0]); err != nil {
@ -138,16 +138,16 @@ func init() {
}},
TOKEN: {Hand: func(m *ice.Message, arg ...string) { m.Cmdy(TOKEN, cli.MAKE) }},
code.VIMER: {Hand: func(m *ice.Message, arg ...string) { _repos_vimer(m, _service_path, arg...) }},
}, mdb.HashAction(mdb.SHORT, REPOS, mdb.FIELD, "time,repos,branch,commit,origin"), mdb.ClearOnExitHashAction()), Hand: func(m *ice.Message, arg ...string) {
}, mdb.HashAction(mdb.SHORT, REPOS, mdb.FIELD, "time,repos,branch,commit"), mdb.ClearOnExitHashAction()), Hand: func(m *ice.Message, arg ...string) {
if len(arg) == 0 {
mdb.HashSelect(m, arg...).Action(mdb.CREATE, TOKEN)
mdb.HashSelect(m, arg...).Sort(REPOS).Action(mdb.CREATE, TOKEN)
m.Echo(strings.ReplaceAll(m.Cmdx("web.code.publish", ice.CONTEXTS), "app username", "dev username"))
m.Echo(m.Cmdx(TOKEN, m.Option(ice.MSG_USERNAME)))
} else if len(arg) == 1 {
_repos_log(m, _repos_open(m, arg[0]))
} else if len(arg) == 2 {
if repos := _repos_open(m, arg[0]); arg[1] == INDEX {
_repos_status(m, repos)
_repos_status(m, arg[0], repos)
} else {
_repos_stats(m, repos, arg[1])
}

View File

@ -1,17 +1,11 @@
package git
import (
"path"
"strings"
ice "shylinux.com/x/icebergs"
"shylinux.com/x/icebergs/base/aaa"
"shylinux.com/x/icebergs/base/cli"
"shylinux.com/x/icebergs/base/ctx"
"shylinux.com/x/icebergs/base/mdb"
"shylinux.com/x/icebergs/base/nfs"
"shylinux.com/x/icebergs/base/web"
"shylinux.com/x/icebergs/core/code"
kit "shylinux.com/x/toolkits"
)
@ -19,48 +13,13 @@ const SPIDE = "spide"
func init() {
Index.MergeCommands(ice.Commands{
SPIDE: {Name: "spide repos auto", Help: "构架图", Actions: ice.MergeActions(ice.Actions{
"depend": {Name: "depend path*=icebergs/base pkg=shy,all", Help: "依赖", Hand: func(m *ice.Message, arg ...string) {
list, keys := map[string]map[string]bool{}, map[string]bool{}
kit.SplitKV(ice.TB, ice.NL, m.Cmdx(cli.SYSTEM, "gotags", "-R", path.Join(ice.USR, m.Option(nfs.PATH))+ice.PS), func(text string, ls []string) {
if strings.HasPrefix(text, "!_") {
return
} else if kit.Select("", ls, 3) != "i" {
return
} else if !strings.Contains(ls[0], m.Option(nfs.PATH)) && m.Option("pkg") == "shy" {
return
}
item, ok := list[ls[0]]
if !ok {
item = map[string]bool{}
list[ls[0]] = item
}
p := strings.TrimPrefix(path.Dir(ls[1]), path.Join(ice.USR, m.Option(nfs.PATH)))
keys[p], item[p] = true, true
})
item := kit.SortedKey(keys)
for k, v := range list {
m.Push("pkg", k).Push(mdb.COUNT, len(v))
for _, i := range item {
m.Push(i, kit.Select("", ice.OK, v[i]))
}
}
m.StatusTimeCount().SortIntR(mdb.COUNT)
}}, code.INNER: {Name: web.CODE_INNER},
}, ctx.CmdAction()), Hand: func(m *ice.Message, arg ...string) {
SPIDE: {Name: "spide repos auto", Help: "构架图", Actions: ctx.CmdAction(), Hand: func(m *ice.Message, arg ...string) {
if len(kit.Slice(arg, 0, 1)) == 0 {
m.Cmdy(REPOS)
} else if len(arg) == 1 {
color := []string{cli.YELLOW, cli.BLUE, cli.CYAN, cli.RED}
nfs.DirDeepAll(m, _repos_path(m, arg[0]), "", func(value ice.Maps) { m.Push("", value, []string{nfs.PATH}) }, nfs.PATH)
m.Options(nfs.DIR_ROOT, _repos_path(m, arg[0])).StatusTimeCount()
ctx.DisplayStory(m, "", mdb.FIELD, nfs.PATH, aaa.ROOT, arg[0])
nfs.DirDeepAll(m, _repos_path(m, arg[0]), "", func(value ice.Maps) {
m.Push(cli.COLOR, color[strings.Count(value[nfs.PATH], ice.PS)%len(color)])
m.Push("", value, []string{nfs.PATH})
}, nfs.PATH)
m.Option(nfs.DIR_ROOT, _repos_path(m, arg[0]))
m.StatusTimeCount()
} else if len(arg) == 2 {
}
}},
})

View File

@ -32,25 +32,6 @@ func _status_tag(m *ice.Message, tags string) string {
return "v0.0.1"
}
}
func _status_each(m *ice.Message, title string, cmds ...string) {
web.GoToast(m, kit.Select(strings.Join(cmds, ice.SP), title), func(toast func(string, int, int)) {
list, count, total := []string{}, 0, m.Cmd(REPOS).Length()
ReposList(m).Table(func(value ice.Maps) {
toast(value[REPOS], count, total)
if msg := m.Cmd(cmds, kit.Dict(cli.CMD_DIR, value[nfs.PATH])); !cli.IsSuccess(msg) {
web.Toast(m, msg.Append(cli.CMD_ERR)+msg.Append(cli.CMD_OUT), "error: "+value[REPOS], "", "3s")
list = append(list, value[REPOS])
m.Sleep3s()
}
count++
})
if len(list) > 0 {
web.Toast(m, strings.Join(list, ice.NL), ice.FAILURE, "30s")
} else {
toast(ice.SUCCESS, count, total)
}
})
}
func _status_stat(m *ice.Message, files, adds, dels int) (int, int, int) {
kit.SplitKV(ice.SP, ice.FS, _git_diff(m), func(text string, ls []string) {
n := kit.Int(ls[0])
@ -189,6 +170,9 @@ func init() {
if _configs_get(m, USER_EMAIL) == "" {
m.Echo("please config user.email").Action(CONFIGS)
} else if len(arg) == 0 {
m.Cmdy(REPOS, STATUS)
m.Action(PULL, PUSH, "insteadof", "oauth").Sort("repos,status,file")
return
files, adds, dels, last := _status_list(m)
m.StatusTimeCount("files", files, "adds", adds, "dels", dels, "last", last.Format(ice.MOD_TIME), nfs.ORIGIN, _git_remote(m))
m.Action(PULL, PUSH, "insteadof", "oauth").Sort("repos,type,file")

View File

@ -22,22 +22,22 @@ func init() {
const (
FROM = "from"
DAYS = "days"
COMMIT = "commit"
ADDS = "adds"
DELS = "dels"
REST = "rest"
COMMIT = "commit"
)
Index.MergeCommands(ice.Commands{
TOTAL: {Name: "total repos auto pie", Help: "统计量", Actions: ice.MergeActions(ice.Actions{
"pie": {Help: "饼图", Hand: func(m *ice.Message, arg ...string) {
defer ctx.DisplayStory(m, "pie.js")
m.Cmd("", func(value ice.Maps) {
if value[REPOS] != mdb.TOTAL {
m.Push(REPOS, value[REPOS]).Push(mdb.VALUE, value[REST]).Push("", value, []string{FROM, DAYS, ADDS, DELS, COMMIT})
}
kit.If(value[REPOS] != mdb.TOTAL, func() {
m.Push(REPOS, value[REPOS]).Push(mdb.VALUE, value[REST]).Push("", value, []string{FROM, DAYS, COMMIT, ADDS, DELS})
})
})
}},
}, ctx.ConfAction("skip", kit.DictList("wubi-dict", "word-dict", "websocket", "go-qrcode", "go-sql-mysql", "echarts"))), Hand: func(m *ice.Message, arg ...string) {
}, ctx.ConfAction("skip", kit.DictList("go-git", "go-qrcode", "websocket"))), Hand: func(m *ice.Message, arg ...string) {
if len(arg) > 0 {
ReposList(m).Table(func(value ice.Maps) {
kit.If(value[REPOS] == arg[0], func() { m.Cmdy("_sum", value[nfs.PATH], arg[1:]) })
@ -45,7 +45,7 @@ func init() {
m.StatusTimeCount(m.AppendSimple(FROM))
return
}
from, days, adds, dels, rest, commit := "", 0, 0, 0, 0, 0
from, days, commit, adds, dels, rest := "", 0, 0, 0, 0, 0
TableGo(ReposList(m), func(value ice.Maps, lock *task.Lock) {
if mdb.Config(m, kit.Keys("skip", value[REPOS])) == ice.TRUE {
return
@ -53,18 +53,16 @@ func init() {
msg := m.Cmd("_sum", value[nfs.PATH], mdb.TOTAL, "10000")
defer lock.Lock()()
msg.Table(func(value ice.Maps) {
if kit.Int(value[DAYS]) > days {
from, days = value[FROM], kit.Int(value[DAYS])
}
kit.If(kit.Int(value[DAYS]) > days, func() { from, days = value[FROM], kit.Int(value[DAYS]) })
commit += kit.Int(value[COMMIT])
adds += kit.Int(value[ADDS])
dels += kit.Int(value[DELS])
rest += kit.Int(value[REST])
commit += kit.Int(value[COMMIT])
})
m.Push(REPOS, value[REPOS]).Copy(msg)
})
m.Push(REPOS, mdb.TOTAL).Push(TAGS, "v3.0.0").Push(FROM, from).Push(DAYS, days).Push(ADDS, adds).Push(DELS, dels).Push(REST, rest).Push(COMMIT, commit)
m.StatusTimeCount().SortIntR(REST)
m.Push(REPOS, mdb.TOTAL).Push(TAGS, "v3.0.0").Push(FROM, from).Push(DAYS, days).Push(COMMIT, commit).Push(ADDS, adds).Push(DELS, dels).Push(REST, rest)
m.SortIntR(REST).StatusTimeCount()
}},
"_sum": {Name: "_sum [path] [total] [count|date] args...", Help: "统计量", Hand: func(m *ice.Message, arg ...string) {
if len(arg) > 0 {
@ -74,9 +72,7 @@ func init() {
}
}
total := false
if len(arg) > 0 && arg[0] == mdb.TOTAL {
total, arg = true, arg[1:]
}
kit.If(len(arg) > 0 && arg[0] == mdb.TOTAL, func() { total, arg = true, arg[1:] })
args := []string{"log", "--shortstat", "--pretty=commit: %ad %n%s", "--date=iso", "--reverse"}
if len(arg) > 0 {
arg[0] += kit.Select("", " 00:00:00", strings.Contains(arg[0], "-") && !strings.Contains(arg[0], ice.DF))
@ -85,7 +81,7 @@ func init() {
} else {
args = append(args, "-n", "30")
}
from, days, adds, dels, commit := "", 0, 0, 0, 0
from, days, commit, adds, dels := "", 0, 0, 0, 0
kit.SplitKV(ice.NL, "commit:", _git_cmds(m, args...), func(text string, ls []string) {
add, del := "0", "0"
for _, v := range kit.Split(strings.TrimSpace(kit.Select("", ls, -1)), ice.FS) {
@ -107,20 +103,13 @@ func init() {
dels += kit.Int(del)
return
}
m.Push(FROM, ls[0])
m.Push(ADDS, add)
m.Push(DELS, del)
m.Push(REST, kit.Int(add)-kit.Int(del))
m.Push(COMMIT, ls[1])
m.Push(FROM, ls[0]).Push(COMMIT, ls[1])
m.Push(ADDS, add).Push(DELS, del).Push(REST, kit.Int(add)-kit.Int(del))
})
if total {
m.Push(TAGS, _git_cmds(m, "describe", "--tags"))
m.Push(FROM, from)
m.Push(DAYS, days)
m.Push(ADDS, adds)
m.Push(DELS, dels)
m.Push(REST, adds-dels)
m.Push(COMMIT, commit)
m.Push(FROM, from).Push(DAYS, days).Push(COMMIT, commit)
m.Push(ADDS, adds).Push(DELS, dels).Push(REST, adds-dels)
}
}},
})

View File

@ -17,8 +17,7 @@ func init() {
if len(arg) == 0 {
m.Cmdy(REPOS)
} else {
m.Cmdy(TOTAL, kit.Slice(arg, 0, 2))
ctx.DisplayStory(m, "")
ctx.DisplayStory(m.Cmdy(TOTAL, kit.Slice(arg, 0, 2)), "")
}
}},
})