Skip to content

Commit

Permalink
Adjust GitHubRepositoryLoader to use WebRepositoryLoader instance
Browse files Browse the repository at this point in the history
  • Loading branch information
Icikowski committed May 3, 2022
1 parent 3c3dfb7 commit db03287
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 18 deletions.
20 changes: 2 additions & 18 deletions application/repos/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import (
"net/http"
"regexp"

"gopkg.in/yaml.v3"
"icikowski.pl/myapps/common"
"icikowski.pl/myapps/types"
)

// GitHubRepositoryLoader loads applications repository from GitHub repository
type GitHubRepositoryLoader struct {
config types.GitHubRepositoryLoaderConfig
target *WebRepositoryLoader
}

// LoadRepository implements RepositoryLoader
Expand Down Expand Up @@ -73,23 +73,7 @@ func (l *GitHubRepositoryLoader) LoadRepository(source string) (types.Repository
}

url := fmt.Sprintf("https://raw.githubusercontent.com/%s/%s/%s/%s", user, repo, branch, filename)
req, _ := http.NewRequest(http.MethodGet, url, nil)

resp, err := http.DefaultClient.Do(req)
if err != nil || resp.StatusCode != http.StatusOK {
if err == nil {
err = fmt.Errorf("got status code %d", resp.StatusCode)
}
common.PrintErrorWhileMsg("loading source", source, err)
return repository, false
}

if err := yaml.NewDecoder(resp.Body).Decode(&repository); err != nil {
common.PrintErrorWhileMsg("parsing source", source, err)
return repository, false
}

return repository, true
return l.target.LoadRepository(url)
}

var _ RepositoryLoader = &GitHubRepositoryLoader{}
1 change: 1 addition & 0 deletions application/repos/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func NewRepositoryProcessor() *RepositoryProcessor {
"https": httpsWebRepositoryIntermediateLoader,
"github": &GitHubRepositoryLoader{
config: config.GetConfiguration().GitHubLoader,
target: webRepositoryLoader,
},
}

Expand Down

0 comments on commit db03287

Please sign in to comment.