Skip to content

Commit 2cdc850

Browse files
committed
Change Git default branch to main in update_rules tool
On-behalf-of: @SAP [email protected] Signed-off-by: Marko Mudrinić <[email protected]>
1 parent faa65a9 commit 2cdc850

File tree

4 files changed

+91
-1490
lines changed

4 files changed

+91
-1490
lines changed

cmd/update-rules/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727
"k8s.io/publishing-bot/cmd/publishing-bot/config"
2828
)
2929

30-
const GitDefaultBranch = "master"
30+
const gitDefaultBranch = "main"
3131

3232
type options struct {
3333
branch string
@@ -149,7 +149,7 @@ func UpdateRules(rules *config.RepositoryRules, branch, goVer string, deleteRule
149149
// find the mainBranch rules
150150
for i := range r.Branches {
151151
br := r.Branches[i]
152-
if br.Name == GitDefaultBranch {
152+
if br.Name == gitDefaultBranch {
153153
cloneBranchRule(&br, &newBranchRule)
154154
mainBranchRuleFound = true
155155
break
@@ -158,7 +158,7 @@ func UpdateRules(rules *config.RepositoryRules, branch, goVer string, deleteRule
158158

159159
// if mainBranch rules not found for repo, it means it's removed from master tree, log warning and skip updating the rules
160160
if !mainBranchRuleFound {
161-
glog.Warningf("%s branch rules not found for repo %s, skipping to update branch %s rules", GitDefaultBranch, r.DestinationRepository, branch)
161+
glog.Warningf("%s branch rules not found for repo %s, skipping to update branch %s rules", gitDefaultBranch, r.DestinationRepository, branch)
162162
continue
163163
}
164164

cmd/update-rules/main_test.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
var (
2525
testdataRules = "testdata/rules.yaml"
2626
testdataInvalidRules = "testdata/invalid_rules.yaml"
27-
remoteRules = "https://raw.githubusercontent.com/kubernetes/kubernetes/master/staging/publishing/rules.yaml"
27+
remoteRules = "https://raw.githubusercontent.com/kcp-dev/kcp/main/staging/publishing/rules.yaml"
2828
)
2929

3030
func TestLoad(t *testing.T) {
@@ -100,8 +100,8 @@ func TestUpdateRules(t *testing.T) {
100100
"1.16.1",
101101
},
102102
{
103-
"master branch rule update for go version",
104-
"master",
103+
"main branch rule update for go version",
104+
"main",
105105
"1.16.4",
106106
},
107107
}
@@ -115,51 +115,51 @@ func TestUpdateRules(t *testing.T) {
115115
UpdateRules(rules, tt.branch, tt.goVersion, false)
116116

117117
for _, repoRule := range rules.Rules {
118-
var masterRulePresent, branchRulePresent bool
119-
var masterRuleIndex, branchRuleIndex int
118+
var mainRulePresent, branchRulePresent bool
119+
var mainRuleIndex, branchRuleIndex int
120120

121121
for i, branchRule := range repoRule.Branches {
122122
switch branchRule.Name {
123-
case "master":
124-
masterRulePresent = true
125-
masterRuleIndex = i
123+
case "main":
124+
mainRulePresent = true
125+
mainRuleIndex = i
126126
case tt.branch:
127127
branchRulePresent = true
128128
branchRuleIndex = i
129129
}
130130
}
131-
switch masterRulePresent {
131+
switch mainRulePresent {
132132
case true:
133-
if !branchRulePresent && tt.branch != "master" {
133+
if !branchRulePresent && tt.branch != "main" {
134134
t.Errorf("error updating branch %s rule for repo %s", tt.branch, repoRule.DestinationRepository)
135135
}
136136
case false:
137137
if branchRulePresent {
138-
t.Errorf("incorrectly added branch %s rule for repo %s whose master branch rule does not exists", tt.branch, repoRule.DestinationRepository)
138+
t.Errorf("incorrectly added branch %s rule for repo %s whose main branch rule does not exists", tt.branch, repoRule.DestinationRepository)
139139
}
140140
}
141141

142142
if repoRule.Branches[branchRuleIndex].Source.Branch != tt.branch {
143143
t.Errorf("incorrect update to branch %s rule for source branch field for repo %s", tt.branch, repoRule.DestinationRepository)
144144
}
145145

146-
if repoRule.Branches[masterRuleIndex].Source.Dir != repoRule.Branches[branchRuleIndex].Source.Dir {
146+
if repoRule.Branches[mainRuleIndex].Source.Dir != repoRule.Branches[branchRuleIndex].Source.Dir {
147147
t.Errorf("incorrect update to branch %s rule for source dir field for repo %s", tt.branch, repoRule.DestinationRepository)
148148
}
149149

150150
if repoRule.Branches[branchRuleIndex].GoVersion != tt.goVersion {
151151
t.Errorf("incorrect go version set for branch %s rule for repo %s", tt.branch, repoRule.DestinationRepository)
152152
}
153153

154-
if len(repoRule.Branches[masterRuleIndex].Dependencies) != len(repoRule.Branches[branchRuleIndex].Dependencies) {
154+
if len(repoRule.Branches[mainRuleIndex].Dependencies) != len(repoRule.Branches[branchRuleIndex].Dependencies) {
155155
t.Errorf("incorrect update to branch %s rule dependencies for repo %s", tt.branch, repoRule.DestinationRepository)
156156
}
157157

158-
if len(repoRule.Branches[masterRuleIndex].RequiredPackages) != len(repoRule.Branches[branchRuleIndex].RequiredPackages) {
158+
if len(repoRule.Branches[mainRuleIndex].RequiredPackages) != len(repoRule.Branches[branchRuleIndex].RequiredPackages) {
159159
t.Errorf("incorrect update to branch %s rule required packages for repo %s", tt.branch, repoRule.DestinationRepository)
160160
}
161161

162-
if repoRule.Branches[masterRuleIndex].SmokeTest != repoRule.Branches[branchRuleIndex].SmokeTest {
162+
if repoRule.Branches[mainRuleIndex].SmokeTest != repoRule.Branches[branchRuleIndex].SmokeTest {
163163
t.Errorf("incorrect update to branch %s rule smoke-test for repo %s", tt.branch, repoRule.DestinationRepository)
164164
}
165165
}

cmd/update-rules/testdata/invalid_rules.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ rules:
22
- destination: code-generator
33
branches:
44
- source:
5-
branch: master
5+
branch: main
66
dir: staging/src/k8s.io/code-generator
7-
name: master
7+
name: main
88
- source:
99
branch: release-1.19
1010
dir: staging/src/k8s.io/code-generator

0 commit comments

Comments
 (0)