aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Daudt <kdaudt@alpinelinux.org>2021-04-27 21:58:37 +0200
committerKevin Daudt <kdaudt@alpinelinux.org>2021-04-27 21:58:37 +0200
commit1ef65438529927cde2f83afb09d484ce196818fc (patch)
tree1d189d0b2140d27e24b25004c7d9b488face8e47
parentbfee82ca3b3ef0cda0cdff3982667892ef78d022 (diff)
parent1b3a13c74f642ada12eec8d8e82ee207c53d255a (diff)
downloadgo-1ef65438529927cde2f83afb09d484ce196818fc.tar.gz
go-1ef65438529927cde2f83afb09d484ce196818fc.tar.bz2
go-1ef65438529927cde2f83afb09d484ce196818fc.tar.xz
merge: improve releases packagev0.2.1
-rw-r--r--README.md64
-rw-r--r--pkg/releases/releases.go38
-rw-r--r--pkg/releases/releases_test.go37
-rw-r--r--pkg/releases/testdata/releases.json28
4 files changed, 122 insertions, 45 deletions
diff --git a/README.md b/README.md
index cf5be0f..51d9a11 100644
--- a/README.md
+++ b/README.md
@@ -1,56 +1,50 @@
# Alpine Go
-Golang packages to interact with:
+These are a set of packages that help with interacting with various Alpine Linux
+related systems. These things include:
+* APKBUILD files
* APKINDEX files
-* apk packages
-* APKBUILD / aports
+* releas.json
## Packages
-### package apkindex
-
-#### `type Package`
-
-``` go
-type Package struct {
- Name string
- Version string
- Arch string
- Description string
- License string
- Origin string
- Maintainer string
- Checksum []byte
- Dependencies []string
- Provides []string
-}
-```
+In-depth documentation for this package can be found on [pkg.go.dev][go-dev]
-#### `type ApkIndex`
+### apkbuild
-``` go
-type ApkIndex struct {
- Signature []byte
- Description string
- Packages []*Package
-}
+```go
+import "gitlab.alpinelinux.org/alpine/go/pkg/apkbuild"
```
-#### `func ParsePackageIndex(apkIndexUnpacked io.ReadCloser) (packages []*Package, err error)`
+Currently only parses secfixes in APKBUILD files.
+
+### apkindex
+
+```go
+import "gitlab.alpinelinux.org/alpine/go/pkg/apkindex"
+```
-ParsePackageIndex parses an APKINDEX archive, provided as raw compressed bytes.
+Parses APKINDEX files an provides information about all packages in the index.
-#### `func IndexFromArchive(archive io.ReadCloser) (apkindex *ApkIndex, err error)`
+### releases
-IndexFromArchive parses a plain-text APKINDEX file from an APKINDEX archive.
+```go
+import "gitlab.alpinelinux.org/alpine/go/pkg/releases"
+```
-## package apkbuild
+Provides functions and structures to get information about Alpine Linux releases.
-### `type Secfixes map[string][]string`
+```go
+rels, err := releases.Fetch()
-func ParseSecfixes(apkbuild io.ReadCloser) (secfixes Secfixes, err error) {
+for _, releaseBranch := range rels.ReleaseBranches {
+ fmt.Printf("Release %s eol: %s\n", releaseBranch.RelBranch, releaseBranch.EolDate)
+}
+```
## License
MIT
+
+[go-dev]:https://pkg.go.dev/gitlab.alpinelinux.org/alpine/go
diff --git a/pkg/releases/releases.go b/pkg/releases/releases.go
index 2576a4c..065a5b0 100644
--- a/pkg/releases/releases.go
+++ b/pkg/releases/releases.go
@@ -1,5 +1,14 @@
package releases
+// Package releases provides functions and structures to parse information about
+// Alpine Linux releases, which is published at https://alpinelinux.org/releases.json.
+//
+// releases, err := NewFromURL("https://alpinelinux.org/releases.json.")
+// if err != nil {
+// // Handle error
+// }
+// fmt.Println(releases.GetRelBranch("v3.13").EolDate)
+
import (
"encoding/json"
"io"
@@ -7,8 +16,6 @@ import (
)
type (
- // Releases
-
Repo struct {
Name string `json:"name"`
EOLDate string `json:"eol_date,omitempty"`
@@ -36,26 +43,37 @@ type (
}
)
-// Fetch downloads and parses the Alpine Linux releases published at
-// https://alpinelinux.org/releases.json
-func Fetch() (releases *Releases, err error) {
- resp, err := http.Get("https://alpinelinux.org/releases.json")
+// NewFromBuffer parses releases.json from a buffer and returns a Releases
+// object if the data could be sucessfully parsed
+func NewFromBuffer(buffer []byte) (releases *Releases, err error) {
+ releases = &Releases{}
+ err = json.Unmarshal(buffer, releases)
+ return
+}
+
+// NewFromURL can be used to parse releases.json directly from a url
+func NewFromURL(url string) (releases *Releases, err error) {
+ resp, err := http.Get(url)
if err != nil {
- return
+ return nil, err
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
-
if err != nil {
return
}
- releases = &Releases{}
- err = json.Unmarshal(body, releases)
+ releases, err = NewFromBuffer(body)
+ return
+}
+// Fetch downloads and parses the Alpine Linux releases published at
+// https://alpinelinux.org/releases.json
+func Fetch() (releases *Releases, err error) {
+ releases, err = NewFromURL("https://alpinelinux.org/releases.json")
return
}
diff --git a/pkg/releases/releases_test.go b/pkg/releases/releases_test.go
new file mode 100644
index 0000000..15e3614
--- /dev/null
+++ b/pkg/releases/releases_test.go
@@ -0,0 +1,37 @@
+package releases
+
+import (
+ "io"
+ "os"
+ "testing"
+
+ "github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
+)
+
+func TestNewFromBuffer(t *testing.T) {
+ assert := assert.New(t)
+ require := require.New(t)
+
+ file, err := os.Open("testdata/releases.json")
+ require.Nil(err)
+
+ buffer, err := io.ReadAll(file)
+ require.Nil(err)
+
+ releases, err := NewFromBuffer(buffer)
+ require.Nil(err)
+
+ assert.Len(releases.Architectures, 2)
+ require.Len(releases.ReleaseBranches, 2)
+
+ firstBranch := releases.ReleaseBranches[0]
+ assert.Equal("edge", firstBranch.RelBranch)
+ assert.Equal("master", firstBranch.GitBranch)
+ assert.Len(firstBranch.Repos, 3)
+
+ secondBranch := releases.ReleaseBranches[1]
+ assert.Equal("v3.13", secondBranch.RelBranch)
+ assert.Equal("3.13-stable", secondBranch.GitBranch)
+ assert.Equal("2022-11-01", secondBranch.Repos[1].EOLDate)
+}
diff --git a/pkg/releases/testdata/releases.json b/pkg/releases/testdata/releases.json
new file mode 100644
index 0000000..a1124c2
--- /dev/null
+++ b/pkg/releases/testdata/releases.json
@@ -0,0 +1,28 @@
+{
+ "architectures": ["x86_64", "aarch64"],
+ "release_branches": [{
+ "rel_branch": "edge",
+ "arches": ["x86_64", "aarch64"],
+ "git_branch": "master",
+ "repos": [
+ {"name": "main"},
+ {"name": "community"},
+ {"name": "testing"}
+ ]
+ },{
+ "rel_branch": "v3.13",
+ "arches": ["x86_64", "aarch64"],
+ "git_branch": "3.13-stable",
+ "repos": [
+ {"name": "main"},
+ {"name": "community", "eol_date": "2022-11-01"}
+ ],
+ "releases": [{
+ "notes": "posts/Alpine-3.13.0-released.md",
+ "version": "3.13.0",
+ "date": "2021-01-14"
+ }],
+ "branch_date": "2021-01-14",
+ "eol_date": "2022-11-01"
+ }]
+}