Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 27 additions & 29 deletions config/assignment.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,6 @@ import (
"github.com/spf13/viper"
)

func (ac AccessLevel) String() string {
if ac == 10 {
return "guest"
}
if ac == 20 {
return "reporter"
}
if ac == 30 {
return "developer"
}
return "maintainer"
}

func GetAssignmentConfig(course, assignment string, onlyForStudentsOrGroups ...string) *AssignmentConfig {
if !viper.IsSet(course) {
log.Fatal().
Expand Down Expand Up @@ -56,21 +43,27 @@ func GetAssignmentConfig(course, assignment string, onlyForStudentsOrGroups ...s
Course: course,
Name: assignment,
UseCoursenameAsPrefix: viper.GetBool(course + ".useCoursenameAsPrefix"),
Path: path,
URL: url,
Per: per,
Description: description(assignmentKey),
ContainerRegistry: containerRegistry,
AccessLevel: accessLevel(assignmentKey),
MergeRequest: mergeRequest(assignmentKey),
Branches: branchRules,
Issues: issues(assignmentKey),
Students: students(per, course, assignment, onlyForStudentsOrGroups...),
Groups: groups(per, course, assignment, onlyForStudentsOrGroups...),
Startercode: starter,
Clone: clone(assignmentKey, defaultCloneBranch),
Release: release,
Seeder: seeder(assignmentKey),
UseEmailDomainAsSuffix: func() bool {
if viper.IsSet(course + ".useEmailDomainAsSuffix") {
return viper.GetBool(course + ".useEmailDomainAsSuffix")
}
return true // default
}(),
Path: path,
URL: url,
Per: per,
Description: description(assignmentKey),
ContainerRegistry: containerRegistry,
AccessLevel: accessLevel(assignmentKey),
MergeRequest: mergeRequest(assignmentKey),
Branches: branchRules,
Issues: issues(assignmentKey),
Students: students(per, course, assignment, onlyForStudentsOrGroups...),
Groups: groups(per, course, assignment, onlyForStudentsOrGroups...),
Startercode: starter,
Clone: clone(assignmentKey, defaultCloneBranch),
Release: release,
Seeder: seeder(assignmentKey),
}

return assignmentConfig
Expand All @@ -80,6 +73,12 @@ func GetAssignmentConfig(course, assignment string, onlyForStudentsOrGroups ...s
// This is incompatible to the filesystem and gitlab so replacing the values is necessary.
func (cfg *AssignmentConfig) RepoSuffix(student *Student) string {
if student.Email != nil {
// If explicitly set to false, always use part before @
if viper.IsSet(cfg.Course+".useEmailDomainAsSuffix") && !cfg.UseEmailDomainAsSuffix {
parts := strings.SplitN(*student.Email, "@", 2)
return parts[0]
}
// Default: use _at_ replacement
return strings.ReplaceAll(*student.Email, "@", "_at_")
}
if student.Id != nil {
Expand All @@ -88,7 +87,6 @@ func (cfg *AssignmentConfig) RepoSuffix(student *Student) string {
if student.Username != nil {
return *student.Username
}

return ""
}

Expand Down
17 changes: 16 additions & 1 deletion config/assignment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,25 @@ func TestRepoNamingHelpers(t *testing.T) {
mail := "a@b.example"
user := "alice"

// Default (field not set, should use suffix)
cfg := &AssignmentConfig{Course: "mpd", Name: "blatt01", UseCoursenameAsPrefix: true}
viper.Reset()
if got := cfg.RepoSuffix(&Student{Email: &mail}); got != "a_at_b.example" {
t.Fatalf("RepoSuffix(email, default) = %q", got)
}

// Explicitly set to true
viper.Set("mpd.useEmailDomainAsSuffix", true)
cfg.UseEmailDomainAsSuffix = true
if got := cfg.RepoSuffix(&Student{Email: &mail}); got != "a_at_b.example" {
t.Fatalf("RepoSuffix(email) = %q", got)
t.Fatalf("RepoSuffix(email, true) = %q", got)
}

// Explicitly set to false
viper.Set("mpd.useEmailDomainAsSuffix", false)
cfg.UseEmailDomainAsSuffix = false
if got := cfg.RepoSuffix(&Student{Email: &mail}); got != "a" {
t.Fatalf("RepoSuffix(email, false) = %q", got)
}
if got := cfg.RepoSuffix(&Student{Id: &id}); got != "123" {
t.Fatalf("RepoSuffix(id) = %q", got)
Expand Down
2 changes: 2 additions & 0 deletions config/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ func (cfg *AssignmentConfig) Show() {
fieldCandidate(0, "Course"),
fieldCandidate(0, "Assignment"),
fieldCandidate(0, "Coursename-Prefix"),
fieldCandidate(0, "EmailDomain-Suffix"),
fieldCandidate(0, "Per"),
fieldCandidate(0, "Base-URL"),
fieldCandidate(0, "Description"),
Expand Down Expand Up @@ -155,6 +156,7 @@ func (cfg *AssignmentConfig) Show() {
writeTopField("Course", cfg.Course)
writeTopField("Assignment", cfg.Name)
writeTopField("Coursename-Prefix", cfg.UseCoursenameAsPrefix)
writeTopField("EmailDomain-Suffix", cfg.UseEmailDomainAsSuffix)
writeTopField("Per", cfg.Per)
writeTopField("Base-URL", cfg.URL)
writeTopField("Description", cfg.Description)
Expand Down
52 changes: 34 additions & 18 deletions config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,21 @@ package config

import "github.com/ProtonMail/go-crypto/openpgp"

func (ac AccessLevel) String() string {
switch ac {
case 10:
return "guest"
case 20:
return "reporter"
case 30:
return "developer"
case 40:
return "maintainer"
default:
return "maintainer"
}
}

type Student struct {
Id *int
Username *string
Expand All @@ -10,24 +25,25 @@ type Student struct {
}

type AssignmentConfig struct {
Course string
Name string
UseCoursenameAsPrefix bool
Path string
URL string
Per Per
Description string
ContainerRegistry bool
AccessLevel AccessLevel
MergeRequest *MergeRequest
Branches []BranchRule
Issues *IssueReplication
Students []*Student
Groups []*Group
Startercode *Startercode
Clone *Clone
Release *Release
Seeder *Seeder
Course string
Name string
UseCoursenameAsPrefix bool
UseEmailDomainAsSuffix bool
Path string
URL string
Per Per
Description string
ContainerRegistry bool
AccessLevel AccessLevel
MergeRequest *MergeRequest
Branches []BranchRule
Issues *IssueReplication
Students []*Student
Groups []*Group
Startercode *Startercode
Clone *Clone
Release *Release
Seeder *Seeder
}

type Per string
Expand Down
5 changes: 4 additions & 1 deletion docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ mpd:
| `coursepath` | GitLab subgroup path for course | — | Required |
| `semesterpath` | Additional grouping level | — | Optional |
| `useCoursenameAsPrefix` | Prepend course name to project names | `false` | Example: `mpd-blatt01` |
| `useEmailDomainAsSuffix` | Use full email (with `_at_...`) as repo suffix | `true` | If `false`, only the part before `@` is used (e.g. `alice` instead of `alice_at_example.org`). |
| `students` | List of course-wide students | — | Can be overridden per assignment |
| `groups` | Dict of group → student lists | — | For `per: group` assignments |

Expand All @@ -94,7 +95,9 @@ Students and groups can be specified by:
- **Username**: `alice`
- **User ID**: `12345`

You can mix formats. If using emails, the `@` is replaced with `_at_` in project names (filesystem compatibility).

You can mix formats. By default, if using emails, the `@` is replaced with `_at_` in project names (filesystem compatibility), e.g. `mpd-blatt01-alice_at_example.org`.
If you set `useEmailDomainAsSuffix: false`, only the part before the `@` is used, e.g. `mpd-blatt01-alice`.

### Student/Group filtering

Expand Down
Loading