Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .github/workflows/mocks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inspired by the docs check

name: Check Mock Generation
on:
push:
branches:
- master
pull_request:
jobs:
mocks:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: 1.17
- name: Intsall go-mock
run: go install github.com/golang/mock/mockgen@latest
- name: Generate mocks
run: make gen-mocks
- name: Check for uncommited files
run: |
export FILES=$(git ls-files -o -m --directory --exclude-standard --no-empty-directory)
export LINES=$(echo "$FILES" | awk 'NF' | wc -l)
if [ $LINES -ne 0 ]; then
echo "Detected files that need to be committed:"
echo "$FILES" | sed -e "s/^/ /"
echo ""
echo "Try running: make gen-mocks"
exit 1
fi
22 changes: 17 additions & 5 deletions internal/latestrelease/finder.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ package latestrelease
import (
"context"
"strings"
"time"

"github.com/Masterminds/semver/v3"
"github.com/google/go-github/v42/github"
"github.com/mongodb/mongocli/internal/version"
)

//go:generate mockgen -destination=../mocks/mock_release_version.go -package=mocks github.com/mongodb/mongocli/internal/version VersionFinder
//go:generate mockgen -destination=../mocks/mock_release_version.go -package=mocks github.com/mongodb/mongocli/internal/latestrelease VersionFinder
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix to mock generation


type VersionFinder interface {
HasNewVersionAvailable(v, tool string) (newVersionAvailable bool, newVersion string, err error)
Expand All @@ -45,14 +46,25 @@ func versionFromTag(release *github.RepositoryRelease, toolName string) string {
return release.GetTagName()
}

const (
mongoCLI = "mongocli"
atlasCLI = "atlascli"
)
Comment on lines +49 to +52
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

drive by these were being imported from the version package but only used here


func isValidTagForTool(tag, tool string) bool {
if tool == version.MongoCLI {
return !strings.Contains(tag, version.AtlasCLI)
if tool == mongoCLI {
return !strings.Contains(tag, atlasCLI)
}
return strings.Contains(tag, tool)
}

func (s *latestReleaseVersionFinder) searchLatestVersionPerTool(currentVersion *semver.Version, toolName string) (bool, *version.ReleaseInformation, error) {
// ReleaseInformation Release information.
type ReleaseInformation struct {
Version string
PublishedAt time.Time
}
Comment on lines +62 to +65
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above, imported from version but only ever used here


func (s *latestReleaseVersionFinder) searchLatestVersionPerTool(currentVersion *semver.Version, toolName string) (bool, *ReleaseInformation, error) {
release, err := s.r.LatestWithCriteria(minPageSize, isValidTagForTool, toolName)

if err != nil || release == nil {
Expand All @@ -66,7 +78,7 @@ func (s *latestReleaseVersionFinder) searchLatestVersionPerTool(currentVersion *
}

if currentVersion.Compare(v) < 0 {
return true, &version.ReleaseInformation{
return true, &ReleaseInformation{
Version: v.Original(),
PublishedAt: release.GetPublishedAt().Time,
}, nil
Expand Down
47 changes: 0 additions & 47 deletions internal/mocks/mock_tool_latest_version_finder.go

This file was deleted.

5 changes: 3 additions & 2 deletions internal/version/release_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ func (s *releaseVersionFetcher) LatestWithCriteria(n int, matchCriteria Criteria
return true
}
}

const owner = "mongodb"
const project = "mongodb-atlas-cli"
for {
releases, resp, err := client.Repositories.ListReleases(s.ctx, owner, "mongodb-atlas-cli", opt)
releases, resp, err := client.Repositories.ListReleases(s.ctx, owner, project, opt)
if err != nil {
return nil, err
}
Expand Down
14 changes: 0 additions & 14 deletions internal/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,8 @@

package version

import "time"

const (
MongoCLI = "mongocli"
AtlasCLI = "atlascli"
owner = "mongodb"
)
Comment on lines -19 to -23
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved closer to where needed


// Version for CLI.
var Version string

// GitCommit git sha of the build.
var GitCommit string

// ReleaseInformation Release information.
type ReleaseInformation struct {
Version string
PublishedAt time.Time
}
Comment on lines -32 to -35
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved closer to where needed