Skip to content

Commit

Permalink
update feature center list
Browse files Browse the repository at this point in the history
  • Loading branch information
jxr98 committed Aug 30, 2021
1 parent 07260dc commit b50df06
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 14 deletions.
19 changes: 10 additions & 9 deletions app/cmd/center_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package cmd

import (
"encoding/xml"
"io/ioutil"
"net/http"
"strings"

"github.com/jedib0t/go-pretty/v6/table"
"github.com/jenkins-zh/jenkins-cli/app/i18n"
"github.com/jenkins-zh/jenkins-cli/client"
"github.com/spf13/cobra"
"io/ioutil"
"net/http"
"strings"
)

//LtsURL is the URL of stable Jenkins RSS
Expand All @@ -17,9 +18,6 @@ const LtsURL = "https://www.jenkins.io/changelog-stable/rss.xml"
//WidthOfDescription is the width of the description column
const WidthOfDescription = 60

//NumberOfLinesOfDescription is the number of lines to be printed in description column
const NumberOfLinesOfDescription = 10

//ASCIIOfLineFeed is the ASCII of line feed
const ASCIIOfLineFeed = 10

Expand All @@ -46,9 +44,12 @@ type Item struct {
}

var centerListOption CenterListOption
var numberOfLines int

func init() {
centerCmd.AddCommand(centerListCmd)
centerListCmd.Flags().IntVarP(&numberOfLines, "lines", "", 10,
i18n.T("the number of lines to be printed in description column"))
}

var centerListCmd = &cobra.Command{
Expand All @@ -72,7 +73,7 @@ var centerListCmd = &cobra.Command{
return error
}
jenkinsVersion := status.Version
changeLog, err := getChangelog(LtsURL, jenkinsVersion, getVersionData)
changeLog, err := getChangelog(LtsURL, jenkinsVersion, numberOfLines, getVersionData)
cmd.Println(changeLog)
return err
},
Expand All @@ -93,7 +94,7 @@ func getVersionData(rss string) ([]Item, string, error) {
return centerListOption.Channel.Items, centerListOption.Channel.Title, nil
}

func getChangelog(rss string, version string, getData func(rss string) ([]Item, string, error)) (changelog string, err error) {
func getChangelog(rss string, version string, lines int, getData func(rss string) ([]Item, string, error)) (changelog string, err error) {
items, title, error := getData(rss)
if error != nil {
return "", error
Expand All @@ -110,7 +111,7 @@ func getChangelog(rss string, version string, getData func(rss string) ([]Item,
}
isTheLatestVersion = 0
temp = trimXMLSymbols(item.Description)
temp = regulateWidthAndLines(temp, WidthOfDescription, NumberOfLinesOfDescription)
temp = regulateWidthAndLines(temp, WidthOfDescription, lines)
t.AppendRow([]interface{}{index + 1, item.Title, temp, item.PubDate[:17]})
t.AppendSeparator()
}
Expand Down
11 changes: 6 additions & 5 deletions app/cmd/center_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import (
"bytes"
_ "embed"
"encoding/xml"
"io/ioutil"
"net/http"
"os"

"github.com/golang/mock/gomock"
"github.com/jenkins-zh/jenkins-cli/mock/mhttp"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"io/ioutil"
"net/http"
"os"
)

//go:embed center_list.txt
Expand Down Expand Up @@ -50,7 +51,7 @@ var _ = Describe("center list command", func() {
Expect(err).To(BeNil())
err = ioutil.WriteFile(rootOptions.ConfigFile, data, 0664)
Expect(err).To(BeNil())
temp, _ := getChangelog(LtsURL, jenkinsVersions[0][8:], mockGetVersionData)
temp, _ := getChangelog(LtsURL, jenkinsVersions[0][8:], 10, mockGetVersionData)
Expect(temp).To(Equal(result[0]))
})

Expand All @@ -61,7 +62,7 @@ var _ = Describe("center list command", func() {
Expect(err).To(BeNil())
err = ioutil.WriteFile(rootOptions.ConfigFile, data, 0664)
Expect(err).To(BeNil())
temp, _ := getChangelog(LtsURL, jenkinsVersions[1][8:], mockGetVersionData)
temp, _ := getChangelog(LtsURL, jenkinsVersions[1][8:], 10, mockGetVersionData)
Expect(temp).To(Equal(result[1]))
})
})
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ require (
github.com/google/go-github/v29 v29.0.3
github.com/hashicorp/go-version v1.2.1
github.com/hinshun/vt10x v0.0.0-20180616224451-1954e6464174
github.com/jedib0t/go-pretty/v6 v6.2.4
github.com/jenkins-zh/jenkins-client v0.0.1
github.com/jenkins-zh/jenkins-formulas v0.0.5
github.com/linuxsuren/cobra-extension v0.0.10
Expand Down
7 changes: 7 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
github.com/fzipp/gocyclo v0.3.1/go.mod h1:DJHO6AUmbdqj2ET4Z9iArSuwWgYDRryYt2wASxc7x3E=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/gliderlabs/ssh v0.2.2 h1:6zsha5zo/TWhRhwqCD3+EarCAgZ2yN28ipRnGPnwkI0=
github.com/gliderlabs/ssh v0.2.2/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0=
Expand Down Expand Up @@ -261,6 +262,8 @@ github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NH
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A=
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo=
github.com/jedib0t/go-pretty/v6 v6.2.4 h1:wdaj2KHD2W+mz8JgJ/Q6L/T5dB7kyqEFI16eLq7GEmk=
github.com/jedib0t/go-pretty/v6 v6.2.4/go.mod h1:+nE9fyyHGil+PuISTCrp7avEdo6bqoMwqZnuiK2r2a0=
github.com/jenkins-zh/jenkins-cli v0.0.32/go.mod h1:uE1mH9PNITrg0sugv6HXuM/CSddg0zxXoYu3w57I3JY=
github.com/jenkins-zh/jenkins-client v0.0.1 h1:+84X9Ce8sQaYNHIgzsm0a16mb0uYeFOhXM9nDx5dsXk=
github.com/jenkins-zh/jenkins-client v0.0.1/go.mod h1:ICBk7OOoTafVP//f/VfKZ34c0ff8vJwVnOsF9btiMYU=
Expand Down Expand Up @@ -324,6 +327,8 @@ github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNx
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b h1:j7+1HpAFS1zy5+Q4qx1fWh90gTKwiN4QCGoY9TWyyO4=
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
Expand Down Expand Up @@ -372,6 +377,7 @@ github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/profile v1.2.1/go.mod h1:hJw3o1OdXxsrSjjVksARp5W95eeEaEfptyVZyv6JUPA=
github.com/pkg/sftp v1.10.1/go.mod h1:lYOWFsE0bwd1+KfKJaKeuokY15vzFx25BLbzYYoAxZI=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
Expand Down Expand Up @@ -600,6 +606,7 @@ golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180816055513-1c9583448a9c/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
Expand Down

0 comments on commit b50df06

Please sign in to comment.