update
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/beego/beego/v2/core/logs"
|
"github.com/beego/beego/v2/core/logs"
|
||||||
@@ -39,6 +40,9 @@ var functions = []Function{
|
|||||||
Rules: []string{"^升级$"},
|
Rules: []string{"^升级$"},
|
||||||
Admin: true,
|
Admin: true,
|
||||||
Handle: func(s im.Sender) interface{} {
|
Handle: func(s im.Sender) interface{} {
|
||||||
|
if runtime.GOOS == "darwin" {
|
||||||
|
return "沙雕。"
|
||||||
|
}
|
||||||
s.Reply("傻妞开始拉取代码。")
|
s.Reply("傻妞开始拉取代码。")
|
||||||
rtn, err := exec.Command("sh", "-c", "cd "+ExecPath+" && git stash && git pull").Output()
|
rtn, err := exec.Command("sh", "-c", "cd "+ExecPath+" && git stash && git pull").Output()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
+55
-8
@@ -1,6 +1,7 @@
|
|||||||
package qinglong
|
package qinglong
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@@ -25,7 +26,7 @@ type Env struct {
|
|||||||
func init() {
|
func init() {
|
||||||
core.AddCommand([]core.Function{
|
core.AddCommand([]core.Function{
|
||||||
{
|
{
|
||||||
Rules: []string{`^env\s+get\s+([\S]*)$`},
|
Rules: []string{`^env\s+get\s+([\S]+)$`},
|
||||||
Handle: func(s im.Sender) interface{} {
|
Handle: func(s im.Sender) interface{} {
|
||||||
m := s.Get()
|
m := s.Get()
|
||||||
env, err := GetEnv(m)
|
env, err := GetEnv(m)
|
||||||
@@ -42,7 +43,7 @@ func init() {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Rules: []string{`^env\s+find\s+([\S]*)$`},
|
Rules: []string{`^env\s+find\s+([\S]+)$`},
|
||||||
Handle: func(s im.Sender) interface{} {
|
Handle: func(s im.Sender) interface{} {
|
||||||
m := s.Get()
|
m := s.Get()
|
||||||
envs, err := GetEnvs(m)
|
envs, err := GetEnvs(m)
|
||||||
@@ -74,7 +75,7 @@ func init() {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Rules: []string{`^env\s+del\s+([\S]*)$`},
|
Rules: []string{`^env\s+del\s+([\S]+)$`},
|
||||||
Handle: func(s im.Sender) interface{} {
|
Handle: func(s im.Sender) interface{} {
|
||||||
if err := RemEnv(&Env{ID: s.Get()}); err != nil {
|
if err := RemEnv(&Env{ID: s.Get()}); err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -82,6 +83,15 @@ func init() {
|
|||||||
return "操作成功"
|
return "操作成功"
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Rules: []string{`^env\s+remark\s+([\S]+)\s+([\S]+)$`},
|
||||||
|
Handle: func(s im.Sender) interface{} {
|
||||||
|
if err := ModEnv(&Env{ID: s.Get(0), Remarks: s.Get(1)}); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return "操作成功"
|
||||||
|
},
|
||||||
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -106,15 +116,52 @@ func GetEnvs(searchValue string) ([]Env, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func SetEnv(e *Env) error {
|
func SetEnv(e *Env) error {
|
||||||
es, err := GetEnvs(e.Name)
|
if e.Name == "JD_COOKIE" {
|
||||||
|
return errors.New("不支持的操作")
|
||||||
|
}
|
||||||
|
envs, err := GetEnvs("")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if len(es) == 0 {
|
for _, env := range envs {
|
||||||
return AddEnv(e)
|
if env.Name == e.Name {
|
||||||
|
if e.Remarks != "" {
|
||||||
|
env.Remarks = e.Remarks
|
||||||
}
|
}
|
||||||
e.ID = es[0].ID
|
if e.Value != "" {
|
||||||
return req(PUT, ENVS, *e)
|
env.Value = e.Value
|
||||||
|
}
|
||||||
|
if e.Name != "" {
|
||||||
|
env.Name = e.Name
|
||||||
|
}
|
||||||
|
env.Timestamp = ""
|
||||||
|
return req(PUT, ENVS, env)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return AddEnv(e)
|
||||||
|
}
|
||||||
|
|
||||||
|
func ModEnv(e *Env) error {
|
||||||
|
envs, err := GetEnvs("")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for _, env := range envs {
|
||||||
|
if env.ID == e.ID {
|
||||||
|
if e.Remarks != "" {
|
||||||
|
env.Remarks = e.Remarks
|
||||||
|
}
|
||||||
|
if e.Value != "" {
|
||||||
|
env.Value = e.Value
|
||||||
|
}
|
||||||
|
if e.Name != "" {
|
||||||
|
env.Name = e.Name
|
||||||
|
}
|
||||||
|
env.Timestamp = ""
|
||||||
|
return req(PUT, ENVS, env)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return errors.New("找不到环境变量")
|
||||||
}
|
}
|
||||||
|
|
||||||
func AddEnv(e *Env) error {
|
func AddEnv(e *Env) error {
|
||||||
|
|||||||
@@ -108,9 +108,9 @@ func req(ps ...interface{}) error {
|
|||||||
if method != GET {
|
if method != GET {
|
||||||
req.Body(body)
|
req.Body(body)
|
||||||
}
|
}
|
||||||
// fmt.Println(Config.Host + "/open/" + api)
|
fmt.Println(Config.Host + "/open/" + api)
|
||||||
// fmt.Println(method)
|
fmt.Println(method)
|
||||||
// fmt.Println(string(body))
|
fmt.Println(string(body))
|
||||||
req.Body(body)
|
req.Body(body)
|
||||||
data, err := req.Bytes()
|
data, err := req.Bytes()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user