Skip to content

Commit 5629499

Browse files
committed
Tiny formatting changes.
1 parent 5f12431 commit 5629499

File tree

2 files changed

+22
-20
lines changed

2 files changed

+22
-20
lines changed

internal/app.go

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ func (a *App) getCleanedCalendar(all []byte, hiddenCourses map[string]bool) (*ic
296296
}
297297
}
298298

299-
// Second pass: deduplicate and clean events, adding additional rooms to description
299+
// Second pass: deduplicate and clean events, adding additional rooms to the description
300300
hasLecture := make(map[string]bool)
301301
var newComponents []ics.Component // saves the components we keep because they are not duplicated
302302

@@ -378,20 +378,12 @@ var reRoom = regexp.MustCompile("^(.*?),.*?(\\d{4})\\.(?:\\d\\d|EG|UG|DG|Z\\d|U\
378378
var reNavigaTUM = regexp.MustCompile("\\(\\d{4}\\.[a-zA-Z0-9]{2}\\.\\d{3}[A-Z]?\\)")
379379

380380
func (a *App) cleanEvent(event *ics.VEvent, additionalLocations []string) {
381+
// Event Title
381382
summary := ""
382383
if s := event.GetProperty(ics.ComponentPropertySummary); s != nil {
383384
summary = cleanEventSummary(s.Value)
384385
}
385-
386-
description := ""
387-
if d := event.GetProperty(ics.ComponentPropertyDescription); d != nil {
388-
description = d.Value
389-
}
390-
391-
location := ""
392-
if l := event.GetProperty(ics.ComponentPropertyLocation); l != nil {
393-
location = event.GetProperty(ics.ComponentPropertyLocation).Value
394-
}
386+
originalSummary := summary
395387

396388
// Remove the TAG and anything after e.g.: (IN0001) or [MA0001]
397389
summary = reTag.ReplaceAllString(summary, "")
@@ -405,11 +397,26 @@ func (a *App) cleanEvent(event *ics.VEvent, additionalLocations []string) {
405397
// What the heck? And why only sometimes???
406398
summary = reWeirdStartingNumbers.ReplaceAllString(summary, "")
407399

400+
// Do all the course-specific replacements
401+
for _, repl := range a.courseReplacements {
402+
summary = strings.ReplaceAll(summary, repl.key, repl.value)
403+
}
408404
event.SetSummary(summary)
409405

406+
// Description
410407
// Remember the old title in the description
411-
description = summary + "\n" + description
408+
description := ""
409+
if d := event.GetProperty(ics.ComponentPropertyDescription); d != nil {
410+
description = d.Value
411+
}
412+
description = originalSummary + "\n" + description
412413

414+
// Location
415+
// Replace the location with the building name, if it matches our map
416+
location := ""
417+
if l := event.GetProperty(ics.ComponentPropertyLocation); l != nil {
418+
location = event.GetProperty(ics.ComponentPropertyLocation).Value
419+
}
413420
results := reRoom.FindStringSubmatch(location)
414421
if len(results) == 3 {
415422
if building, ok := a.buildingReplacements[results[2]]; ok {
@@ -428,14 +435,9 @@ func (a *App) cleanEvent(event *ics.VEvent, additionalLocations []string) {
428435
if len(additionalLocations) > 0 {
429436
description = "Additional rooms:\n" + strings.Join(additionalLocations, "\n") + "\n\n" + description
430437
}
431-
432438
event.SetDescription(description)
433439

434-
// set title on summary:
435-
for _, repl := range a.courseReplacements {
436-
summary = strings.ReplaceAll(summary, repl.key, repl.value)
437-
}
438-
event.SetSummary(summary)
440+
// Set status based on ical status, so cancelled events are marked as such in the calendar
439441
switch event.GetProperty(ics.ComponentPropertyStatus).Value {
440442
case "CONFIRMED":
441443
event.SetStatus(ics.ObjectStatusConfirmed)

internal/app_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,9 @@ func TestLocationReplacement(t *testing.T) {
164164
return
165165
}
166166
desc := calendar.Components[0].(*ics.VEvent).GetProperty(ics.ComponentPropertyDescription).Value
167-
expectedDescription := "Additional rooms:\nMI HS 1\n\nhttps://nav.tum.de/room/5508.02.801\nMW 1801, Ernst-Schmidt-Hörsaal (5508.02.801)\nEinführung in die Rechnerarchitektur\nfix; Abhaltung;"
167+
expectedDescription := "Additional rooms:\nMI HS 1\n\nhttps://nav.tum.de/room/5508.02.801\nMW 1801, Ernst-Schmidt-Hörsaal (5508.02.801)\nEinführung in die Rechnerarchitektur (IN0004) VO, Standardgruppe\nfix; Abhaltung;"
168168
if desc != expectedDescription {
169-
t.Errorf("Description should be %s but is %s", expectedDescription, desc)
169+
t.Errorf("Description should be \n\n%s\n\nbut is\n\n%s\n\n", expectedDescription, desc)
170170
return
171171
}
172172
}

0 commit comments

Comments
 (0)