Skip to content

Expose Go API functions for loading library registry data files #57

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 15, 2021
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module arduino.cc/repository
module github.com/arduino/libraries-repository-engine

go 1.14

Expand Down
2 changes: 1 addition & 1 deletion internal/libraries/db/library.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
"regexp"
"strings"

"arduino.cc/repository/internal/libraries/metadata"
"github.com/arduino/libraries-repository-engine/internal/libraries/metadata"
)

// FromLibraryToRelease extract a Release from LibraryMetadata. LibraryMetadata must be
Expand Down
4 changes: 2 additions & 2 deletions internal/libraries/git_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ import (
"path/filepath"
"testing"

"arduino.cc/repository/internal/libraries/db"
"arduino.cc/repository/internal/libraries/gitutils"
"github.com/arduino/libraries-repository-engine/internal/libraries/db"
"github.com/arduino/libraries-repository-engine/internal/libraries/gitutils"
"github.com/stretchr/testify/require"
)

Expand Down
4 changes: 2 additions & 2 deletions internal/libraries/repoarchive.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ import (
"path/filepath"
"regexp"

"arduino.cc/repository/internal/libraries/metadata"
"arduino.cc/repository/internal/libraries/zip"
"github.com/arduino/libraries-repository-engine/internal/libraries/metadata"
"github.com/arduino/libraries-repository-engine/internal/libraries/zip"
)

// ZipRepo creates a ZIP archive of the repo folder and returns its path.
Expand Down
4 changes: 2 additions & 2 deletions internal/libraries/repoclone.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ import (
"os"
"path/filepath"

"arduino.cc/repository/internal/libraries/db"
"github.com/arduino/libraries-repository-engine/internal/libraries/db"

"fmt"

"arduino.cc/repository/internal/libraries/metadata"
"github.com/arduino/libraries-repository-engine/internal/libraries/metadata"
"github.com/go-git/go-git/v5"
)

Expand Down
7 changes: 4 additions & 3 deletions internal/libraries/repolist.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ import (
"strings"
)

