From 69f351fe1a91268c5d346392c574b48a73ee7482 Mon Sep 17 00:00:00 2001 From: Mohit Sharma Date: Mon, 16 Oct 2023 12:59:27 +0530 Subject: [PATCH] resolving review comments --- .gitignore | 1 - cmd/update-rules/README.md | 8 ++++---- cmd/update-rules/main.go | 26 +++++++++++++------------- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/.gitignore b/.gitignore index 2f384e4a..6062941e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ _output /coverage.out -.idea/* \ No newline at end of file diff --git a/cmd/update-rules/README.md b/cmd/update-rules/README.md index 99ed908a..470ce55d 100644 --- a/cmd/update-rules/README.md +++ b/cmd/update-rules/README.md @@ -63,7 +63,7 @@ Run the command line as: update-rules -branch release-1.24 -go 1.17.1 -o /tmp/rules.yaml -rules /go/src/k8s.io/kubernetes/staging/publishing/rules.yaml # Remove rules and export to /tmp/rules.yaml - update-rules -branch release-1.24 -remove true -o /tmp/rules.yaml -rules /go/src/k8s.io/kubernetes/staging/publishing/rules.yaml + update-rules -branch release-1.24 -delete -o /tmp/rules.yaml -rules /go/src/k8s.io/kubernetes/staging/publishing/rules.yaml -alsologtostderr log to standard error as well as files @@ -79,8 +79,8 @@ Run the command line as: log to standard error instead of files -o string Path to export the updated rules to, e.g. -o /tmp/rules.yaml - -remove - Remove old rules to deprecated branch + -delete + Remove old rules of deprecated branch -rules string [required] URL or Path of the rules file to update rules for, e.g. --rules path/or/url/to/rules/file.yaml -stderrthreshold value @@ -99,5 +99,5 @@ Run the command line as: #### Optional flags: - `-go` flag refers to golang version which should be pinned for given branch, if not given an empty string is set -- `-remove` flag refers to removing the branch from rules, defaults to false +- `-delete` flag refers to removing the branch from rules, if not set defaults to false - `-o` flag refers to output file where the processed rules should be exported, otherwise rules are printed on stdout diff --git a/cmd/update-rules/main.go b/cmd/update-rules/main.go index c8eac708..08b1a381 100644 --- a/cmd/update-rules/main.go +++ b/cmd/update-rules/main.go @@ -32,7 +32,7 @@ const GitDefaultBranch = "master" type options struct { branch string - remove bool + delete bool rulesFile string goVersion string out string @@ -42,7 +42,7 @@ func parseOptions() options { var o options flag.StringVar(&o.branch, "branch", "", "[required] Branch to update rules for, e.g. --branch release-x.yy") flag.StringVar(&o.rulesFile, "rules", "", "[required] URL or Path of the rules file to update rules for, e.g. --rules path/or/url/to/rules/file.yaml") - flag.BoolVar(&o.remove, "remove", false, "Remove old rules to deprecated branch") + flag.BoolVar(&o.delete, "delete", false, "Remove old rules to deprecated branch") flag.StringVar(&o.goVersion, "go", "", "Golang version to pin for this branch, e.g. --go 1.16.1") flag.StringVar(&o.out, "o", "", "Path to export the updated rules to, e.g. -o /tmp/rules.yaml") @@ -58,10 +58,10 @@ func parseOptions() options { update-rules -branch release-1.22 -go 1.17.1 -o /tmp/rules.yaml -rules /go/src/k8s.io/kubernetes/staging/publishing/rules.yaml # Update rules to remove deprecated branch and export to /tmp/rules.yaml - update-rules -branch release-1.22 -remove true -o /tmp/rules.yaml -rules /go/src/k8s.io/kubernetes/staging/publishing/rules.yaml` + update-rules -branch release-1.22 -delete -o /tmp/rules.yaml -rules /go/src/k8s.io/kubernetes/staging/publishing/rules.yaml` flag.Usage = func() { - fmt.Fprintf(os.Stdout, "\n Usage: update-rules --branch BRANCH --rules PATHorURL [--go VERSION | -o PATH | -remove true/false]") + fmt.Fprintf(os.Stdout, "\n Usage: update-rules --branch BRANCH --rules PATHorURL [--go VERSION | -o PATH | --delete ]") fmt.Fprintf(os.Stdout, "\n %s\n\n", examples) flag.PrintDefaults() } @@ -91,7 +91,7 @@ func main() { } // update rules for all destination repos - UpdateRules(rules, o.branch, o.goVersion, o.remove) + UpdateRules(rules, o.branch, o.goVersion, o.delete) // validate rules after update if err := config.Validate(rules); err != nil { glog.Fatalf("update failed, found invalid rules after update: %v", err) @@ -160,14 +160,14 @@ func UpdateRules(rules *config.RepositoryRules, branch, goVer string, removeRule break } } - for i, br := range r.Branches { - if removeRules && br.Name == branch { - glog.Infof("Will remove rule for %s %s", branch, r.DestinationRepository) - r.Branches = append(r.Branches[:i], r.Branches[i+1:]...) - branchRuleExists = true - break - } - } + // for i, br := range r.Branches { + // if removeRules && br.Name == branch { + // glog.Infof("Will remove rule for %s %s", branch, r.DestinationRepository) + // r.Branches = append(r.Branches[:i], r.Branches[i+1:]...) + // branchRuleExists = true + // break + // } + // } // new rules, append to destination's branches if !branchRuleExists { r.Branches = append(r.Branches, newBranchRule)