mirror of
https://github.com/packwiz/packwiz.git
synced 2025-04-19 13:06: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
@ -85,15 +85,20 @@ func getLatestRelease(slug string, branch string) (Release, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return release, err
|
return release, err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = json.Unmarshal(body, &releases)
|
err = json.Unmarshal(body, &releases)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return release, err
|
return release, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if branch != "" {
|
||||||
for _, r := range releases {
|
for _, r := range releases {
|
||||||
if r.TargetCommitish == branch {
|
if r.TargetCommitish == branch {
|
||||||
return r, nil
|
return r, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return release, fmt.Errorf("failed to find release for branch %v", branch)
|
||||||
|
}
|
||||||
|
|
||||||
return releases[0], nil
|
return releases[0], nil
|
||||||
}
|
}
|
||||||
@ -125,7 +130,7 @@ func installRelease(repo Repo, release Release, pack core.Pack) error {
|
|||||||
updateMap["github"], err = ghUpdateData{
|
updateMap["github"], err = ghUpdateData{
|
||||||
Slug: repo.FullName,
|
Slug: repo.FullName,
|
||||||
Tag: release.TagName,
|
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()
|
}.ToMap()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -7,6 +7,7 @@ import (
|
|||||||
"github.com/packwiz/packwiz/core"
|
"github.com/packwiz/packwiz/core"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// TODO: allow setting github api key via env variable
|
||||||
const ghApiServer = "api.github.com"
|
const ghApiServer = "api.github.com"
|
||||||
|
|
||||||
type ghApiClient struct {
|
type ghApiClient struct {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user