mirror of
https://github.com/appleboy/drone-jenkins.git
synced 2026-06-04 18:23:57 +08:00
feat: add context-aware HTTP POST and improve CLI help formatting
- Add context support to HTTP POST requests for improved cancellation and timeout handling - Fix formatting of usage and commands help text in the CLI output Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
+3
-1
@@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
@@ -34,6 +35,7 @@ func NewJenkins(auth *Auth, url string, insecure bool) *Jenkins {
|
|||||||
if insecure {
|
if insecure {
|
||||||
client = &http.Client{
|
client = &http.Client{
|
||||||
Transport: &http.Transport{
|
Transport: &http.Transport{
|
||||||
|
// #nosec G402 -- InsecureSkipVerify is intentionally configurable by user
|
||||||
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -82,7 +84,7 @@ func (jenkins *Jenkins) parseResponse(resp *http.Response, body interface{}) (er
|
|||||||
|
|
||||||
func (jenkins *Jenkins) post(path string, params url.Values, body interface{}) (err error) {
|
func (jenkins *Jenkins) post(path string, params url.Values, body interface{}) (err error) {
|
||||||
requestURL := jenkins.buildURL(path, params)
|
requestURL := jenkins.buildURL(path, params)
|
||||||
req, err := http.NewRequest("POST", requestURL, nil)
|
req, err := http.NewRequestWithContext(context.Background(), "POST", requestURL, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -79,13 +79,15 @@ NAME:
|
|||||||
{{.Name}} - {{.Usage}}
|
{{.Name}} - {{.Usage}}
|
||||||
|
|
||||||
USAGE:
|
USAGE:
|
||||||
{{.HelpName}} {{if .VisibleFlags}}[global options]{{end}}{{if .Commands}} command [command options]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}[arguments...]{{end}}
|
{{.HelpName}} {{if .VisibleFlags}}[global options]{{end}}{{if .Commands}} command [command options]{{end}} ` +
|
||||||
|
`{{if .ArgsUsage}}{{.ArgsUsage}}{{else}}[arguments...]{{end}}
|
||||||
{{if len .Authors}}
|
{{if len .Authors}}
|
||||||
AUTHOR:
|
AUTHOR:
|
||||||
{{range .Authors}}{{ . }}{{end}}
|
{{range .Authors}}{{ . }}{{end}}
|
||||||
{{end}}{{if .Commands}}
|
{{end}}{{if .Commands}}
|
||||||
COMMANDS:
|
COMMANDS:
|
||||||
{{range .Commands}}{{if not .HideHelp}} {{join .Names ", "}}{{ "\t"}}{{.Usage}}{{ "\n" }}{{end}}{{end}}{{end}}{{if .VisibleFlags}}
|
{{range .Commands}}{{if not .HideHelp}} {{join .Names ", "}}{{ "\t"}}{{.Usage}}{{ "\n" }}{{end}}{{end}}{{end}}` +
|
||||||
|
`{{if .VisibleFlags}}
|
||||||
GLOBAL OPTIONS:
|
GLOBAL OPTIONS:
|
||||||
{{range .VisibleFlags}}{{.}}
|
{{range .VisibleFlags}}{{.}}
|
||||||
{{end}}{{end}}{{if .Copyright }}
|
{{end}}{{end}}{{if .Copyright }}
|
||||||
|
|||||||
Reference in New Issue
Block a user