func loadRepoListFromFile(filename string) ([]*Repo, error) {
// LoadRepoListFromFile returns an unfiltered list of library registry entries loaded from the given data file.
func LoadRepoListFromFile(filename string) ([]*Repo, error) {
file, err := os.Open(filename)
if err != nil {
return nil, err
Expand Down Expand Up @@ -153,9 +154,9 @@ func toListOfUniqueRepos(repos []*Repo) []*Repo {
return finalRepos
}

// ListRepos loads a list from the given filename.
// ListRepos returns a filtered list of library registry entries loaded from the given data file.
func ListRepos(reposFilename string) ([]*Repo, error) {
repos, err := loadRepoListFromFile(reposFilename)
repos, err := LoadRepoListFromFile(reposFilename)
if err != nil {
return nil, err
}
Expand Down
25 changes: 0 additions & 25 deletions internal/libraries/repolist_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,31 +29,6 @@ import (
"github.com/stretchr/testify/require"
)

func TestListRepos(t *testing.T) {
repos, err := ListRepos("./testdata/git_test_repos.txt")

require.Equal(t, 11, len(repos))

require.Equal(t, "https://github.com/PaulStoffregen/OctoWS2811.git", repos[0].URL)
require.Equal(t, "https://github.com/PaulStoffregen/AltSoftSerial.git", repos[1].URL)

require.Equal(t, "https://github.com/Cheong2K/ble-sdk-arduino.git", repos[2].URL)
require.Equal(t, "https://github.com/arduino-libraries/Bridge.git", repos[3].URL)
require.Equal(t, "https://github.com/adafruit/Adafruit_ADS1X15.git", repos[4].URL)
require.Equal(t, "https://github.com/adafruit/Adafruit_ADXL345.git", repos[5].URL)
require.Equal(t, "https://github.com/adafruit/Adafruit_AHRS.git", repos[6].URL)
require.Equal(t, "https://github.com/adafruit/Adafruit_AM2315.git", repos[7].URL)
require.Equal(t, "https://github.com/arduino-libraries/Scheduler.git", repos[8].URL)
require.Equal(t, "https://github.com/arduino-libraries/SD.git", repos[9].URL)
require.Equal(t, "https://github.com/arduino-libraries/Servo.git", repos[10].URL)
require.Error(t, err)

error, ok := err.(GitURLsError)
require.True(t, ok)
require.Equal(t, "https://github.com/arduino-libraries", error.Repos[0].URL)
require.Equal(t, "git@github.com:PaulStoffregen/Audio.git", error.Repos[1].URL)
}

func TestRepoFolderPathDetermination(t *testing.T) {
repo := &Repo{URL: "https://github.com/arduino-libraries/Servo.git"}
f, err := repo.AsFolder()
Expand Down
2 changes: 1 addition & 1 deletion internal/libraries/zip/ziphelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
"os/exec"
"path/filepath"

"arduino.cc/repository/internal/libraries/file"
"github.com/arduino/libraries-repository-engine/internal/libraries/file"
)

// Directory creates a new zip archive that contains a copy of "rootFolder" into "zipFile".
Expand Down
41 changes: 41 additions & 0 deletions libraries/repolist.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// This file is part of libraries-repository-engine.
//
// Copyright 2021 ARDUINO SA (http://www.arduino.cc/)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//
// You can be released from the requirements of the above licenses by purchasing
// a commercial license. Buying such a license is mandatory if you want to
// modify or otherwise use the software for commercial activities involving the
// Arduino software without disclosing the source code of your own applications.
// To purchase a commercial license, send an email to license@arduino.cc.

package libraries

import (
"github.com/arduino/libraries-repository-engine/internal/libraries"
)

// LoadRepoListFromFile returns an unfiltered list of library registry entries loaded from the given data file.
func LoadRepoListFromFile(filename string) ([]*Repo, error) {
return libraries.LoadRepoListFromFile(filename)
}

// Repo is the type for the library repository data.
type Repo = libraries.Repo

// ListRepos returns a filtered list of library registry entries loaded from the given data file.
func ListRepos(reposFilename string) ([]*Repo, error) {
return libraries.ListRepos(reposFilename)
}
135 changes: 135 additions & 0 deletions libraries/repolist_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
// This file is part of libraries-repository-engine.
//
// Copyright 2021 ARDUINO SA (http://www.arduino.cc/)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//
// You can be released from the requirements of the above licenses by purchasing
// a commercial license. Buying such a license is mandatory if you want to
// modify or otherwise use the software for commercial activities involving the
// Arduino software without disclosing the source code of your own applications.
// To purchase a commercial license, send an email to license@arduino.cc.

package libraries

import (
"testing"

"github.com/arduino/libraries-repository-engine/internal/libraries"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestLoadRepoListFromFile(t *testing.T) {
_, err := LoadRepoListFromFile("./testdata/nonexistent.txt")
assert.Error(t, err, "Attempt to load non-existent registry data file")

repos, err := LoadRepoListFromFile("./testdata/git_test_repos.txt")
require.NoError(t, err)

reposAssertion := []*Repo{
{
URL: "https://github.com/arduino-libraries",
Types: []string{"Arduino"},
LibraryName: "libraries",
},
{
URL: "git@github.com:PaulStoffregen/Audio.git",
Types: []string{"Contributed"},
LibraryName: "Audio",
},
{
URL: "https://github.com/PaulStoffregen/OctoWS2811.git",
Types: []string{"Arduino", "Contributed"},
LibraryName: "OctoWS2811",
},
{
URL: "https://github.com/PaulStoffregen/AltSoftSerial.git",
Types: []string{"Contributed"},
LibraryName: "AltSoftSerial",
},
{
URL: "https://github.com/Cheong2K/ble-sdk-arduino.git",
Types: []string{"Contributed"},
LibraryName: "ble-sdk-arduino",
},
{
URL: "https://github.com/arduino-libraries/Bridge.git",
Types: []string{"Contributed"},
LibraryName: "Bridge",
},
{
URL: "https://github.com/adafruit/Adafruit_ADS1X15.git",
Types: []string{"Recommended"},
LibraryName: "Adafruit_ADS1X15",
},
{
URL: "https://github.com/adafruit/Adafruit_ADXL345.git",
Types: []string{"Recommended"},
LibraryName: "Adafruit_ADXL345",
},
{
URL: "https://github.com/adafruit/Adafruit_AHRS.git",
Types: []string{"Recommended"},
LibraryName: "Adafruit_AHRS",
},
{
URL: "https://github.com/adafruit/Adafruit_AM2315.git",
Types: []string{"Recommended"},
LibraryName: "Adafruit_AM2315",
},
{
URL: "https://github.com/arduino-libraries/Scheduler.git",
Types: []string{"Arduino"},
LibraryName: "Scheduler",
},
{
URL: "https://github.com/arduino-libraries/SD.git",
Types: []string{"Arduino"},
LibraryName: "SD",
},
{
URL: "https://github.com/arduino-libraries/Servo.git",
Types: []string{"Arduino"},
LibraryName: "Servo",
},
}

assert.Equal(t, reposAssertion, repos)
}

func TestListRepos(t *testing.T) {
repos, err := ListRepos("./testdata/git_test_repos.txt")

require.Equal(t, 11, len(repos))

require.Equal(t, "https://github.com/PaulStoffregen/OctoWS2811.git", repos[0].URL)
require.Equal(t, "https://github.com/PaulStoffregen/AltSoftSerial.git", repos[1].URL)

require.Equal(t, "https://github.com/Cheong2K/ble-sdk-arduino.git", repos[2].URL)
require.Equal(t, "https://github.com/arduino-libraries/Bridge.git", repos[3].URL)
require.Equal(t, "https://github.com/adafruit/Adafruit_ADS1X15.git", repos[4].URL)
require.Equal(t, "https://github.com/adafruit/Adafruit_ADXL345.git", repos[5].URL)
require.Equal(t, "https://github.com/adafruit/Adafruit_AHRS.git", repos[6].URL)
require.Equal(t, "https://github.com/adafruit/Adafruit_AM2315.git", repos[7].URL)
require.Equal(t, "https://github.com/arduino-libraries/Scheduler.git", repos[8].URL)
require.Equal(t, "https://github.com/arduino-libraries/SD.git", repos[9].URL)
require.Equal(t, "https://github.com/arduino-libraries/Servo.git", repos[10].URL)
require.Error(t, err)

error, ok := err.(libraries.GitURLsError)
require.True(t, ok)
require.Equal(t, "https://github.com/arduino-libraries", error.Repos[0].URL)
require.Equal(t, "git@github.com:PaulStoffregen/Audio.git", error.Repos[1].URL)
}
8 changes: 4 additions & 4 deletions sync_libraries.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ import (
"os"
"path/filepath"

"arduino.cc/repository/internal/libraries"
"arduino.cc/repository/internal/libraries/db"
"arduino.cc/repository/internal/libraries/gitutils"
"arduino.cc/repository/internal/libraries/hash"
cc "github.com/arduino/golang-concurrent-workers"
"github.com/arduino/libraries-repository-engine/internal/libraries"
"github.com/arduino/libraries-repository-engine/internal/libraries/db"
"github.com/arduino/libraries-repository-engine/internal/libraries/gitutils"
"github.com/arduino/libraries-repository-engine/internal/libraries/hash"
"github.com/go-git/go-git/v5/plumbing"
)

Expand Down