mirror of
https://github.com/casdoor/casdoor.git
synced 2025-07-03 04:10:20 +08:00
fix: add aheadCnt in sysinfo (#1632)
* feat: add sync module to bi-sync mysql * feat: fix the delay problem * feat: fix go mod * feat: fix the varchar(100) parse error * fix: fix go.mod space inconsistency * fix: fix go.mod space inconsistency * fix: use sql builder instead of concatenation * fix: remove serverId * fix: fix file is not `gofumpt`-ed (gofumpt) error * feat: add mysql bi-sync * feat: fix some data inconsistency problems * feat: add function atuo get server uuid * fix: encapsulate the struct to optimize the code * fix: fix incorrect Casdoor version in system info page * fix: fix incorrect root path * Update sysytem_test.go * feat: add aheadCnt means that the commit is ahead of version several times --------- Co-authored-by: hsluoyz <hsluoyz@qq.com>
This commit is contained in:
@ -48,20 +48,20 @@ func GetMemoryUsage() (uint64, uint64, error) {
|
||||
}
|
||||
|
||||
// get github current commit and repo release version
|
||||
func GetGitRepoVersion() (string, string, error) {
|
||||
func GetGitRepoVersion() (int, string, string, error) {
|
||||
_, filename, _, _ := runtime.Caller(0)
|
||||
rootPath := path.Dir(path.Dir(filename))
|
||||
r, err := git.PlainOpen(rootPath)
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
return -1, "", "", err
|
||||
}
|
||||
ref, err := r.Head()
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
return -1, "", "", err
|
||||
}
|
||||
tags, err := r.Tags()
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
return -1, "", "", err
|
||||
}
|
||||
tagMap := make(map[plumbing.Hash]string)
|
||||
err = tags.ForEach(func(t *plumbing.Reference) error {
|
||||
@ -74,11 +74,12 @@ func GetGitRepoVersion() (string, string, error) {
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
return -1, "", "", err
|
||||
}
|
||||
|
||||
cIter, err := r.Log(&git.LogOptions{From: ref.Hash()})
|
||||
|
||||
aheadCnt := 0
|
||||
releaseVersion := ""
|
||||
// iterates over the commits
|
||||
err = cIter.ForEach(func(c *object.Commit) error {
|
||||
@ -88,11 +89,14 @@ func GetGitRepoVersion() (string, string, error) {
|
||||
releaseVersion = tag
|
||||
}
|
||||
}
|
||||
if releaseVersion == "" {
|
||||
aheadCnt++
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
return -1, "", "", err
|
||||
}
|
||||
|
||||
return ref.Hash().String(), releaseVersion, nil
|
||||
return aheadCnt, ref.Hash().String(), releaseVersion, nil
|
||||
}
|
||||
|
@ -41,15 +41,15 @@ func TestGetMemoryUsage(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetGitRepoVersion(t *testing.T) {
|
||||
commit, version, err := GetGitRepoVersion()
|
||||
aheadCnt, commit, version, err := GetGitRepoVersion()
|
||||
assert.Nil(t, err)
|
||||
t.Log(commit, version)
|
||||
t.Log(aheadCnt, commit, version)
|
||||
}
|
||||
|
||||
func TestGetVersion(t *testing.T) {
|
||||
_, filename, _, _ := runtime.Caller(0)
|
||||
rootPath := path.Dir(path.Dir(filename))
|
||||
r, err := git.PlainOpen(rootPath)
|
||||
root := path.Dir(path.Dir(filename))
|
||||
r, err := git.PlainOpen(root)
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
@ -68,9 +68,10 @@ func TestGetVersion(t *testing.T) {
|
||||
return nil
|
||||
})
|
||||
|
||||
testHash := plumbing.NewHash("16b1d0e1f001c1162a263ed50c1a892c947d5783")
|
||||
testHash := plumbing.NewHash("f8bc87eb4e5ba3256424cf14aafe0549f812f1cf")
|
||||
cIter, err := r.Log(&git.LogOptions{From: testHash})
|
||||
|
||||
aheadCnt := 0
|
||||
releaseVersion := ""
|
||||
// iterates over the commits
|
||||
err = cIter.ForEach(func(c *object.Commit) error {
|
||||
@ -80,7 +81,12 @@ func TestGetVersion(t *testing.T) {
|
||||
releaseVersion = tag
|
||||
}
|
||||
}
|
||||
if releaseVersion == "" {
|
||||
aheadCnt++
|
||||
}
|
||||
return nil
|
||||
})
|
||||
assert.Equal(t, "v1.260.0", releaseVersion)
|
||||
|
||||
assert.Equal(t, 3, aheadCnt)
|
||||
assert.Equal(t, "v1.257.0", releaseVersion)
|
||||
}
|
||||
|
Reference in New Issue
Block a user