generated from bitwarden/template
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PM-11377] Make
Repo
top level config object (#19)
- Loading branch information
1 parent
dc1c4a0
commit 3ac3386
Showing
9 changed files
with
231 additions
and
208 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} | ||
} |
Oops, something went wrong.