generated from ViBiOh/goweb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes None Signed-off-by: Vincent Boutour <[email protected]>
- Loading branch information
Showing
14 changed files
with
123 additions
and
37 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 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 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 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package pypi | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/ViBiOh/httputils/v4/pkg/httpjson" | ||
"github.com/ViBiOh/httputils/v4/pkg/request" | ||
"github.com/ViBiOh/ketchup/pkg/model" | ||
"github.com/ViBiOh/ketchup/pkg/semver" | ||
) | ||
|
||
const ( | ||
registryURL = "https://pypi.org/pypi" | ||
) | ||
|
||
type packageResp struct { | ||
Versions map[string]interface{} `json:"releases"` | ||
} | ||
|
||
// App of package | ||
type App interface { | ||
LatestVersions(string, []string) (map[string]semver.Version, error) | ||
} | ||
|
||
type app struct{} | ||
|
||
// New creates new App from Config | ||
func New() App { | ||
return app{} | ||
} | ||
|
||
func (a app) LatestVersions(name string, patterns []string) (map[string]semver.Version, error) { | ||
ctx := context.Background() | ||
|
||
versions, compiledPatterns, err := model.PreparePatternMatching(patterns) | ||
if err != nil { | ||
return nil, fmt.Errorf("unable to prepare pattern matching: %s", err) | ||
} | ||
|
||
resp, err := request.New().Get(fmt.Sprintf("%s/%s/json", registryURL, name)).Send(ctx, nil) | ||
if err != nil { | ||
return nil, fmt.Errorf("unable to fetch registry: %s", err) | ||
} | ||
|
||
var content packageResp | ||
if err := httpjson.Read(resp, &content); err != nil { | ||
return nil, fmt.Errorf("unable to read versions: %s", err) | ||
} | ||
|
||
for version := range content.Versions { | ||
tagVersion, err := semver.Parse(version) | ||
if err != nil { | ||
continue | ||
} | ||
|
||
model.CheckPatternsMatching(versions, compiledPatterns, tagVersion) | ||
} | ||
|
||
return versions, nil | ||
} |
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
Oops, something went wrong.