// Cached lookup of a merge request. The only properties it is valid to read on the
// returned value are ID, IID and ProjectID - these are hence moved to separate struct
Cached lookup of a merge request. The only properties it is valid to read on the
returned value are ID, IID and ProjectID - these are hence moved to separate struct
// Cached lookup of a merge request . The only properties it is valid to read on the // returned value are ID IID and ProjectID - these are hence moved to separate struct
func resolveMRWithCache(filename string, fn func() (*MergeRequestIdentifiers, error)) (MergeRequestIdentifiers, error) {
	lab.RemoveOldCacheEntries()
	inCache, bytes, err := lab.ReadCache(filename)
	if inCache && err == nil {
		lab.CmdLogger().Debugf("Found MR in cache at %s", filename)
		mr := MergeRequestIdentifiers{}
		err := json.Unmarshal(bytes, &mr)
		if err == nil {
			return mr, nil
		} else {
			lab.CmdLogger().Warningf("Could not unmarshal from cached value: %s", err)
		}
	}
	lab.CmdLogger().Debugf("Cache miss - fetching %s", filename)
	mr, err := fn()
	if err != nil {
		return MergeRequestIdentifiers{}, err
	}
	bytes, err = json.Marshal(mr)
	if err == nil {
		lab.WriteCache(filename, bytes)
	}
	if mr == nil {
		return MergeRequestIdentifiers{}, errors.New("No MR found")
	} else {
		return *mr, nil
	}
}
func resolveMRWithCache ( filename string , fn func ( ) ( * MergeRequestIdentifiers , error ) ) ( MergeRequestIdentifiers , error ) { lab . RemoveOldCacheEntries ( ) inCache , bytes , err := lab . ReadCache ( filename ) if inCache && err == nil { lab . CmdLogger ( ) . Debugf ( " " , filename ) mr := MergeRequestIdentifiers { } err := json . Unmarshal ( bytes , & mr ) if err == nil { return mr , nil } else { lab . CmdLogger ( ) . Warningf ( " " , err ) } } lab . CmdLogger ( ) . Debugf ( " " , filename ) mr , err := fn ( ) if err != nil { return MergeRequestIdentifiers { } , err } bytes , err = json . Marshal ( mr ) if err == nil { lab . WriteCache ( filename , bytes ) } if mr == nil { return MergeRequestIdentifiers { } , errors . New ( " " ) } else { return * mr , nil } }
Cached lookup of a merge request.
Cached lookup of a merge request .