1
Fork 0

Setup husky hooks for api

This commit is contained in:
viktorstrate 2021-04-03 17:49:18 +02:00
parent 0a5e6bf350
commit 95c174d3a5
No known key found for this signature in database
GPG Key ID: 3F855605109C1E8A
6 changed files with 23 additions and 8 deletions

8
.husky/lint-api.sh Normal file
View File

@ -0,0 +1,8 @@
#!/bin/sh
gofiles=$(git diff --cached --name-only --diff-filter=ACM | grep '.go$')
[ -z "$gofiles" ] && exit 0
# Automatically format go code, exit on error
echo "Formatting staged go files"
gofmt -w $gofiles

4
.husky/lint-ui.sh Normal file
View File

@ -0,0 +1,4 @@
#!/bin/sh
cd ui
npx lint-staged

View File

@ -1,4 +1,8 @@
#!/bin/sh #!/bin/sh
. "$(dirname "$0")/_/husky.sh" . "$(dirname "$0")/_/husky.sh"
cd ui && npx lint-staged ## Lint UI
sh "$(dirname "$0")/lint-ui.sh"
## Lint API
sh "$(dirname "$0")/lint-api.sh"

View File

@ -87,7 +87,7 @@ func (c *AlbumScannerCache) GetMediaType(path string) (*MediaType, error) {
return mediaType, nil return mediaType, nil
} }
func (c *AlbumScannerCache) GetAlbumIgnore(path string) (*[]string) { func (c *AlbumScannerCache) GetAlbumIgnore(path string) *[]string {
c.mutex.Lock() c.mutex.Lock()
defer c.mutex.Unlock() defer c.mutex.Unlock()

View File

@ -42,7 +42,6 @@ func SaveEXIF(tx *gorm.DB, media *models.Media) (*models.MediaEXIF, error) {
parser = &externalExifParser{} parser = &externalExifParser{}
} }
exif, err := parser.ParseExif(media) exif, err := parser.ParseExif(media)
if err != nil { if err != nil {
return nil, errors.Wrap(err, "failed to parse exif data") return nil, errors.Wrap(err, "failed to parse exif data")

View File

@ -17,7 +17,7 @@ import (
"gorm.io/gorm" "gorm.io/gorm"
) )
func getPhotoviewIgnore(ignorePath string) ([]string , error){ func getPhotoviewIgnore(ignorePath string) ([]string, error) {
var photoviewIgnore []string var photoviewIgnore []string
// Open .photoviewignore file, if exists // Open .photoviewignore file, if exists
@ -30,13 +30,13 @@ func getPhotoviewIgnore(ignorePath string) ([]string , error){
defer photoviewIgnoreFile.Close() defer photoviewIgnoreFile.Close()
// Read and save .photoviewignore data // Read and save .photoviewignore data
scanner := bufio.NewScanner(photoviewIgnoreFile) scanner := bufio.NewScanner(photoviewIgnoreFile)
for scanner.Scan() { for scanner.Scan() {
photoviewIgnore = append(photoviewIgnore, scanner.Text()) photoviewIgnore = append(photoviewIgnore, scanner.Text())
log.Printf("Ignore found: %s", scanner.Text()) log.Printf("Ignore found: %s", scanner.Text())
} }
return photoviewIgnore, scanner.Err() return photoviewIgnore, scanner.Err()
} }
func findAlbumsForUser(db *gorm.DB, user *models.User, album_cache *AlbumScannerCache) ([]*models.Album, []error) { func findAlbumsForUser(db *gorm.DB, user *models.User, album_cache *AlbumScannerCache) ([]*models.Album, []error) {
@ -101,7 +101,7 @@ func findAlbumsForUser(db *gorm.DB, user *models.User, album_cache *AlbumScanner
// Skip this dir if in ignore list // Skip this dir if in ignore list
ignorePaths := ignore.CompileIgnoreLines(albumIgnore...) ignorePaths := ignore.CompileIgnoreLines(albumIgnore...)
if (ignorePaths.MatchesPath(albumPath + "/")) { if ignorePaths.MatchesPath(albumPath + "/") {
log.Printf("Skip, directroy %s is in ignore file", albumPath) log.Printf("Skip, directroy %s is in ignore file", albumPath)
continue continue
} }