Skip to content

Commit 3729a7f

Browse files
committed
✨ Allow renaming repos completely
1 parent d2cc829 commit 3729a7f

File tree

3 files changed

+32
-12
lines changed

3 files changed

+32
-12
lines changed

Justfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@ dev:
55

66
build:
77
go build -o bin/main main.go
8+
9+
updateschema:
10+
go run main.go --print-jsonschema > config.schema.json

config.schema.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
"prefix": { "type": "string" },
2727
"suffix": { "type": "string" },
2828
"topics": { "items": { "type": "string" }, "type": "array" },
29+
"renames": {
30+
"additionalProperties": { "type": "string" },
31+
"type": "object"
32+
},
2933
"subgroups": {
3034
"properties": { "flatten": { "type": "string" } },
3135
"additionalProperties": false,
@@ -44,6 +48,10 @@
4448
"prefix": { "type": "string" },
4549
"suffix": { "type": "string" },
4650
"topics": { "items": { "type": "string" }, "type": "array" },
51+
"renames": {
52+
"additionalProperties": { "type": "string" },
53+
"type": "object"
54+
},
4755
"subgroups": {
4856
"properties": { "flatten": { "type": "string" } },
4957
"additionalProperties": false,

main.go

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,31 +15,33 @@ import (
1515
"golang.org/x/exp/slices"
1616

1717
"dario.cat/mergo"
18-
ll "github.com/ewen-lbh/label-logger-go"
1918
"github.com/google/uuid"
19+
ll "github.com/gwennlbh/label-logger-go"
2020
"github.com/invopop/jsonschema"
2121
"github.com/joho/godotenv"
2222
"gopkg.in/yaml.v3"
2323
)
2424

2525
type MirrorDefaults struct {
26-
Except []string `json:"except,omitempty"`
27-
Only []string `json:"only,omitempty"`
28-
Prefix string `json:"prefix,omitempty"`
29-
Suffix string `json:"suffix,omitempty"`
30-
Topics []string `json:"topics,omitempty"`
26+
Except []string `json:"except,omitempty"`
27+
Only []string `json:"only,omitempty"`
28+
Prefix string `json:"prefix,omitempty"`
29+
Suffix string `json:"suffix,omitempty"`
30+
Topics []string `json:"topics,omitempty"`
31+
Renames map[string]string `json:"renames,omitempty"`
3132
Subgroups struct {
3233
Flatten string `json:"flatten"`
3334
} `json:"subgroups,omitempty"`
3435
}
3536

3637
type MirrorDefinition struct {
37-
From string `json:"from"`
38-
Except []string `json:"except,omitempty"`
39-
Only []string `json:"only,omitempty"`
40-
Prefix string `json:"prefix,omitempty"`
41-
Suffix string `json:"suffix,omitempty"`
42-
Topics []string `json:"topics,omitempty"`
38+
From string `json:"from"`
39+
Except []string `json:"except,omitempty"`
40+
Only []string `json:"only,omitempty"`
41+
Prefix string `json:"prefix,omitempty"`
42+
Suffix string `json:"suffix,omitempty"`
43+
Topics []string `json:"topics,omitempty"`
44+
Renames map[string]string `json:"renames,omitempty"`
4345
Subgroups struct {
4446
Flatten string `json:"flatten"`
4547
} `json:"subgroups,omitempty"`
@@ -154,6 +156,7 @@ func githubOrgConfig(org string) ([]MirrorDefinition, bool) {
154156
Suffix: config.Defaults.Suffix,
155157
Topics: config.Defaults.Topics,
156158
Subgroups: config.Defaults.Subgroups,
159+
Renames: config.Defaults.Renames,
157160
})
158161
}
159162
return merged, true
@@ -401,6 +404,12 @@ func setGitLabMirror(repo map[string]interface{}, githubName string, githubOrg s
401404
func githubNameFromGitlabPath(path string, mirrorConfigUsed MirrorDefinition) string {
402405
pathParts := strings.Split(path, "/")[1:]
403406
path = strings.Join(pathParts, mirrorConfigUsed.Subgroups.Flatten)
407+
for from, to := range mirrorConfigUsed.Renames {
408+
if from == path {
409+
path = to
410+
break
411+
}
412+
}
404413
path = fmt.Sprintf("%s%s%s", mirrorConfigUsed.Prefix, path, mirrorConfigUsed.Suffix)
405414
return path
406415
}

0 commit comments

Comments
 (0)