0
0
mirror of https://github.com/thegeeklab/wp-gitea-release.git synced 2024-11-24 13:00:40 +00:00

Merge pull request #2 from tboerger/feature/variable-names

Use proper varable names [CI SKIP]
This commit is contained in:
Brad Rydzewski 2015-11-23 14:02:15 -08:00
commit 11a27859e9

52
main.go
View File

@ -23,42 +23,40 @@ type Params struct {
} }
func main() { func main() {
r := drone.Repo{} repo := drone.Repo{}
b := drone.Build{} build := drone.Build{}
w := drone.Workspace{} vargs := Params{}
v := Params{}
plugin.Param("repo", &r) plugin.Param("repo", &repo)
plugin.Param("build", &b) plugin.Param("build", &build)
plugin.Param("workspace", &w) plugin.Param("vargs", &vargs)
plugin.Param("vargs", &v)
plugin.MustParse() plugin.MustParse()
if b.Event != "tag" { if build.Event != "tag" {
fmt.Printf("The GitHub Release plugin is only available for tags\n") fmt.Printf("The GitHub Release plugin is only available for tags\n")
os.Exit(0) os.Exit(0)
return return
} }
if len(v.BaseUrl) == 0 { if len(vargs.BaseUrl) == 0 {
v.BaseUrl = "https://api.github.com/" vargs.BaseUrl = "https://api.github.com/"
} else { } else {
if !strings.HasSuffix(v.BaseUrl, "/") { if !strings.HasSuffix(vargs.BaseUrl, "/") {
v.BaseUrl = v.BaseUrl + "/" vargs.BaseUrl = vargs.BaseUrl + "/"
} }
} }
if len(v.UploadUrl) == 0 { if len(vargs.UploadUrl) == 0 {
v.UploadUrl = "https://uploads.github.com/" vargs.UploadUrl = "https://uploads.github.com/"
} else { } else {
if !strings.HasSuffix(v.UploadUrl, "/") { if !strings.HasSuffix(vargs.UploadUrl, "/") {
v.UploadUrl = v.UploadUrl + "/" vargs.UploadUrl = vargs.UploadUrl + "/"
} }
} }
if len(v.APIKey) == 0 { if len(vargs.APIKey) == 0 {
fmt.Printf("You must provide an API key\n") fmt.Printf("You must provide an API key\n")
os.Exit(1) os.Exit(1)
@ -67,7 +65,7 @@ func main() {
files := make([]string, 0) files := make([]string, 0)
for _, glob := range v.Files { for _, glob := range vargs.Files {
globed, err := filepath.Glob(glob) globed, err := filepath.Glob(glob)
if err != nil { if err != nil {
@ -82,7 +80,7 @@ func main() {
} }
} }
baseUrl, err := url.Parse(v.BaseUrl) baseUrl, err := url.Parse(vargs.BaseUrl)
if err != nil { if err != nil {
fmt.Printf("Failed to parse base URL\n") fmt.Printf("Failed to parse base URL\n")
@ -91,7 +89,7 @@ func main() {
return return
} }
uploadUrl, err := url.Parse(v.UploadUrl) uploadUrl, err := url.Parse(vargs.UploadUrl)
if err != nil { if err != nil {
fmt.Printf("Failed to parse upload URL\n") fmt.Printf("Failed to parse upload URL\n")
@ -102,7 +100,7 @@ func main() {
ts := oauth2.StaticTokenSource( ts := oauth2.StaticTokenSource(
&oauth2.Token{ &oauth2.Token{
AccessToken: v.APIKey, AccessToken: vargs.APIKey,
}) })
tc := oauth2.NewClient( tc := oauth2.NewClient(
@ -115,9 +113,9 @@ func main() {
release, releaseErr := retrieveRelease( release, releaseErr := retrieveRelease(
client, client,
r.Owner, repo.Owner,
r.Name, repo.Name,
filepath.Base(b.Ref)) filepath.Base(build.Ref))
if releaseErr != nil { if releaseErr != nil {
fmt.Println(releaseErr) fmt.Println(releaseErr)
@ -128,8 +126,8 @@ func main() {
uploadErr := appendFiles( uploadErr := appendFiles(
client, client,
r.Owner, repo.Owner,
r.Name, repo.Name,
*release.ID, *release.ID,
files) files)