admin: Display commit ID in admin interface

This commit is contained in:
nemunaire 2022-01-20 15:29:49 +01:00
parent 92bb409764
commit 2645109839
9 changed files with 30 additions and 5 deletions

View File

@ -32,8 +32,14 @@ func getROSettings(_ httprouter.Params, body []byte) (interface{}, error) {
syncMtd = sync.GlobalImporter.Kind() syncMtd = sync.GlobalImporter.Kind()
} }
var syncId *string
if sync.GlobalImporter != nil {
syncId = sync.GlobalImporter.Id()
}
return map[string]interface{}{ return map[string]interface{}{
"sync-type": reflect.TypeOf(sync.GlobalImporter).Name(), "sync-type": reflect.TypeOf(sync.GlobalImporter).Name(),
"sync-id": syncId,
"sync": syncMtd, "sync": syncMtd,
}, nil }, nil
} }

View File

@ -241,7 +241,9 @@
<div class="card-body"> <div class="card-body">
<dl class="row"> <dl class="row">
<dt class="col-3">Synchronisation</dt> <dt class="col-3">Synchronisation</dt>
<dd class="col" title="{{ configro['sync-type'] }}" ng-bind="configro.sync"></dd> <dd class="col-9" title="{{ configro['sync-type'] }}" ng-bind="configro.sync"></dd>
<dt class="col-3" ng-if="configro['sync-id']">ID</dt>
<dd class="col-9" ng-if="configro['sync-id']">{{ configro['sync-id'] }}</dd>
</dl> </dl>
<div class="float-right" ng-if="configro.sync"> <div class="float-right" ng-if="configro.sync">

View File

@ -19,6 +19,8 @@ import (
type Importer interface { type Importer interface {
// Kind returns information about the Importer, for human interrest. // Kind returns information about the Importer, for human interrest.
Kind() string Kind() string
// Id returns information about the current state (commit id, ...).
Id() *string
// init performs the importer initialization. // init performs the importer initialization.
Init() error Init() error
// sync tries to pull the latest modification of the underlying storage. // sync tries to pull the latest modification of the underlying storage.

View File

@ -44,6 +44,9 @@ func SpeedySyncDeep(i Importer) (errs map[string][]string) {
if err := i.Sync(); err != nil { if err := i.Sync(); err != nil {
errs["_sync"] = []string{err.Error()} errs["_sync"] = []string{err.Error()}
if _id := i.Id(); _id != nil {
errs["_sync"] = append(errs["_sync"], *_id)
}
} }
errs["_date"] = []string{fmt.Sprintf("%v", startTime)} errs["_date"] = []string{fmt.Sprintf("%v", startTime)}

View File

@ -38,6 +38,10 @@ func (i CloudImporter) Kind() string {
return "cloud file importer: " + i.baseDAV.String() return "cloud file importer: " + i.baseDAV.String()
} }
func (i CloudImporter) Id() *string {
return nil
}
func (i CloudImporter) Init() error { func (i CloudImporter) Init() error {
return nil return nil
} }

View File

@ -51,7 +51,7 @@ func NewGitImporter(li LocalImporter, remote string) GitImporter {
} }
} }
func (i GitImporter) Kind() string { func (i GitImporter) Id() *string {
var gitinfo string var gitinfo string
r, err := git.PlainOpen(i.li.Base) r, err := git.PlainOpen(i.li.Base)
if err == nil { if err == nil {
@ -61,7 +61,7 @@ func (i GitImporter) Kind() string {
} }
} }
return "git originated from " + i.Remote + " on " + i.li.Kind() + ", currently on commit " + gitinfo return &gitinfo
} }
func (i GitImporter) Init() error { func (i GitImporter) Init() error {

View File

@ -37,3 +37,7 @@ func (i GitImporter) listDir(filename string) ([]string, error) {
func (i GitImporter) stat(filename string) (os.FileInfo, error) { func (i GitImporter) stat(filename string) (os.FileInfo, error) {
return i.li.stat(filename) return i.li.stat(filename)
} }
func (i GitImporter) Kind() string {
return "git originated from " + i.Remote + " on " + i.li.Kind()
}

View File

@ -25,7 +25,7 @@ func NewGitImporter(li LocalImporter, remote string) GitImporter {
} }
} }
func (i GitImporter) Kind() string { func (i GitImporter) Id() *string {
cmdshow := exec.Command("git", "-C", i.li.Base, "show") cmdshow := exec.Command("git", "-C", i.li.Base, "show")
var outshow bytes.Buffer var outshow bytes.Buffer
cmdshow.Stdout = &outshow cmdshow.Stdout = &outshow
@ -43,7 +43,7 @@ func (i GitImporter) Kind() string {
} }
} }
return "git originated from " + i.Remote + " on " + i.li.Kind() + ", currently on commit " + commit return &commit
} }
func (i GitImporter) Init() error { func (i GitImporter) Init() error {

View File

@ -26,6 +26,10 @@ func (i LocalImporter) Kind() string {
} }
} }
func (i LocalImporter) Id() *string {
return nil
}
func (i LocalImporter) Init() error { func (i LocalImporter) Init() error {
if f, err := os.Stat(i.Base); os.IsNotExist(err) { if f, err := os.Stat(i.Base); os.IsNotExist(err) {
if err = os.Mkdir(i.Base, 0751); err != nil { if err = os.Mkdir(i.Base, 0751); err != nil {