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