forked from x/icebergs
opt git
This commit is contained in:
parent
0d20a27ee0
commit
38e0594e2a
@ -1,11 +1,6 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
ice "github.com/shylinux/icebergs"
|
||||
"github.com/shylinux/icebergs/base/cli"
|
||||
"github.com/shylinux/icebergs/base/mdb"
|
||||
kit "github.com/shylinux/toolkits"
|
||||
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"io"
|
||||
@ -17,6 +12,11 @@ import (
|
||||
"path"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
ice "github.com/shylinux/icebergs"
|
||||
"github.com/shylinux/icebergs/base/cli"
|
||||
"github.com/shylinux/icebergs/base/mdb"
|
||||
kit "github.com/shylinux/toolkits"
|
||||
)
|
||||
|
||||
func _spide_create(m *ice.Message, name, address string) {
|
||||
|
21
data.go
21
data.go
@ -1,6 +1,8 @@
|
||||
package ice
|
||||
|
||||
import (
|
||||
"sync"
|
||||
|
||||
kit "github.com/shylinux/toolkits"
|
||||
"github.com/shylinux/toolkits/miss"
|
||||
)
|
||||
@ -10,7 +12,24 @@ func (m *Message) Richs(prefix string, chain interface{}, raw interface{}, cb in
|
||||
if cache == nil {
|
||||
return nil
|
||||
}
|
||||
return miss.Richs(kit.Keys(prefix, chain), cache, raw, cb)
|
||||
|
||||
switch cb := cb.(type) {
|
||||
case func(*sync.Mutex, string, map[string]interface{}):
|
||||
mu := &sync.Mutex{}
|
||||
wg := &sync.WaitGroup{}
|
||||
res = miss.Richs(kit.Keys(prefix, chain), cache, raw, func(key string, value map[string]interface{}) {
|
||||
wg.Add(1)
|
||||
m.Go(func() {
|
||||
defer wg.Done()
|
||||
cb(mu, key, value)
|
||||
})
|
||||
})
|
||||
wg.Wait()
|
||||
default:
|
||||
res = miss.Richs(kit.Keys(prefix, chain), cache, raw, cb)
|
||||
}
|
||||
return res
|
||||
|
||||
}
|
||||
func (m *Message) Rich(prefix string, chain interface{}, data interface{}) string {
|
||||
cache := m.Confm(prefix, chain)
|
||||
|
6
go.mod
6
go.mod
@ -6,10 +6,8 @@ require (
|
||||
github.com/AaronO/go-git-http v0.0.0-20161214145340-1d9485b3a98f
|
||||
github.com/Baozisoftware/qrcode-terminal-go v0.0.0-20170407111555-c0650d8dff0f
|
||||
github.com/gorilla/websocket v1.4.2
|
||||
github.com/kr/pty v1.1.8
|
||||
github.com/mattn/go-colorable v0.1.8
|
||||
github.com/nareix/joy4 v0.0.0-20200507095837-05a4ffbb5369
|
||||
github.com/shylinux/toolkits v0.2.2
|
||||
github.com/shylinux/toolkits v0.2.3
|
||||
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
|
||||
golang.org/x/crypto v0.0.0-20201208171446-5f87f3452ae9
|
||||
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2
|
||||
)
|
||||
|
39
go.sum
39
go.sum
@ -1,40 +1,17 @@
|
||||
github.com/AaronO/go-git-http v0.0.0-20161214145340-1d9485b3a98f/go.mod h1:+6Yuq73F9068Na+mSBNXCvyuxvgw4f/g5ii40e3U8Sc=
|
||||
github.com/Baozisoftware/qrcode-terminal-go v0.0.0-20170407111555-c0650d8dff0f h1:2dk3eOnYllh+wUOuDhOoC2vUVoJF/5z478ryJ+wzEII=
|
||||
github.com/Baozisoftware/qrcode-terminal-go v0.0.0-20170407111555-c0650d8dff0f/go.mod h1:4a58ifQTEe2uwwsaqbh3i2un5/CBPg+At/qHpt18Tmk=
|
||||
github.com/creack/pty v1.1.7 h1:6pwm8kMQKCmgUg0ZHTm5+/YvRK0s3THD/28+T6/kk4A=
|
||||
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
|
||||
github.com/google/uuid v1.1.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
|
||||
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/pty v1.1.8 h1:AkaSdXYQOWeaO3neb8EM634ahkXXe3jYbVh/F9lq+GI=
|
||||
github.com/kr/pty v1.1.8/go.mod h1:O1sed60cT9XZ5uDucP5qwvh+TE3NnUj51EiZO/lmSfw=
|
||||
github.com/maruel/rs v0.0.0-20150922171536-2c81c4312fe4/go.mod h1:kcRFpEzolcEklV6rD7W95mG49/sbdX/PlFmd7ni3RvA=
|
||||
github.com/mattn/go-colorable v0.1.8 h1:c1ghPdyEDarC70ftn0y+A/Ee++9zz8ljHG1b13eJ0s8=
|
||||
github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
|
||||
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
|
||||
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
|
||||
github.com/nareix/joy4 v0.0.0-20200507095837-05a4ffbb5369/go.mod h1:aFJ1ZwLjvHN4yEzE5Bkz8rD8/d8Vlj3UIuvz2yfET7I=
|
||||
github.com/shylinux/toolkits v0.2.0 h1:ZMJGFqqgZBXxu2jUw2Zqu8Vx8KhEgWcMBnlH3cR+MPQ=
|
||||
github.com/shylinux/toolkits v0.2.0/go.mod h1:Y68Ot6xOmo1bun67YvqC3chDGeU2gDxtsUnvVDGJm4g=
|
||||
github.com/shylinux/toolkits v0.2.1 h1:FNCL4Tz6KRHjJbJFGswRLAROzo/AJavW+MrcIOEuB34=
|
||||
github.com/shylinux/toolkits v0.2.1/go.mod h1:Y68Ot6xOmo1bun67YvqC3chDGeU2gDxtsUnvVDGJm4g=
|
||||
github.com/shylinux/toolkits v0.2.2 h1:98AsnjCetFifxV89HrsYv0sdusNiu41D3pvQHbWgPec=
|
||||
github.com/shylinux/toolkits v0.2.2/go.mod h1:oMwi/N00I2cXenmcAkqikEncTzB4u5JhTQ9mO5xj7sY=
|
||||
github.com/shylinux/toolkits v0.2.3 h1:UdE5dUKtc+iVeco9sFrlj98BxVJADYoLNeywTnLrSMc=
|
||||
github.com/shylinux/toolkits v0.2.3/go.mod h1:oMwi/N00I2cXenmcAkqikEncTzB4u5JhTQ9mO5xj7sY=
|
||||
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e h1:MRM5ITcdelLK2j1vwZ3Je0FKVCfqOLp5zO6trqMLYs0=
|
||||
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e/go.mod h1:XV66xRDqSt+GTGFMVlhk3ULuV0y9ZmzeVGR4mloJI3M=
|
||||
github.com/tuotoo/qrcode v0.0.0-20190222102259-ac9c44189bf2/go.mod h1:lPnW9HVS0vJdeYyQtOvIvlXgZPNhUAhwz+z5r8AJk0Y=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20201208171446-5f87f3452ae9 h1:sYNJzB4J8toYPQTM6pAkcmBRgw9SnQKP9oXCHfgy604=
|
||||
golang.org/x/crypto v0.0.0-20201208171446-5f87f3452ae9/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae h1:/WDfKMnPU+m5M4xB+6x4kaepxRw6jWvR5iDRdvjHgy8=
|
||||
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221 h1:/ZHdbVpdR/jk3g30/d4yUL0JU9kksj8+F/bnQUVLGDM=
|
||||
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
|
@ -7,9 +7,6 @@ import (
|
||||
"github.com/shylinux/icebergs/base/web"
|
||||
kit "github.com/shylinux/toolkits"
|
||||
|
||||
"github.com/nareix/joy4/av"
|
||||
"github.com/nareix/joy4/av/avutil"
|
||||
|
||||
"path"
|
||||
)
|
||||
|
||||
@ -43,24 +40,6 @@ func init() {
|
||||
|
||||
p := path.Join(m.Conf(m.Prefix(CACHE), kit.META_PATH), m.Option(kit.MDB_NAME))
|
||||
m.Cmdy(nfs.LINK, p, msg.Append(kit.MDB_FILE))
|
||||
|
||||
if file, e := avutil.Open(p); e == nil {
|
||||
defer file.Close()
|
||||
|
||||
if streams, e := file.Streams(); e == nil {
|
||||
for _, stream := range streams {
|
||||
|
||||
switch {
|
||||
case stream.Type().IsAudio():
|
||||
case stream.Type().IsVideo():
|
||||
// 自动分屏
|
||||
vstream := stream.(av.VideoCodecData)
|
||||
m.Cmd(nfs.LINK, path.Join(m.Conf(m.Prefix(CACHE), kit.META_PATH),
|
||||
kit.Select("竖屏", "横屏", vstream.Width() > vstream.Height()), m.Option(kit.MDB_NAME)), p)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}},
|
||||
mdb.REMOVE: {Name: "remove", Help: "删除", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(mdb.DELETE, m.Prefix(CACHE), "", mdb.HASH, kit.MDB_HASH, m.Option(kit.MDB_HASH))
|
||||
|
@ -1,6 +1,8 @@
|
||||
package git
|
||||
|
||||
import (
|
||||
"path"
|
||||
|
||||
ice "github.com/shylinux/icebergs"
|
||||
"github.com/shylinux/icebergs/base/cli"
|
||||
"github.com/shylinux/icebergs/base/gdb"
|
||||
@ -8,9 +10,6 @@ import (
|
||||
"github.com/shylinux/icebergs/base/web"
|
||||
"github.com/shylinux/icebergs/core/code"
|
||||
kit "github.com/shylinux/toolkits"
|
||||
|
||||
"os"
|
||||
"path"
|
||||
)
|
||||
|
||||
const GIT = "git"
|
||||
@ -18,20 +17,20 @@ const GIT = "git"
|
||||
var Index = &ice.Context{Name: GIT, Help: "代码库",
|
||||
Configs: map[string]*ice.Config{
|
||||
GIT: {Name: GIT, Help: "代码库", Value: kit.Data(
|
||||
"source", "https://mirrors.edge.kernel.org/pub/software/scm/git/git-1.8.3.1.tar.gz", "config", kit.Dict(
|
||||
kit.SSH_SOURCE, "https://mirrors.edge.kernel.org/pub/software/scm/git/git-1.8.3.1.tar.gz", "config", kit.Dict(
|
||||
"alias", kit.Dict("s", "status", "b", "branch"),
|
||||
"credential", kit.Dict("helper", "store"),
|
||||
"core", kit.Dict("quotepath", "false"),
|
||||
"push", kit.Dict("default", "simple"),
|
||||
"color", kit.Dict("ui", "true"),
|
||||
"color", kit.Dict("ui", "always"),
|
||||
),
|
||||
)},
|
||||
},
|
||||
Commands: map[string]*ice.Command{
|
||||
ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
wd, _ := os.Getwd()
|
||||
_repos_insert(m, path.Base(wd), wd)
|
||||
_repos_insert(m, path.Base(kit.Pwd()), kit.Pwd())
|
||||
|
||||
m.Cmd(nfs.DIR, "usr", "name,path").Table(func(index int, value map[string]string, head []string) {
|
||||
m.Cmd(nfs.DIR, kit.SSH_USR, "name,path").Table(func(index int, value map[string]string, head []string) {
|
||||
_repos_insert(m, value[kit.MDB_NAME], value[kit.MDB_PATH])
|
||||
})
|
||||
}},
|
||||
@ -44,13 +43,13 @@ var Index = &ice.Context{Name: GIT, Help: "代码库",
|
||||
m.Cmdy(code.INSTALL, gdb.BUILD, m.Conf(GIT, kit.META_SOURCE))
|
||||
}},
|
||||
gdb.START: {Name: "start", Help: "启动", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Optionv("prepare", func(p string) []string {
|
||||
m.Optionv(code.PREPARE, func(p string) []string {
|
||||
m.Option(cli.CMD_DIR, p)
|
||||
// kit.Fetch(m.Confv(GIT, "meta.config"), func(conf string, value interface{}) {
|
||||
// kit.Fetch(value, func(key string, value string) {
|
||||
// m.Cmd(cli.SYSTEM, "bin/git", "config", "--global", conf+"."+key, value)
|
||||
// })
|
||||
// })
|
||||
kit.Fetch(m.Confv(GIT, kit.Keym("config")), func(conf string, value interface{}) {
|
||||
kit.Fetch(value, func(key string, value string) {
|
||||
m.Cmd(cli.SYSTEM, "bin/git", "config", "--global", conf+"."+key, value)
|
||||
})
|
||||
})
|
||||
return []string{}
|
||||
})
|
||||
m.Cmdy(code.INSTALL, gdb.START, m.Conf(GIT, kit.META_SOURCE), "bin/git")
|
||||
|
@ -31,7 +31,7 @@ cd ./_install
|
||||
chapter "应用"
|
||||
field "代码库" web.code.git.repos
|
||||
field "统计量" web.code.git.total
|
||||
field "提交趋势" web.code.git.trend args icebergs
|
||||
field "代码结构" web.code.git.spide args icebergs
|
||||
field "代码管理" web.code.git.status
|
||||
field "趋势图" web.code.git.trend args `icebergs`
|
||||
field "架构图" web.code.git.spide args `icebergs`
|
||||
field "状态机" web.code.git.status
|
||||
|
||||
|
@ -1,28 +1,25 @@
|
||||
package git
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
ice "github.com/shylinux/icebergs"
|
||||
"github.com/shylinux/icebergs/base/cli"
|
||||
"github.com/shylinux/icebergs/base/mdb"
|
||||
"github.com/shylinux/icebergs/base/nfs"
|
||||
kit "github.com/shylinux/toolkits"
|
||||
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func _repos_path(name string) string {
|
||||
if wd, _ := os.Getwd(); name != path.Base(wd) {
|
||||
return path.Join("usr", name)
|
||||
}
|
||||
return "./"
|
||||
return kit.Select(path.Join(kit.SSH_USR, name), "./", name == path.Base(kit.Pwd()))
|
||||
}
|
||||
func _repos_insert(m *ice.Message, name string, dir string) {
|
||||
if s, e := os.Stat(m.Option(cli.CMD_DIR, path.Join(dir, ".git"))); e == nil && s.IsDir() {
|
||||
ls := strings.SplitN(strings.Trim(m.Cmdx(cli.SYSTEM, GIT, "log", "-n1", `--pretty=format:"%ad %s"`, "--date=iso"), "\""), " ", 4)
|
||||
m.Rich(REPOS, nil, kit.Data(
|
||||
kit.MDB_NAME, name, kit.MDB_PATH, dir,
|
||||
ls := strings.SplitN(strings.Trim(m.Cmdx(cli.SYSTEM, GIT, "log", "-n1", `--pretty=format:"%ad %s"`, "--date=iso"), `"`), " ", 4)
|
||||
m.Rich(REPOS, nil, kit.Data(kit.MDB_NAME, name, kit.MDB_PATH, dir,
|
||||
COMMIT, kit.Select("", ls, 3), kit.MDB_TIME, strings.Join(ls[:2], " "),
|
||||
BRANCH, strings.TrimSpace(m.Cmdx(cli.SYSTEM, GIT, BRANCH)),
|
||||
REMOTE, strings.TrimSpace(m.Cmdx(cli.SYSTEM, GIT, REMOTE, "-v")),
|
||||
@ -35,56 +32,62 @@ const (
|
||||
ORIGIN = "origin"
|
||||
BRANCH = "branch"
|
||||
MASTER = "master"
|
||||
|
||||
CLONE = "clone"
|
||||
ADD = "add"
|
||||
|
||||
INIT = "init"
|
||||
PULL = "pull"
|
||||
PUSH = "push"
|
||||
)
|
||||
const REPOS = "repos"
|
||||
|
||||
func init() {
|
||||
Index.Merge(&ice.Context{
|
||||
Configs: map[string]*ice.Config{
|
||||
REPOS: {Name: REPOS, Help: "仓库", Value: kit.Data(
|
||||
kit.MDB_SHORT, kit.MDB_NAME, kit.MDB_FIELD, "time,name,branch,commit",
|
||||
"owner", "https://github.com/shylinux",
|
||||
REPOS: {Name: REPOS, Help: "代码库", Value: kit.Data(
|
||||
kit.MDB_SHORT, kit.MDB_NAME, kit.SSH_REPOS, "https://github.com/shylinux",
|
||||
)},
|
||||
},
|
||||
Commands: map[string]*ice.Command{
|
||||
REPOS: {Name: "repos name path auto create", Help: "代码库", Action: map[string]*ice.Action{
|
||||
mdb.CREATE: {Name: "create repos branch name path", Help: "添加", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Option(kit.MDB_NAME, kit.Select(strings.TrimSuffix(path.Base(m.Option(kit.SSH_REPOS)), ".git"), m.Option(kit.MDB_NAME)))
|
||||
m.Option(kit.MDB_PATH, kit.Select(path.Join("usr", m.Option(kit.MDB_NAME)), m.Option(kit.MDB_PATH)))
|
||||
m.Option(kit.SSH_REPOS, kit.Select(m.Conf(REPOS, "meta.owner")+"/"+m.Option(kit.MDB_NAME), m.Option(kit.SSH_REPOS)))
|
||||
m.Option(kit.MDB_PATH, kit.Select(path.Join(kit.SSH_USR, m.Option(kit.MDB_NAME)), m.Option(kit.MDB_PATH)))
|
||||
m.Option(kit.SSH_REPOS, kit.Select(m.Conf(REPOS, kit.Keym(kit.SSH_REPOS))+"/"+m.Option(kit.MDB_NAME), m.Option(kit.SSH_REPOS)))
|
||||
|
||||
if _, e := os.Stat(path.Join(m.Option(kit.MDB_PATH), ".git")); e != nil && os.IsNotExist(e) {
|
||||
// 下载仓库
|
||||
if _, e := os.Stat(m.Option(kit.MDB_PATH)); e == nil {
|
||||
m.Option(cli.CMD_DIR, m.Option(kit.MDB_PATH))
|
||||
m.Cmd(cli.SYSTEM, GIT, "init")
|
||||
m.Cmd(cli.SYSTEM, GIT, REMOTE, "add", ORIGIN, m.Option(kit.SSH_REPOS))
|
||||
m.Cmd(cli.SYSTEM, GIT, "pull", ORIGIN, MASTER)
|
||||
} else {
|
||||
m.Cmd(cli.SYSTEM, GIT, "clone", "-b", kit.Select(MASTER, m.Option(BRANCH)),
|
||||
m.Option(kit.SSH_REPOS), m.Option(kit.MDB_PATH))
|
||||
|
||||
}
|
||||
_repos_insert(m, m.Option(kit.MDB_NAME), m.Option(kit.MDB_PATH))
|
||||
if s, e := os.Stat(path.Join(m.Option(kit.MDB_PATH), ".git")); e == nil && s.IsDir() {
|
||||
return
|
||||
}
|
||||
|
||||
// 下载仓库
|
||||
if s, e := os.Stat(m.Option(kit.MDB_PATH)); e == nil && s.IsDir() {
|
||||
m.Option(cli.CMD_DIR, m.Option(kit.MDB_PATH))
|
||||
m.Cmd(cli.SYSTEM, GIT, INIT)
|
||||
m.Cmd(cli.SYSTEM, GIT, REMOTE, ADD, ORIGIN, m.Option(kit.SSH_REPOS))
|
||||
m.Cmd(cli.SYSTEM, GIT, PULL, ORIGIN, MASTER)
|
||||
} else {
|
||||
m.Cmd(cli.SYSTEM, GIT, CLONE, "-b", kit.Select(MASTER, m.Option(BRANCH)),
|
||||
m.Option(kit.SSH_REPOS), m.Option(kit.MDB_PATH))
|
||||
}
|
||||
|
||||
_repos_insert(m, m.Option(kit.MDB_NAME), m.Option(kit.MDB_PATH))
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
if len(arg) > 0 {
|
||||
if wd, _ := os.Getwd(); arg[0] != path.Base(wd) {
|
||||
m.Option(nfs.DIR_ROOT, path.Join("usr", arg[0]))
|
||||
}
|
||||
file := kit.Select("./", path.Join(arg[1:]...))
|
||||
if strings.HasSuffix(file, "/") {
|
||||
m.Cmdy(nfs.DIR, file)
|
||||
} else {
|
||||
m.Cmdy(nfs.CAT, file)
|
||||
}
|
||||
if len(arg) == 0 { // 仓库列表
|
||||
m.Option(mdb.FIELDS, "time,name,branch,commit")
|
||||
m.Cmdy(mdb.SELECT, m.Prefix(REPOS), "", mdb.HASH)
|
||||
m.Sort(kit.MDB_NAME)
|
||||
return
|
||||
}
|
||||
|
||||
m.Option(mdb.FIELDS, m.Conf(REPOS, kit.META_FIELD))
|
||||
m.Cmdy(mdb.SELECT, m.Prefix(REPOS), "", mdb.HASH, kit.MDB_NAME, arg)
|
||||
m.Sort(kit.MDB_NAME)
|
||||
m.Option(nfs.DIR_ROOT, _repos_path(arg[0]))
|
||||
m.Cmdy(nfs.CAT, kit.Select("./", arg, 1), "time,line,path")
|
||||
|
||||
m.Option(cli.CMD_DIR, _repos_path(arg[0]))
|
||||
p := strings.TrimPrefix(strings.TrimPrefix(m.Cmdx(cli.SYSTEM, GIT, REMOTE, "get-url", ORIGIN), "http://"), "https://")
|
||||
pp := kit.MergeURL2(m.Option(ice.MSG_USERWEB), fmt.Sprintf("/code/git/%s", strings.TrimSpace(p)))
|
||||
m.EchoScript(fmt.Sprintf("git clone %s", pp))
|
||||
}},
|
||||
},
|
||||
})
|
||||
|
@ -2,29 +2,37 @@ package git
|
||||
|
||||
import (
|
||||
"github.com/AaronO/go-git-http"
|
||||
"github.com/AaronO/go-git-http/auth"
|
||||
|
||||
ice "github.com/shylinux/icebergs"
|
||||
"github.com/shylinux/icebergs/base/aaa"
|
||||
"github.com/shylinux/icebergs/base/web"
|
||||
kit "github.com/shylinux/toolkits"
|
||||
)
|
||||
|
||||
const SERVE = "serve"
|
||||
const SERVER = "server"
|
||||
|
||||
func init() {
|
||||
Index.Merge(&ice.Context{
|
||||
Configs: map[string]*ice.Config{
|
||||
SERVE: {Name: SERVE, Help: "服务", Value: kit.Data(
|
||||
kit.MDB_SHORT, kit.MDB_NAME, kit.MDB_FIELD, "time,name,branch,commit",
|
||||
"owner", "https://github.com/shylinux",
|
||||
kit.MDB_PATH, ".ish/pluged",
|
||||
)},
|
||||
SERVER: {Name: SERVER, Help: "服务器", Value: kit.Data(kit.MDB_PATH, ".ish/pluged")},
|
||||
},
|
||||
Commands: map[string]*ice.Command{
|
||||
web.WEB_LOGIN: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.Render(ice.RENDER_VOID)
|
||||
}},
|
||||
"/github.com/": {Name: "github.com", Help: "github.com", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
githttp.New(kit.Path(m.Conf(SERVE, kit.META_PATH))).ServeHTTP(m.W, m.R)
|
||||
"/github.com/": {Name: "/github.com/", Help: "/github.com/", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
auth.Authenticator(func(info auth.AuthInfo) (bool, error) {
|
||||
if !aaa.UserLogin(m, info.Username, info.Password) {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
if info.Push && aaa.UserRole(m, info.Username) == aaa.VOID {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
return true, nil
|
||||
})(githttp.New(kit.Path(m.Conf(SERVER, kit.META_PATH)))).ServeHTTP(m.W, m.R)
|
||||
}},
|
||||
},
|
||||
})
|
||||
|
@ -1,116 +1,110 @@
|
||||
package git
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
ice "github.com/shylinux/icebergs"
|
||||
"github.com/shylinux/icebergs/base/cli"
|
||||
"github.com/shylinux/icebergs/base/mdb"
|
||||
"github.com/shylinux/icebergs/core/code"
|
||||
kit "github.com/shylinux/toolkits"
|
||||
|
||||
"path"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
PULL = "pull"
|
||||
COMPILE = "compile"
|
||||
ADD = "add"
|
||||
COMMIT = "commit"
|
||||
PUSH = "push"
|
||||
DIFF = "diff"
|
||||
MAKE = "make"
|
||||
)
|
||||
const STATUS = "status"
|
||||
|
||||
func init() {
|
||||
Index.Merge(&ice.Context{
|
||||
Commands: map[string]*ice.Command{
|
||||
STATUS: {Name: "status name auto pull compile create commit", Help: "代码状态", Action: map[string]*ice.Action{
|
||||
PULL: {Name: "pull", Help: "下载", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Option(cli.PROGRESS_CB, func(update func(name string, count, total int)) {
|
||||
count, total := 0, len(m.Confm(REPOS, kit.MDB_HASH))
|
||||
m.Richs(REPOS, nil, kit.Select(kit.MDB_FOREACH, arg, 0), func(key string, value map[string]interface{}) {
|
||||
value = kit.GetMeta(value)
|
||||
update(kit.Format(value[kit.MDB_NAME]), count, total)
|
||||
Index.Merge(&ice.Context{Commands: map[string]*ice.Command{
|
||||
STATUS: {Name: "status name auto pull compile create commit", Help: "代码状态", Action: map[string]*ice.Action{
|
||||
PULL: {Name: "pull", Help: "下载", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(cli.PROGRESS, mdb.CREATE, func(update func(name string, count, total int)) {
|
||||
count, total := 0, len(m.Confm(REPOS, kit.MDB_HASH))
|
||||
m.Richs(REPOS, nil, kit.Select(kit.MDB_FOREACH, arg, 0), func(key string, value map[string]interface{}) {
|
||||
value = kit.GetMeta(value)
|
||||
update(kit.Format(value[kit.MDB_NAME]), count, total)
|
||||
|
||||
m.Option(cli.CMD_DIR, value[kit.MDB_PATH])
|
||||
m.Cmd(cli.SYSTEM, GIT, PULL)
|
||||
count++
|
||||
})
|
||||
update("", total, total)
|
||||
m.Option(cli.CMD_DIR, value[kit.MDB_PATH])
|
||||
m.Cmd(cli.SYSTEM, GIT, PULL)
|
||||
count++
|
||||
})
|
||||
m.Cmdy(cli.PROGRESS, mdb.CREATE)
|
||||
}},
|
||||
COMPILE: {Name: "compile", Help: "编译", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(cli.SYSTEM, "make")
|
||||
}},
|
||||
mdb.CREATE: {Name: "create main=src/main.go@key name=hi@key from=usr/icebergs/misc/bash/bash.go@key", Help: "模块", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(code.AUTOGEN, mdb.CREATE, arg)
|
||||
}},
|
||||
mdb.INPUTS: {Name: "inputs", Help: "补全", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(code.AUTOGEN, mdb.INPUTS, arg)
|
||||
}},
|
||||
|
||||
ADD: {Name: "add", Help: "添加", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Option(cli.CMD_DIR, _repos_path(m.Option(kit.MDB_NAME)))
|
||||
m.Cmdy(cli.SYSTEM, GIT, ADD, m.Option(kit.MDB_FILE))
|
||||
}},
|
||||
COMMIT: {Name: "commit action=opt,add comment=some", Help: "提交", Hand: func(m *ice.Message, arg ...string) {
|
||||
if m.Option(kit.MDB_NAME) == "" {
|
||||
return
|
||||
}
|
||||
m.Option(cli.CMD_DIR, _repos_path(m.Option(kit.MDB_NAME)))
|
||||
|
||||
if arg[0] == kit.MDB_ACTION {
|
||||
m.Cmdy(cli.SYSTEM, GIT, COMMIT, "-am", kit.Select("opt some", arg[1]+" "+arg[3]))
|
||||
} else {
|
||||
m.Cmdy(cli.SYSTEM, GIT, COMMIT, "-am", kit.Select("opt some", strings.Join(arg, " ")))
|
||||
}
|
||||
m.Option(ice.MSG_PROCESS, ice.PROCESS_REFRESH)
|
||||
}},
|
||||
PUSH: {Name: "push", Help: "上传", Hand: func(m *ice.Message, arg ...string) {
|
||||
if m.Option(kit.MDB_NAME) == "" {
|
||||
return
|
||||
}
|
||||
if strings.Contains(m.Option(kit.MDB_NAME), ":\\") {
|
||||
m.Option(cli.CMD_DIR, m.Option(kit.MDB_NAME))
|
||||
} else {
|
||||
m.Option(cli.CMD_DIR, path.Join("usr", m.Option(kit.MDB_NAME)))
|
||||
}
|
||||
m.Cmdy(cli.SYSTEM, GIT, PUSH)
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.Richs(REPOS, nil, kit.Select(kit.MDB_FOREACH, arg, 0), func(key string, value map[string]interface{}) {
|
||||
value = kit.GetMeta(value)
|
||||
|
||||
if m.Option(cli.CMD_DIR, value[kit.MDB_PATH]); len(arg) > 0 {
|
||||
m.Echo(m.Cmdx(cli.SYSTEM, GIT, "diff"))
|
||||
return // 更改详情
|
||||
}
|
||||
|
||||
// 更改列表
|
||||
for _, v := range strings.Split(strings.TrimSpace(m.Cmdx(cli.SYSTEM, GIT, STATUS, "-sb")), "\n") {
|
||||
vs := strings.SplitN(strings.TrimSpace(v), " ", 2)
|
||||
m.Push("name", value[kit.MDB_NAME])
|
||||
m.Push("tags", vs[0])
|
||||
m.Push("file", vs[1])
|
||||
|
||||
list := []string{}
|
||||
switch vs[0] {
|
||||
case "##":
|
||||
if strings.Contains(vs[1], "ahead") {
|
||||
list = append(list, PUSH)
|
||||
}
|
||||
default:
|
||||
if strings.Contains(vs[0], "??") {
|
||||
list = append(list, ADD)
|
||||
} else {
|
||||
list = append(list, COMMIT)
|
||||
}
|
||||
}
|
||||
m.PushButton(strings.Join(list, ","))
|
||||
}
|
||||
update("", total, total)
|
||||
})
|
||||
m.Sort(kit.MDB_NAME)
|
||||
}},
|
||||
},
|
||||
})
|
||||
COMPILE: {Name: "compile", Help: "编译", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(cli.SYSTEM, MAKE)
|
||||
}},
|
||||
mdb.CREATE: {Name: "create main=src/main.go@key name=hi@key from=usr/icebergs/misc/bash/bash.go@key", Help: "模块", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(code.AUTOGEN, mdb.CREATE, arg)
|
||||
}},
|
||||
mdb.INPUTS: {Name: "inputs", Help: "补全", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(code.AUTOGEN, mdb.INPUTS, arg)
|
||||
}},
|
||||
|
||||
ADD: {Name: "add", Help: "添加", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Option(cli.CMD_DIR, _repos_path(m.Option(kit.MDB_NAME)))
|
||||
m.Cmdy(cli.SYSTEM, GIT, ADD, m.Option(kit.MDB_FILE))
|
||||
}},
|
||||
COMMIT: {Name: "commit action=opt,add comment=some", Help: "提交", Hand: func(m *ice.Message, arg ...string) {
|
||||
if m.Option(kit.MDB_NAME) == "" {
|
||||
return
|
||||
}
|
||||
|
||||
if m.Option(cli.CMD_DIR, _repos_path(m.Option(kit.MDB_NAME))); arg[0] == kit.MDB_ACTION {
|
||||
m.Cmdy(cli.SYSTEM, GIT, COMMIT, "-am", kit.Select("opt some", arg[1]+" "+arg[3]))
|
||||
} else {
|
||||
m.Cmdy(cli.SYSTEM, GIT, COMMIT, "-am", kit.Select("opt some", strings.Join(arg, " ")))
|
||||
}
|
||||
m.Option(ice.MSG_PROCESS, ice.PROCESS_REFRESH)
|
||||
}},
|
||||
PUSH: {Name: "push", Help: "上传", Hand: func(m *ice.Message, arg ...string) {
|
||||
if m.Option(kit.MDB_NAME) == "" {
|
||||
return
|
||||
}
|
||||
|
||||
if strings.Contains(m.Option(kit.MDB_NAME), ":\\") {
|
||||
m.Option(cli.CMD_DIR, m.Option(kit.MDB_NAME))
|
||||
} else {
|
||||
m.Option(cli.CMD_DIR, _repos_path(m.Option(kit.MDB_NAME)))
|
||||
}
|
||||
m.Cmdy(cli.SYSTEM, GIT, PUSH)
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.Richs(REPOS, nil, kit.Select(kit.MDB_FOREACH, arg, 0), func(key string, value map[string]interface{}) {
|
||||
value = kit.GetMeta(value)
|
||||
if m.Option(cli.CMD_DIR, value[kit.MDB_PATH]); len(arg) > 0 {
|
||||
m.Echo(m.Cmdx(cli.SYSTEM, GIT, DIFF))
|
||||
return // 更改详情
|
||||
}
|
||||
|
||||
// 更改列表
|
||||
for _, v := range strings.Split(strings.TrimSpace(m.Cmdx(cli.SYSTEM, GIT, STATUS, "-sb")), "\n") {
|
||||
vs := strings.SplitN(strings.TrimSpace(v), " ", 2)
|
||||
m.Push(kit.MDB_NAME, value[kit.MDB_NAME])
|
||||
m.Push(kit.MDB_TYPE, vs[0])
|
||||
m.Push(kit.MDB_FILE, vs[1])
|
||||
|
||||
list := []string{}
|
||||
switch vs[0] {
|
||||
case "##":
|
||||
if strings.Contains(vs[1], "ahead") {
|
||||
list = append(list, PUSH)
|
||||
}
|
||||
default:
|
||||
if strings.Contains(vs[0], "??") {
|
||||
list = append(list, ADD)
|
||||
} else {
|
||||
list = append(list, COMMIT)
|
||||
}
|
||||
}
|
||||
m.PushButton(strings.Join(list, ","))
|
||||
}
|
||||
})
|
||||
m.Sort(kit.MDB_NAME)
|
||||
}},
|
||||
}})
|
||||
}
|
||||
|
@ -1,14 +1,14 @@
|
||||
package git
|
||||
|
||||
import (
|
||||
ice "github.com/shylinux/icebergs"
|
||||
"github.com/shylinux/icebergs/base/cli"
|
||||
kit "github.com/shylinux/toolkits"
|
||||
|
||||
"os"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
ice "github.com/shylinux/icebergs"
|
||||
"github.com/shylinux/icebergs/base/cli"
|
||||
kit "github.com/shylinux/toolkits"
|
||||
)
|
||||
|
||||
const TOTAL = "total"
|
||||
@ -16,14 +16,13 @@ const TOTAL = "total"
|
||||
func init() {
|
||||
Index.Merge(&ice.Context{
|
||||
Configs: map[string]*ice.Config{
|
||||
TOTAL: {Name: TOTAL, Help: "统计", Value: kit.Data(
|
||||
TOTAL: {Name: TOTAL, Help: "统计量", Value: kit.Data(
|
||||
kit.MDB_SHORT, kit.MDB_NAME, "skip", kit.Dict("wubi-dict", "true", "word-dict", "true"),
|
||||
)},
|
||||
},
|
||||
Commands: map[string]*ice.Command{
|
||||
TOTAL: {Name: "total name auto", Help: "提交统计", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
if len(arg) > 0 {
|
||||
// 提交详情
|
||||
TOTAL: {Name: "total name auto", Help: "统计量", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
if len(arg) > 0 { // 提交详情
|
||||
m.Richs(REPOS, nil, arg[0], func(key string, value map[string]interface{}) {
|
||||
m.Cmdy("_sum", kit.Value(value, kit.META_PATH), arg[1:])
|
||||
})
|
||||
@ -31,37 +30,31 @@ func init() {
|
||||
}
|
||||
|
||||
// 提交统计
|
||||
mu := &sync.Mutex{}
|
||||
wg := &sync.WaitGroup{}
|
||||
days, commit, adds, dels, rest := 0, 0, 0, 0, 0
|
||||
m.Richs(REPOS, nil, kit.MDB_FOREACH, func(key string, value map[string]interface{}) {
|
||||
if m.Conf(TOTAL, kit.Keys("meta.skip", kit.Value(value, "meta.name"))) == "true" {
|
||||
m.Richs(REPOS, nil, kit.MDB_FOREACH, func(mu *sync.Mutex, key string, value map[string]interface{}) {
|
||||
value = kit.GetMeta(value)
|
||||
if m.Conf(TOTAL, kit.Keym("skip", value[kit.MDB_NAME])) == "true" {
|
||||
return
|
||||
}
|
||||
|
||||
wg.Add(1)
|
||||
m.Go(func() {
|
||||
defer wg.Done()
|
||||
msg := m.Cmd("_sum", value[kit.MDB_PATH], "total", "10000")
|
||||
|
||||
msg := m.Cmd("_sum", kit.Value(value, "meta.path"), "total", "10000")
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
|
||||
mu.Lock()
|
||||
defer mu.Unlock()
|
||||
|
||||
msg.Table(func(index int, value map[string]string, head []string) {
|
||||
if kit.Int(value["days"]) > days {
|
||||
days = kit.Int(value["days"])
|
||||
}
|
||||
commit += kit.Int(value["commit"])
|
||||
adds += kit.Int(value["adds"])
|
||||
dels += kit.Int(value["dels"])
|
||||
rest += kit.Int(value["rest"])
|
||||
})
|
||||
m.Push("name", kit.Value(value, "meta.name"))
|
||||
m.Copy(msg)
|
||||
msg.Table(func(index int, value map[string]string, head []string) {
|
||||
if kit.Int(value["days"]) > days {
|
||||
days = kit.Int(value["days"])
|
||||
}
|
||||
commit += kit.Int(value["commit"])
|
||||
adds += kit.Int(value["adds"])
|
||||
dels += kit.Int(value["dels"])
|
||||
rest += kit.Int(value["rest"])
|
||||
})
|
||||
|
||||
m.Push("name", value[kit.MDB_NAME])
|
||||
m.Copy(msg)
|
||||
})
|
||||
wg.Wait()
|
||||
|
||||
m.Push("name", "total")
|
||||
m.Push("days", kit.Int(days)+1)
|
||||
@ -71,7 +64,7 @@ func init() {
|
||||
m.Push("rest", rest)
|
||||
m.SortIntR("rest")
|
||||
}},
|
||||
"_sum": {Name: "_sum [path] [total] [count|date] args...", Help: "统计", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
"_sum": {Name: "_sum [path] [total] [count|date] args...", Help: "统计量", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
if len(arg) > 0 {
|
||||
if s, e := os.Stat(arg[0] + "/.git"); e == nil && s.IsDir() {
|
||||
m.Option(cli.CMD_DIR, arg[0])
|
||||
@ -85,58 +78,60 @@ func init() {
|
||||
}
|
||||
|
||||
args := []string{}
|
||||
args = append(args, "log", kit.Format("--author=%s\\|shylinux", m.Option(ice.MSG_USERNAME)), "--shortstat", "--pretty=commit: %ad %n%s", "--date=iso", "--reverse")
|
||||
args = append(args, "log", kit.Format("--author=%s\\|shylinux", m.Option(ice.MSG_USERNAME)),
|
||||
"--shortstat", "--pretty=commit: %ad %n%s", "--date=iso", "--reverse")
|
||||
if len(arg) > 0 {
|
||||
args = append(args, kit.Select("-n", "--since", strings.Contains(arg[0], "-")))
|
||||
if strings.Contains(arg[0], "-") && !strings.Contains(arg[0], ":") {
|
||||
arg[0] = arg[0] + " 00:00:00"
|
||||
}
|
||||
args = append(args, arg[0:]...)
|
||||
args = append(args, kit.Select("-n", "--since", strings.Contains(arg[0], "-")))
|
||||
args = append(args, arg...)
|
||||
} else {
|
||||
args = append(args, "-n", "30")
|
||||
}
|
||||
|
||||
var total_day time.Duration
|
||||
count, count_add, count_del := 0, 0, 0
|
||||
for i, v := range strings.Split(m.Cmdx(cli.SYSTEM, "git", args), "commit: ") {
|
||||
if i > 0 {
|
||||
l := strings.Split(v, "\n")
|
||||
hs := strings.Split(l[0], " ")
|
||||
|
||||
add, del := "0", "0"
|
||||
if len(l) > 3 {
|
||||
fs := strings.Split(strings.TrimSpace(l[3]), ", ")
|
||||
if adds := strings.Split(fs[1], " "); len(fs) > 2 {
|
||||
dels := strings.Split(fs[2], " ")
|
||||
add = adds[0]
|
||||
del = dels[0]
|
||||
} else if strings.Contains(adds[1], "insertion") {
|
||||
add = adds[0]
|
||||
} else {
|
||||
del = adds[0]
|
||||
}
|
||||
}
|
||||
|
||||
if total {
|
||||
if count++; i == 1 {
|
||||
if t, e := time.Parse("2006-01-02", hs[0]); e == nil {
|
||||
total_day = time.Now().Sub(t)
|
||||
m.Append("from", hs[0])
|
||||
}
|
||||
}
|
||||
count_add += kit.Int(add)
|
||||
count_del += kit.Int(del)
|
||||
continue
|
||||
}
|
||||
|
||||
m.Push("date", hs[0])
|
||||
m.Push("adds", add)
|
||||
m.Push("dels", del)
|
||||
m.Push("rest", kit.Int(add)-kit.Int(del))
|
||||
m.Push("note", l[1])
|
||||
m.Push("hour", strings.Split(hs[1], ":")[0])
|
||||
m.Push("time", hs[1])
|
||||
for i, v := range strings.Split(m.Cmdx(cli.SYSTEM, GIT, args), "commit: ") {
|
||||
l := strings.Split(v, "\n")
|
||||
hs := strings.Split(l[0], " ")
|
||||
if len(l) < 2 {
|
||||
continue
|
||||
}
|
||||
|
||||
add, del := "0", "0"
|
||||
if len(l) > 3 {
|
||||
fs := strings.Split(strings.TrimSpace(l[3]), ", ")
|
||||
if adds := strings.Split(fs[1], " "); len(fs) > 2 {
|
||||
dels := strings.Split(fs[2], " ")
|
||||
add = adds[0]
|
||||
del = dels[0]
|
||||
} else if strings.Contains(adds[1], "insertion") {
|
||||
add = adds[0]
|
||||
} else {
|
||||
del = adds[0]
|
||||
}
|
||||
}
|
||||
|
||||
if total {
|
||||
if count++; i == 1 {
|
||||
if t, e := time.Parse("2006-01-02", hs[0]); e == nil {
|
||||
total_day = time.Now().Sub(t)
|
||||
m.Append("from", hs[0])
|
||||
}
|
||||
}
|
||||
count_add += kit.Int(add)
|
||||
count_del += kit.Int(del)
|
||||
continue
|
||||
}
|
||||
|
||||
m.Push("date", hs[0])
|
||||
m.Push("adds", add)
|
||||
m.Push("dels", del)
|
||||
m.Push("rest", kit.Int(add)-kit.Int(del))
|
||||
m.Push("note", l[1])
|
||||
m.Push("hour", strings.Split(hs[1], ":")[0])
|
||||
m.Push("time", hs[1])
|
||||
}
|
||||
|
||||
if total {
|
||||
|
@ -3,32 +3,24 @@ package git
|
||||
import (
|
||||
ice "github.com/shylinux/icebergs"
|
||||
"github.com/shylinux/icebergs/base/ctx"
|
||||
"github.com/shylinux/icebergs/base/mdb"
|
||||
kit "github.com/shylinux/toolkits"
|
||||
)
|
||||
|
||||
const TREND = "trend"
|
||||
|
||||
func init() {
|
||||
Index.Merge(&ice.Context{
|
||||
Commands: map[string]*ice.Command{
|
||||
TREND: {Name: "trend name=icebergs@key begin_time@date auto", Help: "趋势图", Meta: kit.Dict(
|
||||
"display", "/plugin/story/trend.js",
|
||||
), Action: map[string]*ice.Action{
|
||||
mdb.INPUTS: {Name: "inputs", Help: "补全", Hand: func(m *ice.Message, arg ...string) {
|
||||
m.Cmdy(REPOS).Appendv(ice.MSG_APPEND, kit.Split("name,branch,commit"))
|
||||
}},
|
||||
ctx.COMMAND: {Name: "command", Help: "命令", Hand: func(m *ice.Message, arg ...string) {
|
||||
for _, k := range arg {
|
||||
m.Cmdy(ctx.COMMAND, k)
|
||||
}
|
||||
}},
|
||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
if len(arg) == 0 {
|
||||
m.Option(ice.MSG_DISPLAY, "table")
|
||||
}
|
||||
m.Cmdy(TOTAL, arg)
|
||||
}},
|
||||
},
|
||||
})
|
||||
Index.Merge(&ice.Context{Commands: map[string]*ice.Command{
|
||||
TREND: {Name: "trend name@key begin_time@date auto", Help: "趋势图", Meta: kit.Dict(
|
||||
kit.MDB_DISPLAY, "/plugin/story/trend.js",
|
||||
), Action: map[string]*ice.Action{
|
||||
ctx.COMMAND: {Name: "ctx.command"},
|
||||
}, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
if len(arg) == 0 { // 仓库列表
|
||||
m.Cmdy(REPOS)
|
||||
return
|
||||
}
|
||||
|
||||
m.Cmdy(TOTAL, arg)
|
||||
}},
|
||||
}})
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user