Skip to content

Commit

Permalink
transformation: add transformer to keep original event link
Browse files Browse the repository at this point in the history
Closes #56
  • Loading branch information
timonegk committed Dec 19, 2024
1 parent 8b2c5a3 commit 818df6f
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 0 deletions.
1 change: 1 addition & 0 deletions example.sync.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ transformations:
config:
NewTitle: "[Synchronisierter Termin]"
- name: KeepMeetingLink
- name: AddOriginalLink
# Do not use KeepAttendees when the Outlook Adapter is used as a sink. There is no way to suppress mail invitations
- name: KeepAttendees
config:
Expand Down
1 change: 1 addition & 0 deletions internal/adapter/google/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func calendarEventToEvent(e *calendar.Event, adapterSourceID string) models.Even
Reminders: reminders,
MeetingLink: e.HangoutLink,
Accepted: hasEventAccepted,
HTMLLink: e.HtmlLink,
}
}

Expand Down
1 change: 1 addition & 0 deletions internal/adapter/outlook_http/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ func (o OutlookClient) outlookEventToEvent(oe Event, adapterSourceID string) (e
Reminders: reminders,
MeetingLink: oe.OnlineMeetingUrl,
Accepted: hasEventAccepted,
HTMLLink: oe.HtmlLink,
}

if oe.IsAllDay {
Expand Down
1 change: 1 addition & 0 deletions internal/models/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type Event struct {
Reminders Reminders
MeetingLink string
Accepted bool
HTMLLink string
}

type Reminders []Reminder
Expand Down
2 changes: 2 additions & 0 deletions internal/sync/transformer.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ var (
"PrefixTitle": &transformation.PrefixTitle{Prefix: ""},
"KeepTitle": &transformation.KeepTitle{},
"KeepMeetingLink": &transformation.KeepMeetingLink{},
"AddOriginalLink": &transformation.AddOriginalLink{},
"KeepDescription": &transformation.KeepDescription{},
"KeepLocation": &transformation.KeepLocation{},
"KeepAttendees": &transformation.KeepAttendees{UseEmailAsDisplayName: false},
Expand All @@ -49,6 +50,7 @@ var (
"KeepReminders",
"KeepDescription",
"KeepMeetingLink",
"AddOriginalLink",
"KeepTitle",
"PrefixTitle",
"ReplaceTitle",
Expand Down
19 changes: 19 additions & 0 deletions internal/transformation/addOriginalLink.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package transformation

import (
"fmt"
"github.com/inovex/CalendarSync/internal/models"
)

type AddOriginalLink struct{}

func (t *AddOriginalLink) Name() string {
return "AddOriginalLink"
}

func (t *AddOriginalLink) Transform(source models.Event, sink models.Event) (models.Event, error) {
if len(source.HTMLLink) > 0 {
sink.Description = fmt.Sprintf("original event link: %s\n\n############\n%s", source.HTMLLink, sink.Description)
}
return sink, nil
}
92 changes: 92 additions & 0 deletions internal/transformation/addOriginalLink_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package transformation

import (
"testing"

"github.com/inovex/CalendarSync/internal/models"
"github.com/stretchr/testify/assert"
)

// verify keep attendees
func TestAddOriginalLink_Transform(t *testing.T) {
source := models.Event{
ICalUID: "testId",
ID: "testUid",
Title: "foo",
Description: "bar",
HTMLLink: "https://foo.com/bar?calendarId=testId",
}
sink := models.NewSyncEvent(source)

addOriginalLink := AddOriginalLink{}

event, err := addOriginalLink.Transform(source, sink)

assert.Nil(t, err)
expectedEvent := models.Event{
ICalUID: "testId",
ID: "testUid",
Title: "CalendarSync Event",
Description: "original event link: https://foo.com/bar?calendarId=testId\n\n############\n",
}

assert.Equal(t, expectedEvent, event)
}

func TestAddOriginalLink_Transform_WithKeepDescription(t *testing.T) {
source := models.Event{
ICalUID: "testId",
ID: "testUid",
Title: "foo",
Description: "bar",
HTMLLink: "https://foo.com/bar?calendarId=testId",
}
sink := models.NewSyncEvent(source)

keepDescription := KeepDescription{}
addOriginalLink := AddOriginalLink{}

sink, err := keepDescription.Transform(source, sink)

Check failure on line 49 in internal/transformation/addOriginalLink_test.go

View workflow job for this annotation

GitHub Actions / GolangCI

ineffectual assignment to err (ineffassign)

Check failure on line 49 in internal/transformation/addOriginalLink_test.go

View workflow job for this annotation

GitHub Actions / STATICCHECK

this value of err is never used (SA4006)
event, err := addOriginalLink.Transform(source, sink)

assert.Nil(t, err)
expectedEvent := models.Event{
ICalUID: "testId",
ID: "testUid",
Title: "CalendarSync Event",
Description: "original event link: https://foo.com/bar?calendarId=testId\n\n############\nbar",
}

assert.Equal(t, expectedEvent, event)
}

func TestAddOriginalLink_Transform_WithKeepDescriptionAndKeepMeetingLink(t *testing.T) {
source := models.Event{
ICalUID: "testId",
ID: "testUid",
Title: "foo",
Description: "bar",
MeetingLink: "https://meetinglink.de",
HTMLLink: "https://foo.com/bar?calendarId=testId",
}
sink := models.NewSyncEvent(source)

keepDescription := KeepDescription{}
keepMeetingLink := KeepMeetingLink{}
addOriginalLink := AddOriginalLink{}

sink, _ = keepDescription.Transform(source, sink)
sink, _ = keepMeetingLink.Transform(source, sink)
event, err := addOriginalLink.Transform(source, sink)

assert.Nil(t, err)
expectedEvent := models.Event{
ICalUID: "testId",
ID: "testUid",
Title: "CalendarSync Event",
Description: "original event link: https://foo.com/bar?calendarId=testId\n\n############\n" +
"original meeting link: https://meetinglink.de\n\n############\nbar",
}

assert.Equal(t, expectedEvent, event)
}

0 comments on commit 818df6f

Please sign in to comment.