Skip to content

Commit

Permalink
do some improvements for Travis CI
Browse files Browse the repository at this point in the history
1. update Makefile
2. fix: adjust codes by
    - golint
    - go tool vet
    - gofmt
    - misspell
  • Loading branch information
moooofly committed Jun 12, 2018
1 parent 07ae517 commit 1974b63
Show file tree
Hide file tree
Showing 15 changed files with 79 additions and 66 deletions.
19 changes: 15 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
all: build
all: lint build test

build:
go install ${SRC}
go build -x ./

clean:
go clean -i ${SRC}
install:
go install -x ${SRC}

lint:
gometalinter --exclude=vendor --exclude=repos --disable-all --enable=golint --enable=vet --enable=gofmt ./...
find . -name '*.go' -not -path "./vendor/*" | xargs gofmt -w -s

test:
go test ${SRC}

misspell:
find . -name '*.go' -not -path './vendor/*' -not -path './_repos/*' | xargs misspell -error

clean:
go clean -x -i ${SRC}

2 changes: 1 addition & 1 deletion api/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (x *recentLogs) Execute(args []string) error {
return nil
}

// GetOPLogs
// GetOPLogs ...
//
// e.g. curl -X GET --header 'Accept: application/json' 'https://11.11.11.12/api/logs?username=admin&repository=prj2%2Fphoton&tag=v3&operation=push&begin_timestamp=20171102&page=1&page_size=10'
func GetOPLogs(baseURL string) {
Expand Down
2 changes: 1 addition & 1 deletion api/projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func init() {
"This endpoint is for user to create a new project.",
&prjCreate)
utils.Parser.AddCommand("prj_get",
"Return specific project detail infomation.",
"Return specific project detail information.",
"This endpoint returns specific project information by project ID.",
&prjGet)
utils.Parser.AddCommand("prj_del",
Expand Down
20 changes: 10 additions & 10 deletions api/targets.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (x *targetsPing) Execute(args []string) error {
}

type targetsPingByID struct {
Id int `short:"i" long:"id" description:"(REQUIRED) The replication's target ID." required:"yes"`
ID int `short:"i" long:"id" description:"(REQUIRED) The replication's target ID." required:"yes"`
}

var tpingByID targetsPingByID
Expand All @@ -95,7 +95,7 @@ func (x *targetsPingByID) Execute(args []string) error {
}

type targetsDeleteByID struct {
Id int `short:"i" long:"id" description:"(REQUIRED) The replication's target ID." required:"yes"`
ID int `short:"i" long:"id" description:"(REQUIRED) The replication's target ID." required:"yes"`
}

var tdByID targetsDeleteByID
Expand All @@ -106,7 +106,7 @@ func (x *targetsDeleteByID) Execute(args []string) error {
}

type targetsGetByID struct {
Id int `short:"i" long:"id" description:"(REQUIRED) The replication's target ID." required:"yes"`
ID int `short:"i" long:"id" description:"(REQUIRED) The replication's target ID." required:"yes"`
}

var tgByID targetsGetByID
Expand All @@ -117,7 +117,7 @@ func (x *targetsGetByID) Execute(args []string) error {
}

type targetsUpdateByID struct {
Id int `short:"i" long:"id" description:"(REQUIRED) The replication's target ID." required:"yes" json:"-"`
ID int `short:"i" long:"id" description:"(REQUIRED) The replication's target ID." required:"yes" json:"-"`
EndpointURL string `short:"e" long:"endpoint" description:"(REQUIRED) The target address URL string." required:"yes" json:"endpoint"`
EndpointName string `short:"n" long:"name" description:"(REQUIRED) The target name." required:"yes" json:"name"`
Username string `short:"u" long:"username" description:"(REQUIRED) The target server username." required:"yes" json:"username"`
Expand All @@ -133,7 +133,7 @@ func (x *targetsUpdateByID) Execute(args []string) error {
}

type targetsPoliciesByID struct {
Id int `short:"i" long:"id" description:"(REQUIRED) The replication's target ID." required:"yes"`
ID int `short:"i" long:"id" description:"(REQUIRED) The replication's target ID." required:"yes"`
}

var tpoliciesByID targetsPoliciesByID
Expand Down Expand Up @@ -254,7 +254,7 @@ func PostTargetsPing(baseURL string) {
//
// e.g. curl -X POST --header 'Content-Type: application/json' --header 'Accept: text/plain' 'https://11.11.11.12/api/targets/1/ping'
func PostTargetsPingByID(baseURL string) {
targetURL := baseURL + "/" + strconv.Itoa(tpingByID.Id) + "/ping"
targetURL := baseURL + "/" + strconv.Itoa(tpingByID.ID) + "/ping"
fmt.Println("==> POST", targetURL)

// Read beegosessionID from .cookie.yaml
Expand All @@ -276,7 +276,7 @@ func PostTargetsPingByID(baseURL string) {
//
// e.g. curl -X DELETE --header 'Accept: text/plain' 'https://11.11.11.12/api/targets/2'
func DeleteTargetsByID(baseURL string) {
targetURL := baseURL + "/" + strconv.Itoa(tdByID.Id)
targetURL := baseURL + "/" + strconv.Itoa(tdByID.ID)
fmt.Println("==> DELETE", targetURL)

// Read beegosessionID from .cookie.yaml
Expand All @@ -298,7 +298,7 @@ func DeleteTargetsByID(baseURL string) {
//
// e.g. curl -X GET --header 'Accept: application/json' 'https://11.11.11.12/api/targets/1'
func GetTargetsByID(baseURL string) {
targetURL := baseURL + "/" + strconv.Itoa(tgByID.Id)
targetURL := baseURL + "/" + strconv.Itoa(tgByID.ID)
fmt.Println("==> GET", targetURL)

// Read beegosessionID from .cookie.yaml
Expand Down Expand Up @@ -334,7 +334,7 @@ curl -X PUT --header 'Content-Type: text/plain' --header 'Accept: text/plain' -d
}' 'https://11.11.11.12/api/targets/4'
*/
func UpdateTargetsByID(baseURL string) {
targetURL := baseURL + "/" + strconv.Itoa(tuByID.Id)
targetURL := baseURL + "/" + strconv.Itoa(tuByID.ID)
fmt.Println("==> PUT", targetURL)

// Read beegosessionID from .cookie.yaml
Expand Down Expand Up @@ -365,7 +365,7 @@ func UpdateTargetsByID(baseURL string) {
//
// e.g. curl -X GET --header 'Accept: application/json' 'https://11.11.11.12/api/targets/1/policies/'
func GetPoliciesByID(baseURL string) {
targetURL := baseURL + "/" + strconv.Itoa(tpoliciesByID.Id) + "/policies/"
targetURL := baseURL + "/" + strconv.Itoa(tpoliciesByID.ID) + "/policies/"
fmt.Println("==> GET", targetURL)

// Read beegosessionID from .cookie.yaml
Expand Down
10 changes: 5 additions & 5 deletions utils/heapsort.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@ func (h *minheap) Pop() interface{} {

// Sort on the score of repos
var minh = minheap{}
var mh_bk = minheap{}
var mhBk = minheap{}

func example1() {

h := minheap{
&repoItem{
data: &repoTop{
Id: 31,
ID: 31,
Name: "prj2/photon",
ProjectID: 3,
Description: "",
Expand All @@ -91,7 +91,7 @@ func example1() {
},
&repoItem{
data: &repoTop{
Id: 30,
ID: 30,
Name: "sf3prj/hello-world",
ProjectID: 13,
Description: "",
Expand All @@ -105,7 +105,7 @@ func example1() {
},
&repoItem{
data: &repoTop{
Id: 29,
ID: 29,
Name: "prj5/hello-world",
ProjectID: 6,
Description: "",
Expand All @@ -119,7 +119,7 @@ func example1() {
},
&repoItem{
data: &repoTop{
Id: 4,
ID: 4,
Name: "prj3/hello-world",
ProjectID: 4,
Description: "",
Expand Down
32 changes: 16 additions & 16 deletions utils/retention_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var stats statistics
// ---

type repoTop struct {
Id int `json:"id"`
ID int `json:"id"`
Name string `json:"name"`
ProjectID int `json:"project_id"`
Description string `json:"description"`
Expand Down Expand Up @@ -92,10 +92,10 @@ type reposRetentionPolicy struct {
var reposRP reposRetentionPolicy

func (x *reposRetentionPolicy) Execute(args []string) error {
if err := repo_analyse(); err != nil {
if err := repoAnalyse(); err != nil {
os.Exit(1)
}
if err := repo_erase(); err != nil {
if err := repoErase(); err != nil {
os.Exit(1)
}
rpGCHint()
Expand All @@ -110,13 +110,13 @@ type tagsRetentionPolicy struct {
var tagsRP tagsRetentionPolicy

func (x *tagsRetentionPolicy) Execute(args []string) error {
if err := tag_analyse_and_erase(); err != nil {
if err := tagAnalyseAndErase(); err != nil {
os.Exit(1)
}
return nil
}

func tag_analyse_and_erase() error {
func tagAnalyseAndErase() error {

c, err := CookieLoad()
if err != nil {
Expand Down Expand Up @@ -327,13 +327,13 @@ func grade(r *repoTop, rp *retentionPolicy) float32 {

score := rp.UpdateTime.Base*uf + rp.PullCount.Base*pf + rp.TagsCount.Base*tf
fmt.Printf("[factors] ==> score = UpdateTimeBase*uf + PullCountBase*pf + TagsCountBase*tf = %.2f * %.2f + %.2f * %.2f + %.2f * %.2f = %.2f repo_id: %d\n",
rp.UpdateTime.Base, uf, rp.PullCount.Base, pf, rp.TagsCount.Base, tf, score, r.Id)
rp.UpdateTime.Base, uf, rp.PullCount.Base, pf, rp.TagsCount.Base, tf, score, r.ID)

return score
}

// repo_analyse calculates scores and output topN element by minheap sort
func repo_analyse() error {
// repoAnalyse calculates scores and output topN element by minheap sort
func repoAnalyse() error {

rp, err := rpLoad()
if err != nil {
Expand Down Expand Up @@ -378,7 +378,7 @@ func repo_analyse() error {
}

heap.Init(&minh)
heap.Init(&mh_bk)
heap.Init(&mhBk)
for _, r := range repos {
sc := grade(r, rp)

Expand All @@ -400,21 +400,21 @@ func repo_analyse() error {
score: sc,
}
heap.Push(&minh, it)
heap.Push(&mh_bk, it)
heap.Push(&mhBk, it)
}

fmt.Printf("\n========== 根据分数排名(由低到高)建议删除 public repo 信息如下 ========\n\n")

for mh_bk.Len() > 0 {
it := heap.Pop(&mh_bk).(*repoItem)
for mhBk.Len() > 0 {
it := heap.Pop(&mhBk).(*repoItem)
fmt.Printf("%.2f <==> %+v\n", it.score, *it.data)
}

return nil
}

// repo_erase implements soft deletion
func repo_erase() error {
// repoErase implements soft deletion
func repoErase() error {

var num int
scanner := bufio.NewScanner(os.Stdin)
Expand Down Expand Up @@ -450,7 +450,7 @@ func repo_erase() error {
if num <= 0 || num > 50 {
fmt.Println("[Warning] The valid number range is (0, 50].")
fmt.Println("[Warning] Sorry, you're not allowed proceeding... Abort.")
return fmt.Errorf("error: The number is Out of Range.")
return fmt.Errorf("error: the number is out of range")
}

fmt.Printf("\n=== 开始 soft deletion ===\n\n")
Expand All @@ -476,7 +476,7 @@ func repo_erase() error {
Set("Cookie", "harbor-lang=zh-cn; beegosessionID="+c.BeegosessionID).
End(PrintStatus)
}
num -= 1
num--
}

fmt.Printf("\n=== 完成 soft deletion ===\n\n")
Expand Down
24 changes: 13 additions & 11 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (
yaml "gopkg.in/yaml.v2"
)

var errMalCookies = errors.New("Get Malformed Cookies.")
var errCookiesNotAvailable = errors.New("Target Cookies are Not Available.")
var errMalCookies = errors.New("get malformed cookies")
var errCookiesNotAvailable = errors.New("target cookies are not available")

// Parser is a command registry
var Parser = flags.NewParser(nil, flags.Default)
Expand All @@ -27,7 +27,8 @@ var Request = gorequest.New().TLSClientConfig(&tls.Config{InsecureSkipVerify: tr
var configfile = "./config.yaml"
var secretfile = "./.cookie.yaml"

type beegocookie struct {
// Beegocookie is for beegosessionID storage
type Beegocookie struct {
BeegosessionID string `yaml:"beegosessionID"`
}

Expand All @@ -36,7 +37,8 @@ type generalConfig struct {
Dstip string `yaml:"dstip"`
}

type sysConfig struct {
// SysConfig defines system configurations
type SysConfig struct {
AuthMode string `yaml:"auth_mode" json:"auth_mode"`
EmailFrom string `yaml:"email_from" json:"email_from"`
EmailHost string `yaml:"email_host" json:"email_host"`
Expand All @@ -45,11 +47,11 @@ type sysConfig struct {
EmailUsername string `yaml:"email_username" json:"email_username"`
EmailSsl bool `yaml:"email_ssl" json:"email_ssl"`
EmailInsecure bool `yaml:"email_insecure" json:"email_insecure"`
LdapUrl string `yaml:"ldap_url" json:"ldap_url"`
LdapURL string `yaml:"ldap_url" json:"ldap_url"`
LdapBaseDN string `yaml:"ldap_base_dn" json:"ldap_base_dn"`
LdapFilter string `yaml:"ldap_filter" json:"ldap_filter"`
LdapScope int `yaml:"ldap_scope" json:"ldap_scope"`
LdapUid string `yaml:"ldap_uid" jsonb:"ldap_uid"`
LdapUID string `yaml:"ldap_uid" jsonb:"ldap_uid"`
LdapSearchDN string `yaml:"ldap_search_dn" json:"ldap_search_dn"`
LdapTimeout int `yaml:"ldap_timeout" json:"ldap_timeout"`
ProjectCreationRestriction string `yaml:"project_creation_restriction" json:"project_creation_restriction"`
Expand Down Expand Up @@ -99,7 +101,7 @@ func cookieFilter(cookies []*http.Cookie, filter string) (string, error) {
// .cookie.yaml no matter whether it exists or not.
func cookieSave(beegosessionID string) error {

var cookie beegocookie
var cookie Beegocookie
cookie.BeegosessionID = beegosessionID

c, err := yaml.Marshal(&cookie)
Expand All @@ -116,8 +118,8 @@ func cookieSave(beegosessionID string) error {
}

// CookieLoad loads beegosessionID from .cookie.yaml.
func CookieLoad() (*beegocookie, error) {
var cookie beegocookie
func CookieLoad() (*Beegocookie, error) {
var cookie Beegocookie

dataBytes, err := ioutil.ReadFile(secretfile)
if err != nil {
Expand All @@ -132,8 +134,8 @@ func CookieLoad() (*beegocookie, error) {
}

// SysConfigLoad loads system configuration from config.yaml.
func SysConfigLoad() (*sysConfig, error) {
var config sysConfig
func SysConfigLoad() (*SysConfig, error) {
var config SysConfig

dataBytes, err := ioutil.ReadFile(configfile)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion vendor/github.com/jessevdk/go-flags/completion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 1974b63

Please sign in to comment.