Skip to content

Commit 4bf4d78

Browse files
committed
feat: add useCoursenameAsPrefix option to customize repository naming convention
1 parent a9baccc commit 4bf4d78

12 files changed

Lines changed: 79 additions & 49 deletions

File tree

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ Contents:
6767
coursepath: <base path of course in gitlab>
6868
# if you want to generate directly in coursepath, do not define semesterpath
6969
semesterpath: <gitlab subgroup of coursepath used for this semester>
70+
useCoursenameAsPrefix: <false|true> # if true, repos start with <baseNameOfCourse>-<assignment>, default false
7071
students: # needs only to defined if generating per student
7172
<array of student specifier>
7273
groups: # if students are allowed to work in groups
@@ -118,12 +119,22 @@ Contents:
118119
groups: <add or redefine groups>
119120
```
120121

122+
Naming behavior:
123+
124+
- `useCoursenameAsPrefix: false` (default)
125+
- student repo: `<assignment>-<student>` (example: `blatt1-max_mustermann_at_hm.edu`)
126+
- group repo: `<assignment>-<group>` (example: `blatt1-grp01`)
127+
- `useCoursenameAsPrefix: true`
128+
- student repo: `<baseNameOfCourse>-<assignment>-<student>` (example: `algdati-blatt1-max_mustermann_at_hm.edu`)
129+
- group repo: `<baseNameOfCourse>-<assignment>-<group>` (example: `algdati-blatt1-grp01`)
130+
121131
Example:
122132

123133
```.yaml
124134
algdati:
125135
coursepath: algdati
126136
semesterpath: semester/ob-20ws
137+
useCoursenameAsPrefix: true
127138
students:
128139
- 12334 # GitLab ID
129140
- ob@glabs.io # email address

config/assignment.go

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,21 @@ func GetAssignmentConfig(course, assignment string, onlyForStudentsOrGroups ...s
4848
}
4949

5050
assignmentConfig := &AssignmentConfig{
51-
Course: course,
52-
Name: assignment,
53-
Path: path,
54-
URL: url,
55-
Per: per,
56-
Description: description(assignmentKey),
57-
ContainerRegistry: containerRegistry,
58-
AccessLevel: accessLevel(assignmentKey),
59-
Students: students(per, course, assignment, onlyForStudentsOrGroups...),
60-
Groups: groups(per, course, assignment, onlyForStudentsOrGroups...),
61-
Startercode: startercode(assignmentKey),
62-
Clone: clone(assignmentKey),
63-
Release: release,
64-
Seeder: seeder(assignmentKey),
51+
Course: course,
52+
Name: assignment,
53+
UseCoursenameAsPrefix: viper.GetBool(course + ".useCoursenameAsPrefix"),
54+
Path: path,
55+
URL: url,
56+
Per: per,
57+
Description: description(assignmentKey),
58+
ContainerRegistry: containerRegistry,
59+
AccessLevel: accessLevel(assignmentKey),
60+
Students: students(per, course, assignment, onlyForStudentsOrGroups...),
61+
Groups: groups(per, course, assignment, onlyForStudentsOrGroups...),
62+
Startercode: startercode(assignmentKey),
63+
Clone: clone(assignmentKey),
64+
Release: release,
65+
Seeder: seeder(assignmentKey),
6566
}
6667

6768
return assignmentConfig
@@ -83,6 +84,26 @@ func (cfg *AssignmentConfig) RepoSuffix(student *Student) string {
8384
return ""
8485
}
8586

