mirror of
https://github.com/thegeeklab/wp-gitea-release.git
synced 2024-11-22 10:10:40 +00:00
Moved struct into separate file, fixed bug for nonexistant releases
This commit is contained in:
parent
a7c989263e
commit
684dcb0137
39
main.go
39
main.go
@ -15,23 +15,23 @@ import (
|
|||||||
"golang.org/x/oauth2"
|
"golang.org/x/oauth2"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Params struct {
|
var (
|
||||||
BaseUrl string `json:"base_url"`
|
build string
|
||||||
UploadUrl string `json:"upload_url"`
|
buildDate string
|
||||||
APIKey string `json:"api_key"`
|
)
|
||||||
Files []string `json:"files"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
fmt.Printf("Drone GitHub Release Plugin built at %s\n", buildDate)
|
||||||
|
|
||||||
workspace := drone.Workspace{}
|
workspace := drone.Workspace{}
|
||||||
repo := drone.Repo{}
|
repo := drone.Repo{}
|
||||||
build := drone.Build{}
|
build := drone.Build{}
|
||||||
vargs := Params{}
|
vargs := Params{}
|
||||||
|
|
||||||
|
plugin.Param("workspace", &workspace)
|
||||||
plugin.Param("repo", &repo)
|
plugin.Param("repo", &repo)
|
||||||
plugin.Param("build", &build)
|
plugin.Param("build", &build)
|
||||||
plugin.Param("vargs", &vargs)
|
plugin.Param("vargs", &vargs)
|
||||||
plugin.Param("workspace", &workspace)
|
|
||||||
plugin.MustParse()
|
plugin.MustParse()
|
||||||
|
|
||||||
if build.Event != "tag" {
|
if build.Event != "tag" {
|
||||||
@ -41,10 +41,6 @@ func main() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(workspace.Path) != 0 {
|
|
||||||
os.Chdir(workspace.Path)
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(vargs.BaseUrl) == 0 {
|
if len(vargs.BaseUrl) == 0 {
|
||||||
vargs.BaseUrl = "https://api.github.com/"
|
vargs.BaseUrl = "https://api.github.com/"
|
||||||
} else {
|
} else {
|
||||||
@ -68,6 +64,10 @@ func main() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(workspace.Path) != 0 {
|
||||||
|
os.Chdir(workspace.Path)
|
||||||
|
}
|
||||||
|
|
||||||
files := make([]string, 0)
|
files := make([]string, 0)
|
||||||
|
|
||||||
for _, glob := range vargs.Files {
|
for _, glob := range vargs.Files {
|
||||||
@ -116,7 +116,7 @@ func main() {
|
|||||||
client.BaseURL = baseUrl
|
client.BaseURL = baseUrl
|
||||||
client.UploadURL = uploadUrl
|
client.UploadURL = uploadUrl
|
||||||
|
|
||||||
release, releaseErr := retrieveRelease(
|
release, releaseErr := prepareRelease(
|
||||||
client,
|
client,
|
||||||
repo.Owner,
|
repo.Owner,
|
||||||
repo.Name,
|
repo.Name,
|
||||||
@ -145,31 +145,24 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func prepareRelease(client *github.Client, owner string, repo string, tag string) (*github.RepositoryRelease, error) {
|
func prepareRelease(client *github.Client, owner string, repo string, tag string) (*github.RepositoryRelease, error) {
|
||||||
var release *github.RepositoryRelease
|
release, _ := retrieveRelease(
|
||||||
var releaseErr error
|
|
||||||
|
|
||||||
release, releaseErr = retrieveRelease(
|
|
||||||
client,
|
client,
|
||||||
owner,
|
owner,
|
||||||
repo,
|
repo,
|
||||||
tag)
|
tag)
|
||||||
|
|
||||||
if releaseErr != nil {
|
|
||||||
return nil, releaseErr
|
|
||||||
}
|
|
||||||
|
|
||||||
if release != nil {
|
if release != nil {
|
||||||
return release, nil
|
return release, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
release, releaseErr = createRelease(
|
release, err := createRelease(
|
||||||
client,
|
client,
|
||||||
owner,
|
owner,
|
||||||
repo,
|
repo,
|
||||||
tag)
|
tag)
|
||||||
|
|
||||||
if releaseErr != nil {
|
if err != nil {
|
||||||
return nil, releaseErr
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if release != nil {
|
if release != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user