mirror of
https://github.com/packwiz/packwiz.git
synced 2025-04-27 08:36:30 +02:00
github: don't return releases on wrong branch
if a branch is specified, but a release cannot be found on that branch, return an error instead of simply the latest release Signed-off-by: unilock <unilock@fennet.rentals>
This commit is contained in:
parent
01945213d7
commit
c96a6a30ad
github
@ -85,15 +85,20 @@ func getLatestRelease(slug string, branch string) (Release, error) {
|
||||
if err != nil {
|
||||
return release, err
|
||||
}
|
||||
|
||||
err = json.Unmarshal(body, &releases)
|
||||
if err != nil {
|
||||
return release, err
|
||||
}
|
||||
|
||||
if branch != "" {
|
||||
for _, r := range releases {
|
||||
if r.TargetCommitish == branch {
|
||||
return r, nil
|
||||
}
|
||||
}
|
||||
return release, fmt.Errorf("failed to find release for branch %v", branch)
|
||||
}
|
||||
|
||||
return releases[0], nil
|
||||
}
|
||||
@ -113,7 +118,7 @@ func installRelease(repo Repo, release Release, pack core.Pack) error {
|
||||
}
|
||||
}
|
||||
|
||||
//Install the file
|
||||
// Install the file
|
||||
fmt.Printf("Installing %s from release %s\n", file.Name, release.TagName)
|
||||
index, err := pack.LoadIndex()
|
||||
if err != nil {
|
||||
@ -125,7 +130,7 @@ func installRelease(repo Repo, release Release, pack core.Pack) error {
|
||||
updateMap["github"], err = ghUpdateData{
|
||||
Slug: repo.FullName,
|
||||
Tag: release.TagName,
|
||||
Branch: release.TargetCommitish,
|
||||
Branch: release.TargetCommitish, // TODO: if no branch is specified by the user, we shouldn't record it - in order to remain branch-agnostic in getLatestRelease()
|
||||
}.ToMap()
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -7,6 +7,7 @@ import (
|
||||
"github.com/packwiz/packwiz/core"
|
||||
)
|
||||
|
||||
// TODO: allow setting github api key via env variable
|
||||
const ghApiServer = "api.github.com"
|
||||
|
||||
type ghApiClient struct {
|
||||
|
Loading…
x
Reference in New Issue
Block a user