mirror of
https://github.com/beego/bee.git
synced 2024-11-25 20:10:55 +00:00
change updatedTime to publishedTime
This commit is contained in:
parent
7a7357a983
commit
674b52a732
@ -35,7 +35,7 @@ func updateBee(cmd *commands.Command, args []string) int {
|
|||||||
if err := cmdUp.Run(); err != nil {
|
if err := cmdUp.Run(); err != nil {
|
||||||
beeLogger.Log.Warnf("Run cmd err:%s", err)
|
beeLogger.Log.Warnf("Run cmd err:%s", err)
|
||||||
}
|
}
|
||||||
// update the pushedTime when updateBee every time
|
// update the Time when updateBee every time
|
||||||
utils.UpdateLastPushedTime()
|
utils.UpdateLastPublishedTime()
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ type RuntimeInfo struct {
|
|||||||
Compiler string
|
Compiler string
|
||||||
BeeVersion string
|
BeeVersion string
|
||||||
BeegoVersion string
|
BeegoVersion string
|
||||||
UpdatedAt string
|
Published string
|
||||||
}
|
}
|
||||||
|
|
||||||
// InitBanner loads the banner and prints it to output
|
// InitBanner loads the banner and prints it to output
|
||||||
@ -62,7 +62,7 @@ func show(out io.Writer, content string) {
|
|||||||
runtime.Compiler,
|
runtime.Compiler,
|
||||||
version,
|
version,
|
||||||
GetBeegoVersion(),
|
GetBeegoVersion(),
|
||||||
utils.GetLastPushedTime(),
|
utils.GetLastPublishedTime(),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
beeLogger.Log.Error(err.Error())
|
beeLogger.Log.Error(err.Error())
|
||||||
|
@ -38,7 +38,7 @@ const verboseVersionBanner string = `%s%s______
|
|||||||
├── GOPATH : {{ .GOPATH }}
|
├── GOPATH : {{ .GOPATH }}
|
||||||
├── GOROOT : {{ .GOROOT }}
|
├── GOROOT : {{ .GOROOT }}
|
||||||
├── Compiler : {{ .Compiler }}
|
├── Compiler : {{ .Compiler }}
|
||||||
└── UpdatedAt : {{ .UpdatedAt }}%s
|
└── Published : {{ .Published }}%s
|
||||||
`
|
`
|
||||||
|
|
||||||
const shortVersionBanner = `______
|
const shortVersionBanner = `______
|
||||||
@ -84,7 +84,7 @@ func versionCmd(cmd *commands.Command, args []string) int {
|
|||||||
runtime.Compiler,
|
runtime.Compiler,
|
||||||
version,
|
version,
|
||||||
GetBeegoVersion(),
|
GetBeegoVersion(),
|
||||||
utils.GetLastPushedTime(),
|
utils.GetLastPublishedTime(),
|
||||||
}
|
}
|
||||||
switch outputFormat {
|
switch outputFormat {
|
||||||
case "json":
|
case "json":
|
||||||
|
@ -47,6 +47,11 @@ type Repos struct {
|
|||||||
PushedAt time.Time `json:"pushed_at"`
|
PushedAt time.Time `json:"pushed_at"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Releases struct {
|
||||||
|
PublishedAt time.Time `json:"published_at"`
|
||||||
|
TagName string `json:"tag_name"`
|
||||||
|
}
|
||||||
|
|
||||||
func GetBeeWorkPath() string {
|
func GetBeeWorkPath() string {
|
||||||
curpath, err := os.Getwd()
|
curpath, err := os.Getwd()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -565,7 +570,7 @@ func BeeLastVersion() (version string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// get info of repos bee
|
// get info of bee repos
|
||||||
func BeeReposInfo() (repos Repos) {
|
func BeeReposInfo() (repos Repos) {
|
||||||
var url = "https://api.github.com/repos/beego/bee"
|
var url = "https://api.github.com/repos/beego/bee"
|
||||||
resp, err := http.Get(url)
|
resp, err := http.Get(url)
|
||||||
@ -582,10 +587,32 @@ func BeeReposInfo() (repos Repos) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO UpdateLastTime and NoticeUpdateBee
|
// get info of bee releases
|
||||||
func UpdateLastPushedTime() {
|
func BeeReleasesInfo() (repos []Releases) {
|
||||||
info := BeeReposInfo()
|
var url = "https://api.github.com/repos/beego/bee/releases"
|
||||||
createdAt := info.PushedAt.Format("2006-01-02")
|
resp, err := http.Get(url)
|
||||||
|
if err != nil {
|
||||||
|
beeLogger.Log.Warnf("Get bee releases from github error: %s", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
bodyContent, _ := ioutil.ReadAll(resp.Body)
|
||||||
|
if err = json.Unmarshal(bodyContent, &repos); err != nil {
|
||||||
|
beeLogger.Log.Warnf("Unmarshal releases body error: %s", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
//TODO merge UpdateLastPublishedTime and NoticeUpdateBee
|
||||||
|
func UpdateLastPublishedTime() {
|
||||||
|
info := BeeReleasesInfo()
|
||||||
|
fmt.Printf("%+v", info)
|
||||||
|
if len(info) == 0 {
|
||||||
|
beeLogger.Log.Warn("Has no releases")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
createdAt := info[0].PublishedAt.Format("2006-01-02")
|
||||||
beeHome := system.BeegoHome
|
beeHome := system.BeegoHome
|
||||||
if !IsExist(beeHome) {
|
if !IsExist(beeHome) {
|
||||||
if err := os.MkdirAll(beeHome, 0755); err != nil {
|
if err := os.MkdirAll(beeHome, 0755); err != nil {
|
||||||
@ -593,33 +620,33 @@ func UpdateLastPushedTime() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fp := beeHome + "/.lastUpdatedAt"
|
fp := beeHome + "/.lastPublishedAt"
|
||||||
w, err := os.OpenFile(fp, os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0644)
|
w, err := os.OpenFile(fp, os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
beeLogger.Log.Warnf("Open .lastUpdatedAt file err: %s", err)
|
beeLogger.Log.Warnf("Open .lastPublishedAt file err: %s", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer w.Close()
|
defer w.Close()
|
||||||
if _, err := w.WriteString(createdAt); err != nil {
|
if _, err := w.WriteString(createdAt); err != nil {
|
||||||
beeLogger.Log.Warnf("Update lastUpdatedAt file err: %s", err)
|
beeLogger.Log.Warnf("Update .lastPublishedAt file err: %s", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetLastPushedTime() string {
|
func GetLastPublishedTime() string {
|
||||||
fp := system.BeegoHome + "/.lastUpdatedAt"
|
fp := system.BeegoHome + "/.lastPublishedAt"
|
||||||
if !IsExist(fp) {
|
if !IsExist(fp) {
|
||||||
UpdateLastPushedTime()
|
UpdateLastPublishedTime()
|
||||||
}
|
}
|
||||||
w, err := os.OpenFile(fp, os.O_RDONLY, 0644)
|
w, err := os.OpenFile(fp, os.O_RDONLY, 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
beeLogger.Log.Warnf("Open .lastUpdatedAt file err: %s", err)
|
beeLogger.Log.Warnf("Open .lastPublishedAt file err: %s", err)
|
||||||
return "unknown"
|
return "unknown"
|
||||||
}
|
}
|
||||||
t := make([]byte, 1024)
|
t := make([]byte, 1024)
|
||||||
read, err := w.Read(t)
|
read, err := w.Read(t)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
beeLogger.Log.Warnf("read .lastUpdatedAt file err: %s", err)
|
beeLogger.Log.Warnf("read .lastPublishedAt file err: %s", err)
|
||||||
return "unknown"
|
return "unknown"
|
||||||
}
|
}
|
||||||
return string(t[:read])
|
return string(t[:read])
|
||||||
|
Loading…
Reference in New Issue
Block a user