diff --git a/app/cmd/job.go b/app/cmd/job.go index 4012791edb9b041056c42e6374c5e6a81773f5b0..c1dee376432657bad045b5aef19e7f979723a1cb 100644 --- a/app/cmd/job.go +++ b/app/cmd/job.go @@ -1,6 +1,7 @@ package cmd import ( + "github.com/jenkins-zh/jenkins-cli/app/i18n" "github.com/spf13/cobra" ) @@ -18,8 +19,8 @@ func init() { var jobCmd = &cobra.Command{ Use: "job", - Short: "Manage the job of your Jenkins", - Long: `Manage the job of your Jenkins + Short: i18n.T("Manage the job of your Jenkins"), + Long: i18n.T(`Manage the job of your Jenkins Editing the pipeline job needs to install a plugin which is pipeline-restful-api -https://plugins.jenkins.io/pipeline-restful-api`, +https://plugins.jenkins.io/pipeline-restful-api`), } diff --git a/app/cmd/job_artifact_download.go b/app/cmd/job_artifact_download.go index ae924bbe52d0c60861f025ccc66daf15f844249b..e19e265e9a507420fbbd96daad878bb62563f357 100644 --- a/app/cmd/job_artifact_download.go +++ b/app/cmd/job_artifact_download.go @@ -2,6 +2,7 @@ package cmd import ( "fmt" + "github.com/jenkins-zh/jenkins-cli/app/i18n" "net/http" "path/filepath" "strconv" @@ -27,15 +28,18 @@ var jobArtifactDownloadOption JobArtifactDownloadOption func init() { jobArtifactCmd.AddCommand(jobArtifactDownloadCmd) - jobArtifactDownloadCmd.Flags().StringVarP(&jobArtifactDownloadOption.ID, "id", "i", "", "ID of the job artifact") - jobArtifactDownloadCmd.Flags().BoolVarP(&jobArtifactDownloadOption.ShowProgress, "progress", "", true, "Whether show the progress") - jobArtifactDownloadCmd.Flags().StringVarP(&jobArtifactDownloadOption.DownloadDir, "download-dir", "", "", "The directory which artifact will be downloaded") + jobArtifactDownloadCmd.Flags().StringVarP(&jobArtifactDownloadOption.ID, "id", "i", "", + i18n.T("ID of the job artifact")) + jobArtifactDownloadCmd.Flags().BoolVarP(&jobArtifactDownloadOption.ShowProgress, "progress", "", true, + i18n.T("Whether show the progress")) + jobArtifactDownloadCmd.Flags().StringVarP(&jobArtifactDownloadOption.DownloadDir, "download-dir", "", "", + i18n.T("The directory which artifact will be downloaded")) } var jobArtifactDownloadCmd = &cobra.Command{ Use: "download [buildID]", - Short: "Download the artifact of target job", - Long: `Download the artifact of target job`, + Short: i18n.T("Download the artifact of target job"), + Long: i18n.T(`Download the artifact of target job`), Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { argLen := len(args) diff --git a/app/cmd/job_build.go b/app/cmd/job_build.go index 3d233f4130813eb6eb57647789a2211541a0b89b..28b21abd62dac02481aac1fb7e96af867182a6ed 100644 --- a/app/cmd/job_build.go +++ b/app/cmd/job_build.go @@ -3,6 +3,7 @@ package cmd import ( "encoding/json" "fmt" + "github.com/jenkins-zh/jenkins-cli/app/i18n" "log" "net/http" @@ -32,8 +33,8 @@ func init() { var jobBuildCmd = &cobra.Command{ Use: "build ", - Short: "Build the job of your Jenkins", - Long: `Build the job of your Jenkins`, + Short: i18n.T("Build the job of your Jenkins"), + Long: i18n.T("Build the job of your Jenkins"), Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { name := args[0] diff --git a/app/cmd/job_create.go b/app/cmd/job_create.go index 0d7a5b41121228c5da2e03cbb62f8eeda9889b49..f894b3daa1cda157d0474602a9efedaecc07f696 100644 --- a/app/cmd/job_create.go +++ b/app/cmd/job_create.go @@ -1,10 +1,10 @@ package cmd import ( + "github.com/jenkins-zh/jenkins-cli/app/i18n" "net/http" "github.com/AlecAivazis/survey/v2" - "github.com/jenkins-zh/jenkins-cli/app/helper" "github.com/jenkins-zh/jenkins-cli/client" "github.com/spf13/cobra" @@ -28,10 +28,10 @@ func init() { var jobCreateCmd = &cobra.Command{ Use: "create ", - Short: "Create a job in your Jenkins", - Long: `Create a job in your Jenkins`, + Short: i18n.T("Create a job in your Jenkins"), + Long: i18n.T(`Create a job in your Jenkins`), Args: cobra.MinimumNArgs(1), - Run: func(cmd *cobra.Command, args []string) { + RunE: func(cmd *cobra.Command, args []string) (err error) { jobName := args[0] jclient := &client.JobClient{ JenkinsCore: client.JenkinsCore{ @@ -41,7 +41,6 @@ var jobCreateCmd = &cobra.Command{ getCurrentJenkinsAndClient(&(jclient.JenkinsCore)) var createMode string - var err error if createMode, err = jobCreateOption.getCreateMode(jclient); err == nil { payload := client.CreateJobPayload{ Name: jobName, @@ -54,7 +53,7 @@ var jobCreateCmd = &cobra.Command{ } err = jclient.Create(payload) } - helper.CheckErr(cmd, err) + return }, } diff --git a/app/cmd/job_delete.go b/app/cmd/job_delete.go index 79785188cde1e0c1b0b6ae2b5c467fba9bbbb30f..e3515a85b6fb01ef8f5df7044ab65a8599ccdd07 100644 --- a/app/cmd/job_delete.go +++ b/app/cmd/job_delete.go @@ -2,6 +2,7 @@ package cmd import ( "fmt" + "github.com/jenkins-zh/jenkins-cli/app/i18n" "net/http" "github.com/jenkins-zh/jenkins-cli/app/helper" @@ -26,8 +27,8 @@ func init() { var jobDeleteCmd = &cobra.Command{ Use: "delete ", - Short: "Delete a job in your Jenkins", - Long: `Delete a job in your Jenkins`, + Short: i18n.T("Delete a job in your Jenkins"), + Long: i18n.T("Delete a job in your Jenkins"), Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { jobName := args[0] diff --git a/app/cmd/job_edit.go b/app/cmd/job_edit.go index 8dda265b0b21329c270e7dace4c831afe61dab4e..26ebaec49f8a589041abb89d06b228c181f0f495 100644 --- a/app/cmd/job_edit.go +++ b/app/cmd/job_edit.go @@ -1,12 +1,11 @@ package cmd import ( + "github.com/jenkins-zh/jenkins-cli/app/i18n" "io/ioutil" "net/http" "github.com/AlecAivazis/survey/v2" - "github.com/jenkins-zh/jenkins-cli/app/helper" - "github.com/jenkins-zh/jenkins-cli/client" "github.com/spf13/cobra" ) @@ -25,22 +24,21 @@ var jobEditOption JobEditOption func init() { jobCmd.AddCommand(jobEditCmd) jobEditCmd.Flags().StringVarP(&jobEditOption.URL, "url", "", "", - "URL of the Jenkinsfile to files to use to replace pipeline") + i18n.T("URL of the Jenkinsfile to files to use to replace pipeline")) jobEditCmd.Flags().StringVarP(&jobEditOption.Filename, "filename", "f", "", - "Filename to files to use to replace pipeline") + i18n.T("Filename to files to use to replace pipeline")) jobEditCmd.Flags().StringVarP(&jobEditOption.Script, "script", "s", "", - "Script to use to replace pipeline. Use script first if you give filename at the meantime.") + i18n.T("Script to use to replace pipeline. Use script first if you give filename at the meantime.")) } var jobEditCmd = &cobra.Command{ Use: "edit ", - Short: "Edit the job of your Jenkins", - Long: `Edit the job of your Jenkins. We only support to edit the pipeline job.`, + Short: i18n.T("Edit the job of your Jenkins"), + Long: i18n.T(`Edit the job of your Jenkins. We only support to edit the pipeline job.`), Args: cobra.MinimumNArgs(1), - Run: func(cmd *cobra.Command, args []string) { + RunE: func(cmd *cobra.Command, args []string) (err error) { name := args[0] var content string - var err error jclient := &client.JobClient{ JenkinsCore: client.JenkinsCore{ @@ -52,7 +50,7 @@ var jobEditCmd = &cobra.Command{ if content, err = jobEditOption.getPipeline(jclient, name); err == nil { err = jclient.UpdatePipeline(name, content) } - helper.CheckErr(cmd, err) + return }, } diff --git a/app/cmd/job_history.go b/app/cmd/job_history.go index a5d60f6f83cb4756e42746512e59e4b1c70d0ee2..1333b746f28130ec87808c5f1e6390b0e47116ae 100644 --- a/app/cmd/job_history.go +++ b/app/cmd/job_history.go @@ -3,7 +3,7 @@ package cmd import ( "bytes" "fmt" - "github.com/jenkins-zh/jenkins-cli/app/helper" + "github.com/jenkins-zh/jenkins-cli/app/i18n" "github.com/jenkins-zh/jenkins-cli/client" "github.com/jenkins-zh/jenkins-cli/util" "github.com/spf13/cobra" @@ -26,10 +26,10 @@ func init() { var jobHistoryCmd = &cobra.Command{ Use: "history ", - Short: "Print the history of job in your Jenkins", - Long: `Print the history of job in your Jenkins`, + Short: i18n.T("Print the history of job in your Jenkins"), + Long: i18n.T(`Print the history of job in your Jenkins`), Args: cobra.MinimumNArgs(1), - Run: func(cmd *cobra.Command, args []string) { + RunE: func(cmd *cobra.Command, args []string) (err error) { jobName := args[0] jClient := &client.JobClient{ @@ -39,7 +39,8 @@ var jobHistoryCmd = &cobra.Command{ } getCurrentJenkinsAndClient(&(jClient.JenkinsCore)) - builds, err := jClient.GetHistory(jobName) + var builds []*client.JobBuild + builds, err = jClient.GetHistory(jobName) if err == nil { var data []byte data, err = jobHistoryOption.Output(builds) @@ -47,7 +48,7 @@ var jobHistoryCmd = &cobra.Command{ cmd.Print(string(data)) } } - helper.CheckErr(cmd, err) + return }, } diff --git a/app/cmd/job_input.go b/app/cmd/job_input.go index 65128692d5339fc12e1e79f69993bd218873f8ee..d8ea44a4b3e17ca73838c32d7a149010e92f7f72 100644 --- a/app/cmd/job_input.go +++ b/app/cmd/job_input.go @@ -3,6 +3,7 @@ package cmd import ( "encoding/json" "fmt" + "github.com/jenkins-zh/jenkins-cli/app/i18n" "log" "net/http" "strconv" @@ -27,19 +28,16 @@ var jobInputOption JobInputOption func init() { jobCmd.AddCommand(jobInputCmd) - jobInputCmd.Flags().StringVarP(&jobInputOption.Action, "action", "", "", "The action wether you want to process or abort.") + jobInputCmd.Flags().StringVarP(&jobInputOption.Action, "action", "", "", + i18n.T("The action whether you want to process or abort.")) } var jobInputCmd = &cobra.Command{ Use: "input [buildID]", - Short: "Input a job in your Jenkins", - Long: `Input a job in your Jenkins`, + Short: i18n.T("Input a job in your Jenkins"), + Long: i18n.T("Input a job in your Jenkins"), + Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { - if len(args) < 1 { - cmd.Help() - return - } - jobName := args[0] buildID := -1 diff --git a/app/cmd/job_input_test.go b/app/cmd/job_input_test.go index e8130b03eb72eadc4f4bf578119348af29e69bcb..ded9149b4273f6d3d7253da5f25dca1973ef6e08 100644 --- a/app/cmd/job_input_test.go +++ b/app/cmd/job_input_test.go @@ -7,7 +7,6 @@ import ( "github.com/jenkins-zh/jenkins-cli/client" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" - "github.com/spf13/cobra" "io/ioutil" "os" @@ -54,16 +53,12 @@ var _ = Describe("job input command", func() { rootCmd.SetArgs([]string{"job", "input"}) - jobInputCmd.SetHelpFunc(func(cmd *cobra.Command, _ []string) { - cmd.Print("help") - }) - buf := new(bytes.Buffer) rootCmd.SetOutput(buf) _, err = rootCmd.ExecuteC() - Expect(err).To(BeNil()) + Expect(err).To(HaveOccurred()) - Expect(buf.String()).To(Equal("help")) + Expect(buf.String()).To(ContainSubstring("Error: requires at least 1 arg(s)")) }) It("should success, abort without inputs", func() { diff --git a/app/cmd/job_log.go b/app/cmd/job_log.go index 814bd620122dd57d9f23af9d914792e4cc943670..7960af68372c6b89ca01b75142e0d466b27ffe0f 100644 --- a/app/cmd/job_log.go +++ b/app/cmd/job_log.go @@ -1,6 +1,7 @@ package cmd import ( + "github.com/jenkins-zh/jenkins-cli/app/i18n" "net/http" "time" @@ -24,16 +25,19 @@ var jobLogOption JobLogOption func init() { jobCmd.AddCommand(jobLogCmd) - jobLogCmd.Flags().IntVarP(&jobLogOption.History, "history", "s", -1, "Specific build history of log") - jobLogCmd.Flags().BoolVarP(&jobLogOption.Watch, "watch", "w", false, "Watch the job logs") - jobLogCmd.Flags().IntVarP(&jobLogOption.Interval, "interval", "i", 1, "Interval of watch") + jobLogCmd.Flags().IntVarP(&jobLogOption.History, "history", "s", -1, + i18n.T("Specific build history of log")) + jobLogCmd.Flags().BoolVarP(&jobLogOption.Watch, "watch", "w", false, + i18n.T("Watch the job logs")) + jobLogCmd.Flags().IntVarP(&jobLogOption.Interval, "interval", "i", 1, + i18n.T("Interval of watch")) } var jobLogCmd = &cobra.Command{ Use: "log [buildID]", - Short: "Print the job's log of your Jenkins", - Long: `Print the job's log of your Jenkins -It'll print the log text of the last build if you don't give the build id.`, + Short: i18n.T("Print the job's log of your Jenkins"), + Long: i18n.T(`Print the job's log of your Jenkins +It'll print the log text of the last build if you don't give the build id.`), Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { name := args[0] diff --git a/app/cmd/job_param.go b/app/cmd/job_param.go index a653cc8f2523100408acb3254dbe335c7f935893..bf0608c268b5e6283e1683d192ad744c5d0337bc 100644 --- a/app/cmd/job_param.go +++ b/app/cmd/job_param.go @@ -2,6 +2,7 @@ package cmd import ( "encoding/json" + "github.com/jenkins-zh/jenkins-cli/app/i18n" "net/http" "github.com/jenkins-zh/jenkins-cli/app/helper" @@ -29,8 +30,8 @@ func init() { var jobParamCmd = &cobra.Command{ Use: "param ", - Short: "Get parameters of the job of your Jenkins", - Long: `Get parameters of the job of your Jenkins`, + Short: i18n.T("Get parameters of the job of your Jenkins"), + Long: i18n.T("Get parameters of the job of your Jenkins"), Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { name := args[0] diff --git a/app/cmd/job_search.go b/app/cmd/job_search.go index 43b3845c56bb088ae7097d0d84462716013ba26c..c92abc9ab0ddab4b0d02cd186f89c54ddf66a8a0 100644 --- a/app/cmd/job_search.go +++ b/app/cmd/job_search.go @@ -2,6 +2,7 @@ package cmd import ( "fmt" + "github.com/jenkins-zh/jenkins-cli/app/i18n" "net/http" "strings" @@ -24,16 +25,18 @@ var jobSearchOption JobSearchOption func init() { jobCmd.AddCommand(jobSearchCmd) - jobSearchCmd.Flags().IntVarP(&jobSearchOption.Max, "max", "", 10, "The number of limitation to print") - jobSearchCmd.Flags().BoolVarP(&jobSearchOption.PrintAll, "all", "", false, "Print all items if there's no keyword") + jobSearchCmd.Flags().IntVarP(&jobSearchOption.Max, "max", "", 10, + i18n.T("The number of limitation to print")) + jobSearchCmd.Flags().BoolVarP(&jobSearchOption.PrintAll, "all", "", false, + i18n.T("Print all items if there's no keyword")) jobSearchCmd.Flags().StringVarP(&jobSearchOption.Format, "output", "o", "json", - `Formats of the output which contain name, path`) + i18n.T(`Formats of the output which contain name, path`)) } var jobSearchCmd = &cobra.Command{ Use: "search [keyword]", - Short: "Print the job of your Jenkins", - Long: `Print the job of your Jenkins`, + Short: i18n.T("Print the job of your Jenkins"), + Long: i18n.T(`Print the job of your Jenkins`), Run: func(cmd *cobra.Command, args []string) { if !jobSearchOption.PrintAll && len(args) == 0 { cmd.Help() diff --git a/app/cmd/job_stop.go b/app/cmd/job_stop.go index c92ba695be4b1c2398d58f8d1631e2ca272c99e0..e46ecbc1c423e24f7ebdbc867fe8e7f80d5a48ce 100644 --- a/app/cmd/job_stop.go +++ b/app/cmd/job_stop.go @@ -2,13 +2,11 @@ package cmd import ( "fmt" - "net/http" - "strconv" - - "github.com/jenkins-zh/jenkins-cli/app/helper" - + "github.com/jenkins-zh/jenkins-cli/app/i18n" "github.com/jenkins-zh/jenkins-cli/client" "github.com/spf13/cobra" + "net/http" + "strconv" ) // JobStopOption is the job stop option @@ -26,18 +24,16 @@ func init() { } var jobStopCmd = &cobra.Command{ - Use: "stop ", - Short: "Stop a job build in your Jenkins", - Long: `Stop a job build in your Jenkins`, - Args: cobra.MinimumNArgs(2), - Run: func(cmd *cobra.Command, args []string) { - var ( - buildNum int - err error - ) - if buildNum, err = strconv.Atoi(args[1]); err != nil { - cmd.PrintErrln(err) - return + Use: "stop [buildNumber]", + Short: i18n.T("Stop a job build in your Jenkins"), + Long: i18n.T("Stop a job build in your Jenkins"), + Args: cobra.MinimumNArgs(1), + RunE: func(cmd *cobra.Command, args []string) (err error) { + buildNum := -1 + if len(args) > 1 { + if buildNum, err = strconv.Atoi(args[1]); err != nil { + return + } } jobName := args[0] @@ -52,7 +48,6 @@ var jobStopCmd = &cobra.Command{ } getCurrentJenkinsAndClient(&(jclient.JenkinsCore)) - err = jclient.StopJob(jobName, buildNum) - helper.CheckErr(cmd, err) + return jclient.StopJob(jobName, buildNum) }, } diff --git a/app/cmd/job_stop_test.go b/app/cmd/job_stop_test.go index 072a5c41de8134bdb1f39009a2503e7fdf54334a..e674dc15e2757a8f7d2b2a3240bd8984ea51d64d 100644 --- a/app/cmd/job_stop_test.go +++ b/app/cmd/job_stop_test.go @@ -70,7 +70,7 @@ var _ = Describe("job stop command", func() { roundTripper.EXPECT(). RoundTrip(requestCrumb).Return(responseCrumb, nil) - rootCmd.SetArgs([]string{"job", "stop", jobName, "1", "-b", "true"}) + rootCmd.SetArgs([]string{"job", "stop", jobName, "1", "-b"}) buf := new(bytes.Buffer) rootCmd.SetOutput(buf) @@ -79,5 +79,59 @@ var _ = Describe("job stop command", func() { Expect(buf.String()).To(Equal("")) }) + + It("stop the last build, with batch mode", func() { + data, err := generateSampleConfig() + Expect(err).To(BeNil()) + err = ioutil.WriteFile(rootOptions.ConfigFile, data, 0664) + Expect(err).To(BeNil()) + + jobName := "fakeJob" + request, _ := http.NewRequest("POST", fmt.Sprintf("http://localhost:8080/jenkins/job/%s/lastBuild/stop", jobName), nil) + request.Header.Add("CrumbRequestField", "Crumb") + request.SetBasicAuth("admin", "111e3a2f0231198855dceaff96f20540a9") + response := &http.Response{ + StatusCode: 200, + Proto: "HTTP/1.1", + Request: request, + Body: ioutil.NopCloser(bytes.NewBufferString("")), + } + roundTripper.EXPECT(). + RoundTrip(request).Return(response, nil) + + requestCrumb, _ := http.NewRequest("GET", "http://localhost:8080/jenkins/crumbIssuer/api/json", nil) + requestCrumb.SetBasicAuth("admin", "111e3a2f0231198855dceaff96f20540a9") + responseCrumb := &http.Response{ + StatusCode: 200, + Proto: "HTTP/1.1", + Request: requestCrumb, + Body: ioutil.NopCloser(bytes.NewBufferString(` + {"crumbRequestField":"CrumbRequestField","crumb":"Crumb"} + `)), + } + roundTripper.EXPECT(). + RoundTrip(requestCrumb).Return(responseCrumb, nil) + + rootCmd.SetArgs([]string{"job", "stop", jobName, "-b"}) + + buf := new(bytes.Buffer) + rootCmd.SetOutput(buf) + _, err = rootCmd.ExecuteC() + Expect(err).To(BeNil()) + + Expect(buf.String()).To(Equal("")) + }) + + It("stop the last build, with batch mode", func() { + jobName := "fakeJob" + rootCmd.SetArgs([]string{"job", "stop", jobName, "not-number", "-b"}) + + buf := new(bytes.Buffer) + rootCmd.SetOutput(buf) + _, err := rootCmd.ExecuteC() + Expect(err).To(HaveOccurred()) + + Expect(buf.String()).To(ContainSubstring("Error: strconv.Atoi: parsing")) + }) }) }) diff --git a/app/cmd/job_type.go b/app/cmd/job_type.go index a8b15a6b3de33caedc96a792998d7400293f15cd..ed4a3112aa1655b569bc14df6a99488573f87ec9 100644 --- a/app/cmd/job_type.go +++ b/app/cmd/job_type.go @@ -3,6 +3,7 @@ package cmd import ( "bytes" "fmt" + "github.com/jenkins-zh/jenkins-cli/app/i18n" "net/http" "github.com/jenkins-zh/jenkins-cli/app/helper" @@ -28,8 +29,8 @@ func init() { var jobTypeCmd = &cobra.Command{ Use: "type", - Short: "Print the types of job which in your Jenkins", - Long: `Print the types of job which in your Jenkins`, + Short: i18n.T("Print the types of job which in your Jenkins"), + Long: i18n.T("Print the types of job which in your Jenkins"), Run: func(cmd *cobra.Command, _ []string) { jclient := &client.JobClient{ JenkinsCore: client.JenkinsCore{ diff --git a/app/cmd/open.go b/app/cmd/open.go index 2af3d547b2620646721e471dfa5fb422fef444ba..3b8184865c7c3d283cd80136caeaaf043bc1d504 100644 --- a/app/cmd/open.go +++ b/app/cmd/open.go @@ -2,6 +2,7 @@ package cmd import ( "fmt" + "github.com/jenkins-zh/jenkins-cli/app/i18n" "log" "os/exec" "runtime" @@ -22,15 +23,17 @@ var openOption OpenOption func init() { rootCmd.AddCommand(openCmd) - openCmd.Flags().StringVarP(&openOption.Name, "name", "n", "", "Open a specific Jenkins by name") - openCmd.Flags().BoolVarP(&openOption.Config, "config", "c", false, "Open the configuration page of Jenkins") + openCmd.Flags().StringVarP(&openOption.Name, "name", "n", "", + i18n.T("Open a specific Jenkins by name")) + openCmd.Flags().BoolVarP(&openOption.Config, "config", "c", false, + i18n.T("Open the configuration page of Jenkins")) openOption.SetFlag(openCmd) } var openCmd = &cobra.Command{ Use: "open [config name]", - Short: "Open your Jenkins with a browse", - Long: `Open your Jenkins with a browse`, + Short: i18n.T("Open your Jenkins with a browse"), + Long: i18n.T(`Open your Jenkins with a browse`), Example: `jcli open -n `, Run: func(_ *cobra.Command, args []string) { var jenkins *JenkinsServer diff --git a/app/cmd/plugin_check.go b/app/cmd/plugin_check.go index 1365ca70aa5ebe866e13aa4f5caad98037aa01a3..2227db1518ac3f1e1598ce9de18bd47b9b700bff 100644 --- a/app/cmd/plugin_check.go +++ b/app/cmd/plugin_check.go @@ -3,6 +3,7 @@ package cmd import ( "fmt" "github.com/jenkins-zh/jenkins-cli/app/helper" + "github.com/jenkins-zh/jenkins-cli/app/i18n" "io/ioutil" "net/http" @@ -23,8 +24,8 @@ func init() { var pluginCheckCmd = &cobra.Command{ Use: "check", - Short: "Check update center server", - Long: `Check update center server`, + Short: i18n.T("Check update center server"), + Long: i18n.T(`Check update center server`), Run: func(cmd *cobra.Command, _ []string) { jClient := &client.PluginManager{ JenkinsCore: client.JenkinsCore{ diff --git a/app/cmd/plugin_install.go b/app/cmd/plugin_install.go index 6f2a85772b5d071e54ca5e534598a1246a26548e..b946164bdce07bd4ca53f252991eed2c4f793c17 100644 --- a/app/cmd/plugin_install.go +++ b/app/cmd/plugin_install.go @@ -33,8 +33,8 @@ func init() { var pluginInstallCmd = &cobra.Command{ Use: "install [pluginName]", Short: i18n.T("Install the plugins"), - Long: `Install the plugins -Allow you to install a plugin with or without the version`, + Long: i18n.T(`Install the plugins +Allow you to install a plugin with or without the version`), Example: `jcli plugin install localization-zh-cn jcli plugin install localization-zh-cn@1.0.9 `, diff --git a/app/i18n/jcli/zh_CN/LC_MESSAGES/jcli.po b/app/i18n/jcli/zh_CN/LC_MESSAGES/jcli.po index e4a441ab6c23d526060aa45e6bdfea222160ab28..6d157645d6c730602c5596805cefcd6fe92527d1 100644 --- a/app/i18n/jcli/zh_CN/LC_MESSAGES/jcli.po +++ b/app/i18n/jcli/zh_CN/LC_MESSAGES/jcli.po @@ -8,7 +8,7 @@ msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: EMAIL\n" "POT-Creation-Date: 2019-11-21 13:00+0800\n" -"PO-Revision-Date: 2019-11-21 22:17+0800\n" +"PO-Revision-Date: 2019-11-22 23:01+0800\n" "Language-Team: \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" @@ -18,17 +18,45 @@ msgstr "" "Plural-Forms: nplurals=1; plural=0;\n" "Language: zh_CN\n" +#: app/cmd/job_type.go:32 app/cmd/job_type.go:33 +msgid "Print the types of job which in your Jenkins" +msgstr "" + +#: app/cmd/plugin_check.go:27 app/cmd/plugin_check.go:28 +msgid "Check update center server" +msgstr "" + +#: app/cmd/center_download.go:44 +msgid "Download Jenkins from a mirror site. You can get more mirror sites from https://jenkins-zh.cn/tutorial/management/mirror/" +msgstr "" + +#: app/cmd/job.go:22 +msgid "Manage the job of your Jenkins" +msgstr "" + +#: app/cmd/job_artifact_download.go:34 +msgid "Whether show the progress" +msgstr "是否显示进度条" + +#: app/cmd/job_edit.go:29 +msgid "Filename to files to use to replace pipeline" +msgstr "" + +#: app/cmd/plugin_download.go:36 +msgid "Download the plugins" +msgstr "下载插件" + #: app/cmd/restart.go:29 app/cmd/restart.go:30 -msgid "Restart your Jenkins" -msgstr "" +msgid "Restart your Jenkins" +msgstr "重启 Jenkins" #: app/cmd/root.go:79 msgid "Select a Jenkins server for this time" msgstr "选择本次执行的 Jenkins" #: app/cmd/config_add.go:30 -msgid "Proxy of the Jenkins" -msgstr "" +msgid "Proxy of the Jenkins" +msgstr "Jenkins 的代理" #: app/cmd/plugin_upgrade.go:32 app/cmd/plugin_upgrade.go:33 msgid "Upgrade the specific plugin" @@ -39,8 +67,8 @@ msgid "Manage the config of jcli" msgstr "管理 jcli 的配置" #: app/cmd/config_generate.go:28 -msgid "Copy the output into clipboard" -msgstr "拷贝输出到剪贴板" +msgid "Copy the output into clipboard" +msgstr "拷贝输出到剪贴板" #: app/cmd/root.go:77 msgid "An alternative config file" @@ -50,9 +78,25 @@ msgstr "指定另外一个配置文件" msgid "List all Jenkins config items" msgstr "列出所有的 Jenkins 配置项" +#: app/cmd/job_edit.go:31 +msgid "Script to use to replace pipeline. Use script first if you give filename at the meantime." +msgstr "" + +#: app/cmd/job_input.go:37 app/cmd/job_input.go:38 +msgid "Input a job in your Jenkins" +msgstr "" + +#: app/cmd/job_log.go:38 +msgid "Print the job's log of your Jenkins" +msgstr "输出任务的日志" + +#: app/cmd/config_generate.go:34 app/cmd/config_generate.go:35 +msgid "Generate a sample config file for you" +msgstr "为你生成一份样本配置文件" + #: app/cmd/doc.go:30 app/cmd/doc.go:31 -msgid "Generate document for all jcl commands" -msgstr "为所有的 jcli 命令生成文档" +msgid "Generate document for all jcl commands" +msgstr "为所有的 jcli 命令生成文档" #: app/cmd/root.go:37 msgid "jcli is a tool which could help you with your multiple Jenkins" @@ -75,8 +119,8 @@ msgid "Print the version of Jenkins CLI" msgstr "打印 Jenkins CLI 的版本" #: app/cmd/completion.go:14 app/cmd/completion.go:15 -msgid "Genereate bash completion scripts" -msgstr "生成 bash 自动补全的脚本" +msgid "Genereate bash completion scripts" +msgstr "生成 bash 自动补全的脚本" #: app/cmd/plugin_download.go:31 app/cmd/plugin_install.go:29 msgid "If you want to show the progress of download a plugin" @@ -84,7 +128,7 @@ msgstr "你是否希望显示插件下载的进度" #: app/cmd/plugin_download.go:37 msgid "Download the plugins which contain the target plugin and its dependencies" -msgstr "" +msgstr "下载插件及其依赖" #: app/cmd/plugin_uninstall.go:26 app/cmd/plugin_uninstall.go:27 msgid "Uninstall the plugins" @@ -99,44 +143,32 @@ msgid "Whether skip the post command hook" msgstr "是否跳过后置命令钩子" #: app/cmd/center_download.go:32 -msgid "Version of the Jenkins which you want to download" -msgstr "" +msgid "Version of the Jenkins which you want to download" +msgstr "你希望下载的 Jenkins 版本" #: app/cmd/config_add.go:22 -msgid "Name of the Jenkins" -msgstr "" - -#: app/cmd/config_list.go:28 app/cmd/config_list.go:29 -msgid "List all Jenkins config items" -msgstr "" - -#: app/cmd/config_generate.go:34 app/cmd/config_generate.go:35 -msgid "Generate a sample config file for you" -msgstr "" +msgid "Name of the Jenkins" +msgstr "Jenkins 的名称" #: app/cmd/config_add.go:28 -msgid "Token of the Jenkins" -msgstr "" +msgid "Token of the Jenkins" +msgstr "Jenkins 的令牌" #: app/cmd/config_add.go:32 -msgid "ProxyAuth of the Jenkins" -msgstr "" - -#: app/cmd/root.go:36 -msgid "jcli is a tool which could help you with your multiple Jenkins" -msgstr "" +msgid "ProxyAuth of the Jenkins" +msgstr "" #: app/cmd/center_watch.go:27 -msgid "The watch will be continue util Jenkins needs restart" -msgstr "" +msgid "The watch will be continue util Jenkins needs restart" +msgstr "" #: app/cmd/config_add.go:26 -msgid "UserName of the Jenkins" -msgstr "" +msgid "UserName of the Jenkins" +msgstr "Jenkins 的用户名" #: app/cmd/config_edit.go:21 app/cmd/config_edit.go:22 -msgid "Edit a Jenkins config" -msgstr "" +msgid "Edit a Jenkins config" +msgstr "编辑 Jenkins 配置" #: app/cmd/plugin_download.go:25 msgid "If you want to skip download dependency of plugin" @@ -144,7 +176,7 @@ msgstr "你是否想要跳过下载依赖插件" #: app/cmd/plugin_upload.go:45 msgid "Password of remote plugin URL" -msgstr "" +msgstr "远程插件的秘密" #: app/cmd/plugin_upload.go:58 msgid "Upload a plugin to your Jenkins" @@ -156,15 +188,15 @@ msgstr "管理你的 Jenkins 更新中心" #: app/cmd/job_artifact.go:33 app/cmd/job_artifact.go:34 msgid "Print the artifact list of target job" -msgstr "" +msgstr "输出目标任务的归档文件列表" -#: app/cmd/plugin_download.go:27 -msgid "If you want to skip download optional dependency of plugin" -msgstr "" +#: app/cmd/job_search.go:29 +msgid "The number of limitation to print" +msgstr "输出的数量限制" -#: app/cmd/plugin_download.go:36 -msgid "Download the plugins" -msgstr "下载插件" +#: app/cmd/open.go:29 +msgid "Open the configuration page of Jenkins" +msgstr "" #: app/cmd/plugin_install.go:35 msgid "Install the plugins" @@ -188,52 +220,20 @@ msgstr "你是否想要从镜像站点下载插件" #: app/cmd/plugin_list.go:35 app/cmd/plugin_list.go:36 msgid "Print all the plugins which are installed" -msgstr "" +msgstr "输出已经安装的插件" #: app/cmd/center_watch.go:29 -msgid "The watch will be continue util all Jenkins plugins installation is completed" -msgstr "" +msgid "The watch will be continue util all Jenkins plugins installation is completed" +msgstr "" #: app/cmd/common.go:101 app/cmd/config_generate.go:26 -msgid "Interactive mode" -msgstr "" - -#: app/cmd/plugin_download.go:29 app/cmd/plugin_install.go:27 -msgid "If you want to download plugin from a mirror site" -msgstr "" +msgid "Interactive mode" +msgstr "交互模式" #: app/cmd/plugin_upload.go:43 msgid "User of remote plugin URL" msgstr "" -#: app/cmd/plugin_upload.go:47 -msgid "Remote Jenkins which will find from config list" -msgstr "" - -#: app/cmd/plugin_upload.go:58 -msgid "Upload a plugin to your Jenkins" -msgstr "" - -#: app/cmd/root.go:76 -msgid "An alternative config file" -msgstr "" - -#: app/cmd/center.go:31 app/cmd/center.go:32 -msgid "Manage your update center" -msgstr "" - -#: app/cmd/center_download.go:36 -msgid "If you want to show the download progress" -msgstr "" - -#: app/cmd/completion.go:14 app/cmd/completion.go:15 -msgid "Genereate bash completion scripts" -msgstr "" - -#: app/cmd/config.go:32 app/cmd/config.go:33 -msgid "Manage the config of jcli" -msgstr "管理 jcli 的配置信息" - #: app/cmd/plugin_upload.go:59 msgid "Upload a plugin from local filesystem or remote URL to your Jenkins" msgstr "上传来自本地文件系统或者远程 URL 的插件到你的 Jenkins" diff --git a/client/job.go b/client/job.go index 748427ef3777f2ebb2fd7b6ed55e4e2e6bdbe7a2..b71f787c7e8404360ae704c73b7187e6d06af42a 100644 --- a/client/job.go +++ b/client/job.go @@ -69,7 +69,13 @@ func (q *JobClient) BuildWithParams(jobName string, parameters []ParameterDefini // StopJob stops a job build func (q *JobClient) StopJob(jobName string, num int) (err error) { path := ParseJobPath(jobName) - api := fmt.Sprintf("%s/%d/stop", path, num) + + var api string + if num <= 0 { + api = fmt.Sprintf("%s/lastBuild/stop", path) + } else { + api = fmt.Sprintf("%s/%d/stop", path, num) + } _, err = q.RequestWithoutData("POST", api, nil, nil, 200) return diff --git a/client/job_test.go b/client/job_test.go index 452d89d1b2e3f78ba56dcd856d8210c93571e604..2c24717eaae3f4bc5d8c4b71fbb565296d58eeab 100644 --- a/client/job_test.go +++ b/client/job_test.go @@ -219,6 +219,36 @@ var _ = Describe("job test", func() { err := jobClient.StopJob(jobName, buildID) Expect(err).To(BeNil()) }) + + It("stop the last job build without a folder", func() { + jobName := "fakeJob" + buildID := -1 + request, _ := http.NewRequest("POST", fmt.Sprintf("%s/job/%s/lastBuild/stop", jobClient.URL, jobName), nil) + request.Header.Add("CrumbRequestField", "Crumb") + response := &http.Response{ + StatusCode: 200, + Proto: "HTTP/1.1", + Request: request, + Body: ioutil.NopCloser(bytes.NewBufferString("")), + } + roundTripper.EXPECT(). + RoundTrip(request).Return(response, nil) + + requestCrumb, _ := http.NewRequest("GET", fmt.Sprintf("%s%s", jobClient.URL, "/crumbIssuer/api/json"), nil) + responseCrumb := &http.Response{ + StatusCode: 200, + Proto: "HTTP/1.1", + Request: requestCrumb, + Body: ioutil.NopCloser(bytes.NewBufferString(` + {"crumbRequestField":"CrumbRequestField","crumb":"Crumb"} + `)), + } + roundTripper.EXPECT(). + RoundTrip(requestCrumb).Return(responseCrumb, nil) + + err := jobClient.StopJob(jobName, buildID) + Expect(err).To(BeNil()) + }) }) Context("GetJob", func() {