Skip to content

Commit

Permalink
[PM-11377] Make Repo top level config object (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
SaintPatrck authored Sep 10, 2024
1 parent dc1c4a0 commit 3ac3386
Show file tree
Hide file tree
Showing 9 changed files with 231 additions and 208 deletions.
5 changes: 4 additions & 1 deletion .cspell.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
{
"$schema": "https://raw.githubusercontent.com/streetsidesoftware/cspell/main/cspell.schema.json",
"version": "0.2",
"words": ["Bitwarden"],
"words": [
"Bitwarden",
"fdroid"
],
"flagWords": [],
"ignorePaths": [
".vscode",
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/fdroid.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,5 +104,6 @@ jobs:
env:
GH_ACCESS_TOKEN: ${{ steps.retrieve-secrets.outputs.github-pat-bitwarden-devops-bot-repo-scope }}
GH_TOKEN: ${{ steps.retrieve-secrets.outputs.github-pat-bitwarden-devops-bot-repo-scope }}
DRY_RUN: ${{ !contains(inputs.dry-run, 'true') }}
run: |
bash update.sh --dry-run ${{ inputs.dry-run }}
17 changes: 0 additions & 17 deletions apps.yaml

This file was deleted.

80 changes: 0 additions & 80 deletions metascoop/apps/apps.go

This file was deleted.

58 changes: 46 additions & 12 deletions metascoop/apps/repo.go
Original file line number Diff line number Diff line change
@@ -1,30 +1,64 @@
package apps

import (
"fmt"
"net/url"
"os"
"strings"

"gopkg.in/yaml.v3"
)

type Repo struct {
Author string
Name string
Host string
type Application struct {
AntiFeatures []string `yaml:"anti_features"`
Categories []string `yaml:"categories"`
Description string `yaml:"description"`
Filename string `yaml:"filename"`
Id string `yaml:"id"`
Name string `yaml:"name"`

ReleaseDescription string
}
type Repo struct {
GitURL string `yaml:"git"`
Summary string `yaml:"summary"`
Applications []Application `yaml:"applications"`

func RepoInfo(repoURL string) (r Repo, err error) {
u, uerr := url.ParseRequestURI(repoURL)
if uerr != nil {
Owner string
Name string
Host string
License string
}
func ParseRepoFile(filepath string) (list []Repo, err error) {
f, err := os.Open(filepath)
if err != nil {
return
}
defer f.Close()

split := strings.Split(strings.Trim(u.Path, "/"), "/")
if len(split) < 2 {
var repos map[string]Repo
err = yaml.NewDecoder(f).Decode(&repos)
if err != nil {
return
}

r.Author = split[0]
r.Name = split[1]
r.Host = strings.TrimPrefix(u.Host, "www.")
for k, r := range repos {
u, uerr := url.ParseRequestURI(r.GitURL)
if uerr != nil {
err = fmt.Errorf("problem with given git URL %q for repo with key=%q, name=%q: %w", r.GitURL, k, r.Name, uerr)
return
}
split := strings.Split(strings.Trim(u.Path, "/"), "/")
if len(split) < 2 {
return
}

r.Owner = split[0]
r.Name = split[1]
r.Host = strings.TrimPrefix(u.Host, "www.")

list = append(list, r)
}

return
}
28 changes: 23 additions & 5 deletions metascoop/apps_test.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,36 @@
package main

import (
"fmt"
"strings"
"testing"

"metascoop/apps"
)

func TestAppsFile(t *testing.T) {
appsList, err := apps.ParseAppFile("../apps.yaml")
func TestRepoFile(t *testing.T) {
reposList, err := apps.ParseRepoFile("../repos.yaml")
if err != nil {
t.Errorf("error parsing apps file: %s", err.Error())
t.Errorf("error parsing repos file: %s", err.Error())
}
if len(reposList) == 0 {
t.Errorf("the repo list is empty, wanted at least one repo")
}
if len(reposList[0].Applications) == 0 {
t.Errorf("the repo app list is empty, wanted at least one app")
}

for _, r := range reposList {
if strings.Contains(r.Name, "Bitwarden") == false {
t.Errorf("the repo name does not contain bitwarden. name=%s", r.Name)
}
fmt.Printf("repo=%q\n", r)

if len(appsList) == 0 {
t.Errorf("the app list is empty, wanted at least one app")
if len(r.Applications) == 0 {
t.Errorf("the repo contains no applications. at least one application is expected")
}
for _, a := range r.Applications {
fmt.Printf("app=%q\n", a)
}
}
}
Loading

0 comments on commit 3ac3386

Please sign in to comment.