Skip to content

Commit

Permalink
Merge pull request #482 from gphotosuploader/release-5.0.0
Browse files Browse the repository at this point in the history
Release 5.0.0
  • Loading branch information
pacoorozco authored Oct 16, 2024
2 parents f2b227f + f85086a commit 21c029e
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 112 deletions.
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,24 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/) and this project adheres to [Semantic Versioning](https://semver.org/).

## 5.0.0
### Added
- Google Photos scopes have changed, some of them have been removed. The CLI will use the new ones. ([#474][i474])

### Changed
- Bump `golang.org/x/text` to 0.19.0 ([#479][i479])
- Bump `golang.org/x/term` to 0.25.0 ([#478][i478])
- Bump `github.com/schollz/progressbar/v3` to 3.16.1 ([#477][i477])

### Removed
- The deprecated `Album: auto:folderName` and `Album: auto:folderPath` options have been removed. Use the `Album: template:%_directory%` and `Album: template:%_folderpath%` options instead.
- The deprecated `Jobs: CreateAlbums` option has been removed. Use the `Jobs: Album` option instead.

[i474]: https://github.com/gphotosuploader/gphotos-uploader-cli/issues/474
[i479]: https://github.com/gphotosuploader/gphotos-uploader-cli/pull/479
[i478]: https://github.com/gphotosuploader/gphotos-uploader-cli/pull/478
[i477]: https://github.com/gphotosuploader/gphotos-uploader-cli/pull/477

## 4.6.0
### Added
- Support for the latest published Go version (1.23). This project will maintain compatibility with the latest **two major versions** published.
Expand Down
12 changes: 7 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module github.com/gphotosuploader/gphotos-uploader-cli

go 1.21
go 1.22

toolchain go1.23.2

require (
github.com/99designs/keyring v1.2.2
Expand All @@ -14,7 +16,7 @@ require (
github.com/mitchellh/go-homedir v1.1.0
github.com/pierrec/xxHash v0.1.5
github.com/pkg/errors v0.9.1
github.com/schollz/progressbar/v3 v3.15.0
github.com/schollz/progressbar/v3 v3.16.1
github.com/sirupsen/logrus v1.9.3
github.com/spf13/afero v1.11.0
github.com/spf13/cobra v1.8.1
Expand All @@ -23,8 +25,8 @@ require (
github.com/syndtr/goleveldb v1.0.0
golang.org/x/oauth2 v0.23.0
golang.org/x/sync v0.8.0
golang.org/x/term v0.24.0
golang.org/x/text v0.18.0
golang.org/x/term v0.25.0
golang.org/x/text v0.19.0
)

require (
Expand All @@ -51,7 +53,7 @@ require (
github.com/mtibben/percent v0.2.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
golang.org/x/sys v0.25.0 // indirect
golang.org/x/sys v0.26.0 // indirect
google.golang.org/api v0.198.0 // indirect
gopkg.in/yaml.v2 v2.3.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
21 changes: 12 additions & 9 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym
github.com/bmatcuk/doublestar/v2 v2.0.4 h1:6I6oUiT/sU27eE2OFcWqBhL1SwjyvQuOssxT4a1yidI=
github.com/bmatcuk/doublestar/v2 v2.0.4/go.mod h1:QMmcs3H2AUQICWhfzLXz+IYln8lRQmTZRptLie8RgRw=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/chengxilo/virtualterm v1.0.4 h1:Z6IpERbRVlfB8WkOmtbHiDbBANU7cimRIof7mk9/PwM=
github.com/chengxilo/virtualterm v1.0.4/go.mod h1:DyxxBZz/x1iqJjFxTFcr6/x+jSpqN0iwWCOK1q10rlY=
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
Expand Down Expand Up @@ -169,6 +171,8 @@ github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovk
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d h1:5PJl274Y63IEHC+7izoQE9x6ikvDFZS2mDVS3drnohI=
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db h1:62I3jR2EmQ4l5rM/4FEfDWcRD+abF5XlKShorW5LRoQ=
Expand Down Expand Up @@ -196,8 +200,8 @@ github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/schollz/progressbar/v3 v3.15.0 h1:cNZmcNiVyea6oofBTg80ZhVXxf3wG/JoAhqCCwopkQo=
github.com/schollz/progressbar/v3 v3.15.0/go.mod h1:ncBdc++eweU0dQoeZJ3loXoAc+bjaallHRIm8pVVeQM=
github.com/schollz/progressbar/v3 v3.16.1 h1:RnF1neWZFzLCoGx8yp1yF7SDl4AzNDI5y4I0aUJRrZQ=
github.com/schollz/progressbar/v3 v3.16.1/go.mod h1:I2ILR76gz5VXqYMIY/LdLecvMHDPVcQm3W/MSKi1TME=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/spf13/afero v1.11.0 h1:WJQKhtpdm3v2IzqG8VMqrr6Rf3UYpEF239Jy9wNepM8=
Expand All @@ -209,7 +213,6 @@ github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
Expand Down Expand Up @@ -337,17 +340,17 @@ golang.org/x/sys v0.0.0-20210616045830-e2b7044e8c71/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34=
golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.24.0 h1:Mh5cbb+Zk2hqqXNO7S1iTjEphVL+jb8ZWaqh/g+JWkM=
golang.org/x/term v0.24.0/go.mod h1:lOBK/LVxemqiMij05LGJ0tzNr8xlmwBRJ81PX6wVLH8=
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.25.0 h1:WtHI/ltw4NvSUig5KARz9h521QvRC8RmF/cuYqifU24=
golang.org/x/term v0.25.0/go.mod h1:RPyXicDX+6vLxogjjRxjgD2TKtmAO6NZBsBRfrOLu7M=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224=
golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM=
golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
Expand Down
33 changes: 2 additions & 31 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,8 @@ func (c Config) validateJob(fs afero.Fs, job FolderUploadJob, logger log.Logger)
}

func (c Config) checkDeprecatedCreateAlbums(job FolderUploadJob, logger log.Logger) error {
// TODO: 'CreateAlbums' is deprecated. It should be removed on version 5.x
// 'CreateAlbums' is deprecated and it should not be used.
if job.CreateAlbums != "" {
logger.Warnf("Deprecation Notice: The configuration option 'CreateAlbums' is deprecated and will be removed in a future version. Please update your configuration accordingly.")
}
if job.Album == "" && !isValidCreateAlbums(job.CreateAlbums) {
return fmt.Errorf("option CreateAlbums is invalid, '%s", job.CreateAlbums)
}
return nil
Expand Down Expand Up @@ -210,13 +207,6 @@ func (c Config) ensureSourceFolderAbsolutePaths() error {
return nil
}

func isValidAlbumGenerationMethod(method string) bool {
if method != "folderPath" && method != "folderName" {
return false
}
return true
}

// ValidateAlbumOption checks if the value is a valid Album option.
func validateAlbumOption(value string, logger log.Logger) error {
if value == "" {
Expand All @@ -232,7 +222,7 @@ func validateAlbumOption(value string, logger log.Logger) error {
case "name":
return validateNameOption()
case "auto":
return validateAutoOption(after, logger)
return fmt.Errorf("option Album is invalid, '%s", value)
case "template":
return validateTemplateOption(after)
}
Expand All @@ -243,15 +233,6 @@ func validateNameOption() error {
return nil
}

func validateAutoOption(after string, logger log.Logger) error {
// TODO: 'auto:' is deprecated. It should be removed on version 5.x
logger.Warnf("Deprecation Notice: The configuration option 'auto:%s' is deprecated and will be removed in a future version. Please update your configuration accordingly.", after)
if !isValidAlbumGenerationMethod(after) {
return fmt.Errorf("option Album is invalid: unknown album generation method '%s'", after)
}
return nil
}

func validateTemplateOption(after string) error {
err := upload.ValidateAlbumNameTemplate(after)
if err != nil {
Expand All @@ -260,16 +241,6 @@ func validateTemplateOption(after string) error {
return nil
}

// isValidCreateAlbums checks if the value is a valid CreateAlbums option.
func isValidCreateAlbums(value string) bool {
switch value {
case "Off", "folderPath", "folderName":
return true
default:
}
return false
}

// unmarshalReader unmarshal HJSON data into the provided interface.
func unmarshalReader(in io.Reader, c interface{}) error {
buf := new(bytes.Buffer)
Expand Down
59 changes: 5 additions & 54 deletions internal/config/config_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package config_test

import (
"fmt"
"github.com/gphotosuploader/gphotos-uploader-cli/internal/log"
"path/filepath"
"strings"
"testing"

"github.com/spf13/afero"
Expand Down Expand Up @@ -68,9 +66,7 @@ func TestFromFile(t *testing.T) {
}{
{"Should success with Album's name option", "testdata/valid-config/configWithAlbumNameOption.hjson", "youremail@domain.com", false},
{"Should success with Album's template containing token", "testdata/valid-config/configWithAlbumTemplateToken.hjson", "youremail@domain.com", false},
{"Should success with deprecated Album's auto folderName option", "testdata/valid-config/configWithDeprecatedAlbumAutoFolderNameOption.hjson", "youremail@domain.com", false},
{"Should success with deprecated Album's auto folderPath option", "testdata/valid-config/configWithDeprecatedAlbumAutoFolderPathOption.hjson", "youremail@domain.com", false},
{"Should success with deprecated CreateAlbums option", "testdata/valid-config/configWithDeprecatedCreateAlbumsOption.hjson", "youremail@domain.com", false},
{"Should success without Album option", "testdata/valid-config/configWithoutAlbumOption.hjson", "youremail@domain.com", false},

{"Should fail if config dir does not exist", "testdata/non-existent/config.hjson", "", true},
{"Should fail if Account is invalid", "testdata/invalid-config/EmptyAccount.hjson", "", true},
Expand All @@ -85,7 +81,9 @@ func TestFromFile(t *testing.T) {
{"Should fail if Album's key is invalid", "testdata/invalid-config/AlbumBadKey.hjson", "", true},
{"Should fail if Album's name is invalid", "testdata/invalid-config/AlbumEmptyName.hjson", "", true},
{"Should fail if Album's auto value is invalid", "testdata/invalid-config/AlbumBadAutoValue.hjson", "", true},
{"Should fail if deprecated CreateAlbums is invalid", "testdata/invalid-config/DeprecatedCreateAlbums.hjson", "", true},
{"Should fail if deprecated CreateAlbums option is used", "testdata/invalid-config/DeprecatedCreateAlbumsOption.hjson", "", true},
{"Should fail if deprecated Album's auto folderName option is used", "testdata/invalid-config/DeprecatedAlbumAutoFolderNameOption.hjson", "", true},
{"Should fail if deprecated Album's auto folderPath option is used", "testdata/invalid-config/DeprecatedAlbumAutoFolderPathOption.hjson", "", true},
}

for _, tc := range testCases {
Expand All @@ -104,52 +102,6 @@ func TestFromFile(t *testing.T) {
}
}

type mockLogger struct {
log.Logger
messages []string
}

func (m *mockLogger) Warnf(format string, args ...interface{}) {
m.messages = append(m.messages, fmt.Sprintf(format, args...))
}

func TestDeprecationNotices(t *testing.T) {
testCases := []struct {
name string
path string
want string
}{
{"CreateAlbums option", "testdata/valid-config/configWithDeprecatedCreateAlbumsOption.hjson", "CreateAlbums"},
{"auto:folderPath option", "testdata/valid-config/configWithDeprecatedAlbumAutoFolderPathOption.hjson", "auto:folderPath"},
{"auto:folderName option", "testdata/valid-config/configWithDeprecatedAlbumAutoFolderNameOption.hjson", "auto:folderName"},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
fs := afero.OsFs{}
logger := &mockLogger{}
_, err := config.FromFile(fs, tc.path, logger)
if err != nil {
t.Fatalf("Expected no error, got %v", err)
}
// Check that the deprecation notice was logged
if !contains(logger.messages, tc.want) {
t.Errorf("Expected deprecation notice for '%s', got %v", tc.want, logger.messages)
}
})
}
}

// contains checks if a slice contains a string
func contains(slice []string, str string) bool {
for _, v := range slice {
if strings.Contains(v, str) {
return true
}
}
return false
}

func TestConfig_SafePrint(t *testing.T) {
cfg := config.Config{
APIAppCredentials: config.APIAppCredentials{
Expand All @@ -162,14 +114,13 @@ func TestConfig_SafePrint(t *testing.T) {
{
SourceFolder: "foo",
Album: "name:albumName",
CreateAlbums: "folderPath",
DeleteAfterUpload: false,
IncludePatterns: []string{},
ExcludePatterns: []string{},
},
},
}
want := `{"APIAppCredentials":{"ClientID":"client-id","ClientSecret":"REMOVED"},"Account":"account","SecretsBackendType":"auto","Jobs":[{"SourceFolder":"foo","Album":"name:albumName","CreateAlbums":"folderPath","DeleteAfterUpload":false,"IncludePatterns":[],"ExcludePatterns":[]}]}`
want := `{"APIAppCredentials":{"ClientID":"client-id","ClientSecret":"REMOVED"},"Account":"account","SecretsBackendType":"auto","Jobs":[{"SourceFolder":"foo","Album":"name:albumName","DeleteAfterUpload":false,"IncludePatterns":[],"ExcludePatterns":[]}]}`

if want != cfg.SafePrint() {
t.Errorf("want: %s, got: %s", want, cfg.SafePrint())
Expand Down
12 changes: 1 addition & 11 deletions internal/config/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ type FolderUploadJob struct {
// These are the valid values: "name:", "auto:", "template".
// "name:" : Followed by the album name in Google Photos (album names are not unique, so the first to match
// will be selected)
// "auto:" : (deprecated) Followed either "folderPath" or "folderName" will use an autogenerated album name based on the
// object's folder path or object's folder name. Use `template` instead.
// "template": Followed by a template string that can contain the following predefine tokens and functions:
// Tokens:
// %_folderpath% - full path of the folder containing the file.
Expand All @@ -60,15 +58,7 @@ type FolderUploadJob struct {

Album string `json:"Album,omitempty"`

// CreateAlbums is the parameter to create albums on Google Photos.
//
// Deprecated: CreateAlbums exists to maintain backwards compatibility with version 4.x. It should not be used in
// favor of the Album option.
//
// Valid options were:
// Off: Disable album creation (default).
// folderPath: Creates album with the name based on full folder path.
// folderName: Creates album with the name based on the folder name.
// CreateAlbums exists to notice users about its deprecation. It should not be used in favor of the Album option.
CreateAlbums string `json:"CreateAlbums,omitempty"`

// DeleteAfterUpload if it is true, the app will remove files after upload them.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@
[
{
SourceFolder: ./testdata
CreateAlbums: invalid
DeleteAfterUpload: false
IncludePatterns: []
ExcludePatterns: []
}
]
}
}

0 comments on commit 21c029e

Please sign in to comment.