87+
func (cfg *AssignmentConfig) RepoBaseName() string {
88+
if cfg.UseCoursenameAsPrefix {
89+
return fmt.Sprintf("%s-%s", cfg.Course, cfg.Name)
90+
}
91+
92+
return cfg.Name
93+
}
94+
95+
func (cfg *AssignmentConfig) RepoNameWithSuffix(suffix string) string {
96+
return fmt.Sprintf("%s-%s", cfg.RepoBaseName(), suffix)
97+
}
98+
99+
func (cfg *AssignmentConfig) RepoNameForStudent(student *Student) string {
100+
return cfg.RepoNameWithSuffix(cfg.RepoSuffix(student))
101+
}
102+
103+
func (cfg *AssignmentConfig) RepoNameForGroup(group *Group) string {
104+
return cfg.RepoNameWithSuffix(group.Name)
105+
}
106+
86107
func assignmentPath(course, assignment string) string {
87108
path := viper.GetString(course + ".coursepath")
88109
if semesterpath := viper.GetString(course + ".semesterpath"); len(semesterpath) > 0 {

config/show.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ func (cfg *AssignmentConfig) Show() {
135135
fmt.Print(aurora.Sprintf(aurora.Cyan(`
136136
Course: %s
137137
Assignment: %s
138+
Coursename-Prefix: %t
138139
Per: %s
139140
Base-URL: %s
140141
Description: %s
@@ -148,6 +149,7 @@ Release: %s
148149
`),
149150
aurora.Yellow(cfg.Course),
150151
aurora.Yellow(cfg.Name),
152+
aurora.Yellow(cfg.UseCoursenameAsPrefix),
151153
aurora.Yellow(cfg.Per),
152154
aurora.Yellow(cfg.URL),
153155
aurora.Yellow(cfg.Description),

config/types.go

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,21 @@ type Student struct {
1010
}
1111

1212
type AssignmentConfig struct {
13-
Course string
14-
Name string
15-
Path string
16-
URL string
17-
Per Per
18-
Description string
19-
ContainerRegistry bool
20-
AccessLevel AccessLevel
21-
Students []*Student
22-
Groups []*Group
23-
Startercode *Startercode
24-
Clone *Clone
25-
Release *Release
26-
Seeder *Seeder
13+
Course string
14+
Name string
15+
UseCoursenameAsPrefix bool
16+
Path string
17+
URL string
18+
Per Per
19+
Description string
20+
ContainerRegistry bool
21+
AccessLevel AccessLevel
22+
Students []*Student
23+
Groups []*Group
24+
Startercode *Startercode
25+
Clone *Clone
26+
Release *Release
27+
Seeder *Seeder
2728
}
2829

2930
type Per string

config/urls.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ func (cfg *AssignmentConfig) Urls(assignment bool) {
77
fmt.Println(cfg.URL)
88
} else if cfg.Per == PerStudent {
99
for _, stud := range cfg.Students {
10-
fmt.Printf("%s/%s-%s\n", cfg.URL, cfg.Name, cfg.RepoSuffix(stud))
10+
fmt.Printf("%s/%s\n", cfg.URL, cfg.RepoNameForStudent(stud))
1111
}
1212
} else { // PerGroup
1313
for _, group := range cfg.Groups {
14-
fmt.Printf("%s/%s-%s\n", cfg.URL, cfg.Name, group.Name)
14+
fmt.Printf("%s/%s\n", cfg.URL, cfg.RepoNameForGroup(group))
1515
}
1616
}
1717
}

git/clone.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ func Clone(cfg *config.AssignmentConfig, noSpinner bool) {
3838
func cloneurl(cfg *config.AssignmentConfig, suffix string) string {
3939
return fmt.Sprintf("%s/%s-%s",
4040
strings.Replace(strings.Replace(cfg.URL, "https://", "git@", 1), "/", ":", 1),
41-
cfg.Name, suffix)
41+
cfg.RepoBaseName(), suffix)
4242
}
4343

4444
func localpath(cfg *config.AssignmentConfig, suffix string) string {
45-
return fmt.Sprintf("%s/%s-%s", cfg.Clone.LocalPath, cfg.Name, suffix)
45+
return fmt.Sprintf("%s/%s", cfg.Clone.LocalPath, cfg.RepoNameWithSuffix(suffix))
4646
}
4747

4848
func clone(localpath, branch, cloneurl string, auth ssh.AuthMethod, force bool, noSpinner bool) {

gitlab/archive.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ func (c *Client) archivePerStudent(assignmentCfg *config.AssignmentConfig, unarc
3737
}
3838

3939
for _, student := range assignmentCfg.Students {
40-
name := assignmentCfg.Name + "-" + assignmentCfg.RepoSuffix(student)
41-
projectname := fmt.Sprintf("%s/%s", assignmentCfg.Path, name)
40+
projectname := fmt.Sprintf("%s/%s", assignmentCfg.Path, assignmentCfg.RepoNameForStudent(student))
4241
project, _, err := c.Projects.GetProject(
4342
projectname,
4443
&gitlab.GetProjectOptions{},
@@ -60,7 +59,7 @@ func (c *Client) archivePerGroup(assignmentCfg *config.AssignmentConfig, unarchi
6059
}
6160

6261
for _, grp := range assignmentCfg.Groups {
63-
projectname := fmt.Sprintf("%s/%s-%s", assignmentCfg.Path, assignmentCfg.Name, grp.Name)
62+
projectname := fmt.Sprintf("%s/%s", assignmentCfg.Path, assignmentCfg.RepoNameForGroup(grp))
6463
project, _, err := c.Projects.GetProject(
6564
projectname,
6665
&gitlab.GetProjectOptions{},

gitlab/delete.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ func (c *Client) deletePerStudent(assignmentCfg *config.AssignmentConfig, assign
3434
}
3535

3636
for _, student := range assignmentCfg.Students {
37-
name := assignmentCfg.Name + "-" + assignmentCfg.RepoSuffix(student)
38-
c.delete(assignmentGroupID, name)
37+
c.delete(assignmentGroupID, assignmentCfg.RepoNameForStudent(student))
3938
}
4039
}
4140

@@ -46,7 +45,7 @@ func (c *Client) deletePerGroup(assignmentCfg *config.AssignmentConfig, assignme
4645
}
4746

4847
for _, grp := range assignmentCfg.Groups {
49-
c.delete(assignmentGroupID, assignmentCfg.Name+"-"+grp.Name)
48+
c.delete(assignmentGroupID, assignmentCfg.RepoNameForGroup(grp))
5049
}
5150
}
5251

gitlab/generate.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ func (c *Client) generatePerStudent(assignmentCfg *config.AssignmentConfig, assi
219219
}
220220

221221
for _, student := range assignmentCfg.Students {
222-
name := assignmentCfg.Name + "-" + assignmentCfg.RepoSuffix(student)
222+
name := assignmentCfg.RepoNameForStudent(student)
223223
c.generate(assignmentCfg, assignmentGroupID, name, []*config.Student{student}, starterrepo)
224224
}
225225
}
@@ -232,6 +232,6 @@ func (c *Client) generatePerGroup(assignmentCfg *config.AssignmentConfig, assign
232232
}
233233

234234
for _, grp := range assignmentCfg.Groups {
235-
c.generate(assignmentCfg, assignmentGroupID, assignmentCfg.Name+"-"+grp.Name, grp.Members, starterrepo)
235+
c.generate(assignmentCfg, assignmentGroupID, assignmentCfg.RepoNameForGroup(grp), grp.Members, starterrepo)
236236
}
237237
}

gitlab/protect.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,7 @@ func (c *Client) protectToBranchPerStudent(assignmentCfg *config.AssignmentConfi
118118
}
119119

120120
for _, student := range assignmentCfg.Students {
121-
name := assignmentCfg.Name + "-" + assignmentCfg.RepoSuffix(student)
122-
projectname := fmt.Sprintf("%s/%s", assignmentCfg.Path, name)
121+
projectname := fmt.Sprintf("%s/%s", assignmentCfg.Path, assignmentCfg.RepoNameForStudent(student))
123122
project, _, err := c.Projects.GetProject(
124123
projectname,
125124
&gitlab.GetProjectOptions{},
@@ -141,7 +140,7 @@ func (c *Client) protectToBranchPerGroup(assignmentCfg *config.AssignmentConfig)
141140
}
142141

143142
for _, grp := range assignmentCfg.Groups {
144-
projectname := fmt.Sprintf("%s/%s-%s", assignmentCfg.Path, assignmentCfg.Name, grp.Name)
143+
projectname := fmt.Sprintf("%s/%s", assignmentCfg.Path, assignmentCfg.RepoNameForGroup(grp))
145144
project, _, err := c.Projects.GetProject(
146145
projectname,
147146
&gitlab.GetProjectOptions{},

0 commit comments

Comments
 (0)