diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d05d69e..5e13b49 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -79,38 +79,3 @@ jobs: # - os: ios # args: -app-id calc.sha${{ github.sha }} # host: macos-latest - - # - name: Cache build artifacts - # uses: actions/cache@v3 - # with: - # path: | - # ~/go/pkg/mod - # ~/.cache/go-build - # ~/.cache/fyne-cross - # key: ${{ runner.os }}-build-cache-${{ hashFiles('**/go.sum') }} - - # - name: Install Fyne-cross - # # working-directory: fyne-cross - # run: go install github.com/fyne-io/fyne-cross@latest - - # # attempt to use "go install" but fallback to "go get" - # # - name: Install Fyne - # # run: | - # # go install fyne.io/fyne/v2/cmd/fyne@latest || - # # go get fyne.io/fyne/v2/cmd/fyne@latest - - # # - name: Install Podman - # # if: ${{ runner.os == 'macos' }} - # # run: | - # # brew install podman - # # podman machine init - # # podman machine start - - # - name: Build - # # working-directory: calculator - # run: | - # fyne-cross \ - # ${{ matrix.target.os }} \ - # ${{ matrix.target.args }} \ - # -name mastotool${{ matrix.target.ext }} \ - # -app-id com.github.PaulWaldo.mastotool diff --git a/.github/workflows/verification.yml b/.github/workflows/verification.yml index 2f3bb33..1f3a3b6 100644 --- a/.github/workflows/verification.yml +++ b/.github/workflows/verification.yml @@ -25,21 +25,22 @@ jobs: run: test -z $(find . -name '*.go' -type f | xargs goimports -e -d | tee /dev/stderr) - name: "Run staticcheck" run: staticcheck ./... + # Unable to do race detection now, see https://github.com/fyne-io/fyne/issues/2509 - name: "Unit Tests" - run: go test -v -race -cover ./... + run: go test -v -cover ./... golangci: - strategy: - matrix: - go: ["1.21"] - os: [macos-latest, windows-latest, linux] name: lint - runs-on: ${{ matrix.os }} + runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - name: Install required packages + run: sudo apt-get update && sudo apt-get install -y libgl1-mesa-dev xorg-dev + + - uses: actions/checkout@v4 - uses: actions/setup-go@v4 with: - go-version: ${{ matrix.go }} + go-version: "1.21.x" + - name: golangci-lint uses: golangci/golangci-lint-action@v3 with: diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..6859c2d --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,184 @@ +# !! Requires Pre-Commit +# !! https://pre-commit.com +# !! Config File: $GIT_REPO_ROOT/.pre-commit-config.yaml +# !! Already have a config file present? +# !! Copy/Paste everything below `repos:` into your existing file +# !! Don't already have a config file? +# !! Copy this whole file into your repo root (as '.pre-commit-config.yaml') +# !! Delete this header section +# !! Consider adding some built-in pre-commmit hooks to your project +# !! (They're quite useful!) +# !! ALL Hooks enabled by default - Comment out hooks you are not using +repos: + # ========================================================================== + # Golang Pre-Commit Hooks | https://github.com/tekwizely/pre-commit-golang + # + # Visit the project home page to learn more about the available Hooks, + # including useful arguments you might want to pass into them. + # + # File-Based Hooks: + # Run against matching staged files individually. + # + # Module-Based Hooks: + # Run against module root folders containing matching staged files. + # + # Package-Based Hooks: + # Run against folders containing one or more staged files. + # + # Repo-Based Hooks: + # Run against the entire repo. + # The hooks only run once (if any matching files are staged), + # and are NOT provided the list of staged files, + # + # My-Cmd-* Hooks + # Allow you to invoke custom tools in various contexts. + # Can be useful if your favorite tool(s) are not built-in (yet) + # + # Hook Suffixes + # Hooks have suffixes in their name that indicate their targets: + # + # +-----------+--------------+ + # | Suffix | Target | + # |-----------+--------------+ + # | | Files | + # | -mod | Module | + # | -pkg | Package | + # | -repo | Repo Root | + # | -repo-mod | All Modules | + # | -repo-pkg | All Packages | + # +-----------+--------------+ + # + # ! Multiple Hook Invocations + # ! Due to OS command-line-length limits, Pre-Commit can invoke a hook + # ! multiple times if a large number of files are staged. + # ! For file and repo-based hooks, this isn't an issue, but for module + # ! and package-based hooks, there is a potential for the hook to run + # ! against the same module or package multiple times, duplicating any + # ! errors or warnings. + # + # Useful Hook Parameters: + # - id: hook-id + # args: [arg1, arg2, ..., '--'] # Pass options ('--' is optional) + # always_run: true # Run even if no matching files staged + # alias: hook-alias # Create an alias + # + # Passing Options To Hooks: + # If your options contain a reference to an existing file, then you will + # need to use a trailing '--' argument to separate the hook options from + # the modified-file list that Pre-Commit passes into the hook. + # NOTE: For repo-based hooks, '--' is not needed. + # + # Passing Environment Variables to Hooks: + # You can pass environment variables to hooks using args with the + # following format: + # + # --hook:env:NAME=VALUE + # + # Always Run: + # By default, hooks ONLY run when matching file types are staged. + # When configured to "always_run", a hook is executed as if EVERY matching + # file were staged. + # + # Aliases: + # Consider adding aliases to longer-named hooks for easier CLI usage. + # ========================================================================== + - repo: https://github.com/tekwizely/pre-commit-golang + rev: v1.0.0-rc.1 + hooks: + # + # Go Build + # + # - id: go-build-mod + # - id: go-build-pkg + # - id: go-build-repo-mod + # - id: go-build-repo-pkg + # + # Go Mod Tidy + # + - id: go-mod-tidy + # - id: go-mod-tidy-repo + # + # Go Test + # + - id: go-test-mod + # - id: go-test-pkg + # - id: go-test-repo-mod + # - id: go-test-repo-pkg + # + # Go Vet + # + # - id: go-vet + # - id: go-vet-mod + # - id: go-vet-pkg + # - id: go-vet-repo-mod + # - id: go-vet-repo-pkg + # + # Revive + # + # - id: go-revive + # - id: go-revive-mod + # - id: go-revive-repo-mod + # + # GoSec + # + # - id: go-sec-mod + # - id: go-sec-pkg + # - id: go-sec-repo-mod + # - id: go-sec-repo-pkg + # + # StaticCheck + # + - id: go-staticcheck-mod + # - id: go-staticcheck-pkg + # - id: go-staticcheck-repo-mod + # - id: go-staticcheck-repo-pkg + # + # StructSlop + # + # - id: go-structslop-mod + # - id: go-structslop-pkg + # - id: go-structslop-repo-mod + # - id: go-structslop-repo-pkg + # + # Formatters + # + # - id: go-fmt + # - id: go-fmt-repo + # - id: go-fumpt # replaces go-fmt + # - id: go-fumpt-repo # replaces go-fmt-repo + - id: go-imports # replaces go-fmt + # - id: go-imports-repo # replaces go-fmt-repo + # - id: go-returns # replaces go-imports & go-fmt + # - id: go-returns-repo # replaces go-imports-repo & go-fmt-repo + # + # Style Checkers + # + # - id: go-lint + # - id: go-critic + # + # GolangCI-Lint + # - Fast Multi-Linter + # - Can be configured to replace MOST other hooks + # - Supports repo config file for configuration + # - https://github.com/golangci/golangci-lint + # + # - id: golangci-lint + # - id: golangci-lint-mod + # - id: golangci-lint-pkg + - id: golangci-lint-repo-mod + # - id: golangci-lint-repo-pkg + # + # Invoking Custom Go Tools + # - Configured *entirely* through the `args` attribute, ie: + # args: [ go, test, ./... ] + # - Use arg `--hook:error-on-output` to indicate that any output from the tool + # should be treated as an error. + # - Use the `name` attribute to provide better messaging when the hook runs + # - Use the `alias` attribute to be able to invoke your hook via `pre-commit run` + # + # - id: my-cmd + # - id: my-cmd-mod + # - id: my-cmd-pkg + # - id: my-cmd-repo + # - id: my-cmd-repo-mod + # - id: my-cmd-repo-pkg diff --git a/Makefile b/Makefile index 15efc6e..6cc3290 100644 --- a/Makefile +++ b/Makefile @@ -18,4 +18,12 @@ package: fyne package -icon assets/Icon.png -name Mastotool mobilesim: - go run -tags mobile main.go \ No newline at end of file + go run -tags mobile main.go + +showcov: + go test ./... -coverprofile=coverage.out -covermode=count + go tool cover -html=coverage.out + rm coverage.out + +testdocs: + gotestdox ./... \ No newline at end of file diff --git a/go.sum b/go.sum index 0e3ff67..ca678f0 100644 --- a/go.sum +++ b/go.sum @@ -74,8 +74,7 @@ github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.m github.com/envoyproxy/go-control-plane v0.9.9-0.20210217033140-668b12f5399d/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= -github.com/fredbi/uri v1.0.0 h1:s4QwUAZ8fz+mbTsukND+4V5f+mJ/wjaTokwstGUAemg= -github.com/fredbi/uri v1.0.0/go.mod h1:1xC40RnIOGCaQzswaOvrzvG/3M3F0hyDVb3aO/1iGy0= +github.com/felixge/fgprof v0.9.3 h1:VvyZxILNuCiUCSXtPtYmmtGvb65nqXh2QFWc0Wpf2/g= github.com/fredbi/uri v1.1.0 h1:OqLpTXtyRg9ABReqvDGdJPqZUxs8cyBDOMXBbskCaB8= github.com/fredbi/uri v1.1.0/go.mod h1:aYTUoAXBOq7BLfVJ8GnKmfcuURosB1xyHDIfWeC/iW4= github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= @@ -98,8 +97,6 @@ github.com/go-gl/glfw/v3.3/glfw v0.0.0-20221017161538-93cebf72946b h1:GgabKamyOY github.com/go-gl/glfw/v3.3/glfw v0.0.0-20221017161538-93cebf72946b/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= github.com/go-text/render v0.0.0-20230619120952-35bccb6164b8 h1:VkKnvzbvHqgEfm351rfr8Uclu5fnwq8HP2ximUzJsBM= github.com/go-text/render v0.0.0-20230619120952-35bccb6164b8/go.mod h1:h29xCucjNsDcYb7+0rJokxVwYAq+9kQ19WiFuBKkYtc= -github.com/go-text/typesetting v0.0.0-20230803102845-24e03d8b5372 h1:FQivqchis6bE2/9uF70M2gmmLpe82esEm2QadL0TEJo= -github.com/go-text/typesetting v0.0.0-20230803102845-24e03d8b5372/go.mod h1:evDBbvNR/KaVFZ2ZlDSOWWXIUKq0wCOEtzLxRM8SG3k= github.com/go-text/typesetting v0.0.0-20230905121921-abdbcca6e0eb h1:4GpJirtA8yY24aqbU3uppiXGYiVpWfLIrqc2NNKKk9s= github.com/go-text/typesetting v0.0.0-20230905121921-abdbcca6e0eb/go.mod h1:evDBbvNR/KaVFZ2ZlDSOWWXIUKq0wCOEtzLxRM8SG3k= github.com/go-text/typesetting-utils v0.0.0-20230616150549-2a7df14b6a22 h1:LBQTFxP2MfsyEDqSKmUBZaDuDHN1vpqDyOZjcqS7MYI= @@ -165,6 +162,7 @@ github.com/google/pprof v0.0.0-20201023163331-3e6fc7fc9c4c/go.mod h1:kpwsk12EmLe github.com/google/pprof v0.0.0-20201203190320-1bf35d6f28c2/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20210122040257-d980be63207e/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20210226084205-cbba55b83ad5/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= +github.com/google/pprof v0.0.0-20211214055906-6f57359322fd h1:1FjCyPC+syAzJ5/2S8fqdZK1R22vvA0J7JZKcuOIQ7Y= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= @@ -239,6 +237,7 @@ github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FI github.com/pelletier/go-toml v1.9.3/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c= github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/profile v1.7.0 h1:hnbDkaNWPCLMO9wGLdBFTIZvzDrDfBM2072E1S9gJkA= github.com/pkg/sftp v1.10.1/go.mod h1:lYOWFsE0bwd1+KfKJaKeuokY15vzFx25BLbzYYoAxZI= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= @@ -269,7 +268,6 @@ github.com/srwiley/oksvg v0.0.0-20221011165216-be6e8873101c/go.mod h1:cNQ3dwVJtS github.com/srwiley/rasterx v0.0.0-20220730225603-2ab79fcdd4ef h1:Ch6Q+AZUxDBCVqdkI8FSpFyZDtCVBc2VmejdNrm5rRQ= github.com/srwiley/rasterx v0.0.0-20220730225603-2ab79fcdd4ef/go.mod h1:nXTWP6+gD5+LUJ8krVhhoeHjvHTutPxMYl5SvkcnJNE= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= @@ -277,7 +275,6 @@ github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5 github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= @@ -327,8 +324,6 @@ golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u0 golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM= golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU= -golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63 h1:m64FZMko/V45gv0bNmrNYoDEq8U5YUhetc9cBWKS1TQ= -golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63/go.mod h1:0v4NqG35kSWCMzLaMeX+IQrlSnVE/bqGSyC2cz/9Le8= golang.org/x/exp v0.0.0-20230905200255-921286631fa9 h1:GoHiUyI/Tp2nVkLI2mCxVkOjsbSXD66ic0XW0js0R9g= golang.org/x/exp v0.0.0-20230905200255-921286631fa9/go.mod h1:S2oDrQGGwySpoQPVqRShND87VCbxmc6bL1Yd2oYrm6k= golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= @@ -350,8 +345,6 @@ golang.org/x/lint v0.0.0-20210508222113-6edffad5e616/go.mod h1:3xt1FjdF8hUf6vQPI golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE= golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o= golang.org/x/mobile v0.0.0-20211207041440-4e6c2922fdee/go.mod h1:pe2sM7Uk+2Su1y7u/6Z8KJ24D7lepUjFZbhFOrmDfuQ= -golang.org/x/mobile v0.0.0-20230901161150-52620a4a7557 h1:mLrcd+qwh23kzD7ej1VxCa+A23UNr+BCjSj2tNX8/NM= -golang.org/x/mobile v0.0.0-20230901161150-52620a4a7557/go.mod h1:f0gjFM6UTH7y1WEZBm/kquBYsogL+NQtllKFy4Rdulc= golang.org/x/mobile v0.0.0-20230922142353-e2f452493d57 h1:Q6NT8ckDYNcwmi/bmxe+XbiDMXqMRW1xFBtJ+bIpie4= golang.org/x/mobile v0.0.0-20230922142353-e2f452493d57/go.mod h1:wEyOn6VvNW7tcf+bW/wBz1sehi2s2BZ4TimyR7qZen4= golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= diff --git a/internal/app/ui/authenticate.go b/internal/app/ui/authenticate.go index 16d23a3..ada45b6 100644 --- a/internal/app/ui/authenticate.go +++ b/internal/app/ui/authenticate.go @@ -21,9 +21,7 @@ func (ma *myApp) authenticate() { form := dialog.NewCustomConfirm("URL of your Mastodon server", "Authenticate", "Abort", formContents, func(confirmed bool) { if confirmed { val, _ := ma.prefs.MastodonServer.Get() - // fmt.Printf("Server is %s\n", val) app, err := mastodon.RegisterApp(context.Background(), app.NewAuthenticationConfig(val)) - // fmt.Printf("Got token %+v\n", app) if err != nil { dialog.NewError(err, ma.window).Show() return @@ -66,7 +64,7 @@ func (ma *myApp) getAuthCode() { { Text: "Authorization Code", Widget: accessTokenEntry, - HintText: "XXXXXXXXXXXXXXX", + HintText: "XXX-XXX-XXX", }}, func(confirmed bool) { if confirmed { diff --git a/internal/app/ui/followedtags.go b/internal/app/ui/followedtags.go index 9cb72eb..3008128 100644 --- a/internal/app/ui/followedtags.go +++ b/internal/app/ui/followedtags.go @@ -5,7 +5,9 @@ import ( "strings" "fyne.io/fyne/v2" + "fyne.io/fyne/v2/canvas" "fyne.io/fyne/v2/container" + "fyne.io/fyne/v2/data/binding" "fyne.io/fyne/v2/dialog" "fyne.io/fyne/v2/theme" "fyne.io/fyne/v2/widget" @@ -72,7 +74,22 @@ func (ma *myApp) MakeFollowedTagsUI() fyne.CanvasObject { ma.refreshButton = widget.NewButtonWithIcon("Refresh", theme.ViewRefreshIcon(), func() { ma.refreshFollowedTags() }) - bottom := container.NewBorder(nil, nil, nil, ma.refreshButton, ma.unfollowButton) + bottomButtons := container.NewBorder(nil, nil, nil, ma.refreshButton, ma.unfollowButton) + + // Created muted text that shows the connected server + ma.serverText = canvas.NewText("", theme.PlaceHolderColor()) + ma.serverText.TextSize = theme.CaptionTextSize() + ss := func() { + s, _ := ma.prefs.MastodonServer.Get() + ma.serverText.Text = s + ma.serverText.Refresh() + } + if ma.prefs.MastodonServer != nil { + ma.prefs.MastodonServer.AddListener(binding.NewDataListener(ss)) + } + + bottom := container.NewVBox(ma.serverText, bottomButtons) + // bottom := container.NewBorder(nil, nil, nil, ma.refreshButton, ma.unfollowButton) return container.NewBorder(nil, bottom, nil, nil, ma.listChoices) } diff --git a/internal/app/ui/followedtags_test.go b/internal/app/ui/followedtags_test.go index 69aaae1..f2064c2 100644 --- a/internal/app/ui/followedtags_test.go +++ b/internal/app/ui/followedtags_test.go @@ -92,10 +92,14 @@ func TestFollowedTagsUI_TappingRefreshButtonRepopulatesTags(t *testing.T) { keepTags := createTags("KTag", 3) removeTags := createTags("RTag", 1) ma := myApp{keepTags: keepTags, removeTags: removeTags, window: w, app: a, prefs: NewPreferences(a)} - _ = ma.prefs.AccessToken.Set("access") - _ = ma.prefs.ClientID.Set("clientid") - _ = ma.prefs.ClientSecret.Set("secret") + var err error + err = ma.prefs.AccessToken.Set("access") + assert.NoError(t, err) + err = ma.prefs.ClientID.Set("clientid") + assert.NoError(t, err) + err = ma.prefs.ClientSecret.Set("secret") w.SetContent(ma.MakeFollowedTagsUI()) + assert.NoError(t, err) w.Resize(fyne.Size{Width: 400, Height: 400}) assert.Equal(t, 3, ma.listChoices.LeftList.Length()) assert.Equal(t, 1, ma.listChoices.RightList.Length()) @@ -114,11 +118,45 @@ func TestFollowedTagsUI_TappingRefreshButtonRepopulatesTags(t *testing.T) { } })) defer serv.Close() - ma.prefs = NewPreferences(a) - err := ma.prefs.MastodonServer.Set(serv.URL) + err = ma.prefs.MastodonServer.Set(serv.URL) assert.NoError(t, err) test.Tap(ma.refreshButton) assert.Equal(t, 1, ma.listChoices.LeftList.Length(), "After refresh, expecting 1 item, got %d", ma.listChoices.LeftList.Length()) assert.Equal(t, 0, ma.listChoices.RightList.Length(), "After refresh, expecting 0 items, got %d", ma.listChoices.RightList.Length()) } + +func Test_MakeFollowedTagsUI_SetsServerTextFromCurrentServer(t *testing.T) { + type fields struct { + server string + } + tests := []struct { + name string + fields fields + want string + }{ + { + name: "Proper server URL", + fields: fields{server: "https://myserver.com"}, + want: "https://myserver.com", + }, + { + name: "Empty server URL", + want: "", + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + a := test.NewApp() + w := a.NewWindow("") + p := NewPreferences(a) + err := p.MastodonServer.Set(tt.fields.server) + assert.NoError(t, err) + + ma := &myApp{prefs: p, app: a, window: w} + ui := ma.MakeFollowedTagsUI() + w.SetContent(ui) + assert.Equal(t, tt.want, ma.serverText.Text) + }) + } +} diff --git a/internal/app/ui/main.go b/internal/app/ui/main.go index 54b333e..2646bf5 100644 --- a/internal/app/ui/main.go +++ b/internal/app/ui/main.go @@ -3,6 +3,7 @@ package ui import ( "fyne.io/fyne/v2" "fyne.io/fyne/v2/app" + "fyne.io/fyne/v2/canvas" "fyne.io/fyne/v2/widget" "github.com/mattn/go-mastodon" ) @@ -18,6 +19,7 @@ type myApp struct { unfollowButton *widget.Button refreshButton *widget.Button loginMenu, logoutMenu *fyne.MenuItem + serverText *canvas.Text } func Run() { diff --git a/old/ci.yml b/old/ci.yml deleted file mode 100644 index 4c738dc..0000000 --- a/old/ci.yml +++ /dev/null @@ -1,142 +0,0 @@ -name: "CI" -on: [push, pull_request] - -jobs: - setup-code: - uses: ./.github/workflows/setup_code.yml - - verify: - uses: ./.github/workflows/code_verification.yml - - # lint: - # name: Lint - # runs-on: "ubuntu-latest" - # steps: - # - name: Install required packages - # run: sudo apt-get update && sudo apt-get install -y libgl1-mesa-dev xorg-dev - - # - uses: actions/checkout@v4 - - # - name: Set up Go - # uses: actions/setup-go@v4 - # with: - # go-version: "1.20" - - # # - name: Setup Go environment - # # uses: actions/setup-go@v3 - # # with: - # # go-version: "1.19.x" - - # - name: Install staticcheck - # run: go install honnef.co/go/tools/cmd/staticcheck@latest - # - name: Install goimports - # run: go install golang.org/x/tools/cmd/goimports@latest - - # # Checks-out the repository under $GITHUB_WORKSPACE - # - uses: actions/checkout@v4 - - # # Run linters - # - name: Run go vet - # run: go vet ./... - # - name: Run goimports - # run: test -z $(find . -name '*.go' -type f | xargs goimports -e -d | tee /dev/stderr) - # - name: Run staticcheck - # run: staticcheck ./... - - # test: - # name: "Test" - # runs-on: ${{ matrix.os }} - # strategy: - # matrix: - # os: [ubuntu-latest] - # # use max/min supported Go versions - # go-version: ["1.18.x", "1.21.x"] - - # steps: - # - name: Setup Go environment - # id: setup-go - # uses: actions/setup-go@v3 - # with: - # go-version: ${{ matrix.go-version }} - # - name: Install required packages - # run: sudo apt-get update && sudo apt-get install -y libgl1-mesa-dev xorg-dev - - # # Checks-out the repository under $GITHUB_WORKSPACE - # - uses: actions/checkout@v4 - - # # Run tests - # - run: go test -v -race -cover ./... - - build: - name: "Build MastoTool (${{ matrix.target.os }}, ${{ matrix.go-version }})" - runs-on: ${{ matrix.target.host || 'ubuntu-latest' }} - # env: - # GO111MODULE: on - strategy: - fail-fast: false - matrix: - # use max/min supported Go versions - go-version: ["1.18.x"] - target: - - os: linux - # - os: windows - # ext: .exe - # - os: freebsd - # - os: android - # args: -app-id calc.sha${{ github.sha }} - ## Not shared darwin image is available at the moment - # - os: darwin - # args: -app-id calc.sha${{ github.sha }} - # host: macos-latest - # - os: web - - ## Currently not easily supported from GitHub actions. - ## https://github.com/fyne-io/fyne-cross/pull/104#issuecomment-1099494308 - # - os: ios - # args: -app-id calc.sha${{ github.sha }} - # host: macos-latest - - steps: - - name: Setup Go environment - id: setup-go - uses: actions/setup-go@v3 - with: - go-version: ${{ matrix.go-version }} - - - name: Checkout code - uses: actions/checkout@v4 - - - name: Cache build artifacts - uses: actions/cache@v3 - with: - path: | - ~/go/pkg/mod - ~/.cache/go-build - ~/.cache/fyne-cross - key: ${{ runner.os }}-build-cache-${{ hashFiles('**/go.sum') }} - - - name: Install Fyne-cross - # working-directory: fyne-cross - run: go install github.com/fyne-io/fyne-cross@latest - - # attempt to use "go install" but fallback to "go get" - # - name: Install Fyne - # run: | - # go install fyne.io/fyne/v2/cmd/fyne@latest || - # go get fyne.io/fyne/v2/cmd/fyne@latest - - # - name: Install Podman - # if: ${{ runner.os == 'macos' }} - # run: | - # brew install podman - # podman machine init - # podman machine start - - - name: Build - # working-directory: calculator - run: | - fyne-cross \ - ${{ matrix.target.os }} \ - ${{ matrix.target.args }} \ - -name mastotool${{ matrix.target.ext }} \ - -app-id com.github.PaulWaldo.mastotool diff --git a/old/codeql.yml b/old/codeql.yml deleted file mode 100644 index 7974b97..0000000 --- a/old/codeql.yml +++ /dev/null @@ -1,86 +0,0 @@ -# For most projects, this workflow file will not need changing; you simply need -# to commit it to your repository. -# -# You may wish to alter this file to override the set of languages analyzed, -# or to provide custom queries or build logic. -# -# ******** NOTE ******** -# We have attempted to detect the languages in your repository. Please check -# the `language` matrix defined below to confirm you have the correct set of -# supported CodeQL languages. -# -name: "CodeQL" - -on: - push: - # branches: ["main"] - pull_request: - # The branches below must be a subset of the branches above - # branches: ["main"] - schedule: - - cron: "30 5 * * 0" - -jobs: - analyze: - name: Analyze - # Runner size impacts CodeQL analysis time. To learn more, please see: - # - https://gh.io/recommended-hardware-resources-for-running-codeql - # - https://gh.io/supported-runners-and-hardware-resources - # - https://gh.io/using-larger-runners - # Consider using larger runners for possible analysis time improvements. - runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }} - timeout-minutes: ${{ (matrix.language == 'swift' && 120) || 360 }} - permissions: - actions: read - contents: read - security-events: write - - strategy: - fail-fast: false - matrix: - language: ["go"] - # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby', 'swift' ] - # Use only 'java' to analyze code written in Java, Kotlin or both - # Use only 'javascript' to analyze code written in JavaScript, TypeScript or both - # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support - - steps: - # -name: "Setup Code" - # - uses: ./.github/workflows/setup_code.yml - - name: Checkout repository - uses: actions/checkout@v3 - - - name: Install required packages - run: sudo apt-get update && sudo apt-get install -y libgl1-mesa-dev xorg-dev - - # Initializes the CodeQL tools for scanning. - - name: Initialize CodeQL - uses: github/codeql-action/init@v2 - with: - languages: ${{ matrix.language }} - # If you wish to specify custom queries, you can do so here or in a config file. - # By default, queries listed here will override any specified in a config file. - # Prefix the list here with "+" to use these queries and those in the config file. - - # For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs - # queries: security-extended,security-and-quality - - # Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift). - # If this step fails, then you should remove it and run the build manually (see below) - - name: Autobuild - uses: github/codeql-action/autobuild@v2 - - # ℹī¸ Command-line programs to run using the OS shell. - # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun - - # If the Autobuild fails above, remove it and uncomment the following three lines. - # modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance. - - # - run: | - # echo "Run, Build Application using script" - # ./location_of_script_within_repo/buildscript.sh - - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v2 - with: - category: "/language:${{matrix.language}}" diff --git a/old/go_app.yml b/old/go_app.yml deleted file mode 100644 index 58950f0..0000000 --- a/old/go_app.yml +++ /dev/null @@ -1,83 +0,0 @@ -# .github/workflows/go_app.yml - -name: Go Application CI/CD - -on: - pull_request_target: - types: - - opened - - synchronize - - reopened - - ready_for_review - push: - branches: - - main - - develop - - "*" - tags-ignore: - - "*" - -jobs: - setup: - runs-on: ubuntu-latest - - steps: - - name: Install required packages - run: sudo apt-get update && sudo apt-get install -y libgl1-mesa-dev xorg-dev - - - name: Checkout code - uses: actions/checkout@v3 - with: - ref: ${{ github.ref }} - - - name: Set up Go - uses: actions/setup-go@v4 - with: - go-version: 1.x - - - name: Build the Go application - run: go version && pwd && ls -lR && go build -o myapp - - build: - runs-on: ubuntu-latest - needs: setup - - steps: - - name: Build the Go application - run: go version && pwd && ls -lR && go build -o myapp - - test: - runs-on: ubuntu-latest - needs: setup - - steps: - - name: Run tests and generate code coverage report - run: go test -coverprofile=coverage.out ./... - - - name: Upload coverage report - if: always() # Upload coverage report regardless of test success - uses: actions/upload-artifact@v2 - with: - name: coverage-report - path: coverage.out - - release: - runs-on: ubuntu-latest - needs: setup - - steps: - - name: Build and release executables - run: | - GOOS=darwin GOARCH=amd64 go build -o myapp_macOS - GOOS=windows GOARCH=amd64 go build -o myapp_windows.exe - GOOS=linux GOARCH=amd64 go build -o myapp_linux - - - name: Upload executables as artifacts - if: always() # Upload executables regardless of build success - uses: actions/upload-artifact@v2 - with: - name: release-artifacts - path: | - myapp_macOS - myapp_windows.exe - myapp_linux