Skip to content

Commit

Permalink
chore: refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
nce committed Nov 30, 2022
1 parent ded4540 commit 14c32b4
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Bulid
name: Build
on:
- push

Expand Down
20 changes: 16 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
# ics2mattermost
> **Note**
>
> An ICS (calendar) parser sending todays Events and Absentees to Mattermost.
> An ICS (calendar) parser; sending todays Events and Absentees to Mattermost.
This application was created out of need for a Mattermost notification informing
This application was created out of need for a Mattermost notification, informing
us of todays appointments.
We wanted to display todays absentees, Meetingslinks and Daily times.
We wanted to display todays absentees, Meetingslinks and Daily/meeting times.

I use a personal access token to access our (confluence) ics calendar and parse
todays appointments. One notification gets send to our channel with all of the
aggregated information.

# Usage
Currently four Env Variables are necessary to run the application:
```sh
export ICS_URL=<url to the ics calendar>

export MATTERMOST_URL=<url to the mattermost incoming webhook>

export ICS_USER=<login name to access the calendar>
export ICS_TOKEN=<personal access token to the calendar>
```
*Remember:* the ics/calendar config is done with confluence in mind

# Development
Setup:
```bash
Expand All @@ -24,5 +36,5 @@ Creat a new Incomig Webhook Integration and export that URL as

Run tests:
```bash
go tests ./...
make test
```
20 changes: 16 additions & 4 deletions icsparser/daily.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type DailyIngest struct {

func (c *Calendar) gatherRelevantEvents() DailyIngest {

var ingest DailyIngest
var ingest DailyIngest

for _, event := range c.Events {
travelers, err := event.GetPersonsByCategory("travel")
Expand Down Expand Up @@ -54,19 +54,31 @@ func (c *Calendar) PrepareDailyIngest() (map[string]string, error) {
logger.Info(fmt.Sprintf("amount of meetings: %d", len(ingest.EventsToday)))

loc := time.Local
var formattedEvents string
var formattedEvents, travellers, absentees string

for _, e := range ingest.EventsToday {
formattedEvents = formattedEvents + ":calendar: " + e.Start.In(loc).Format("15:04") + " - " +
e.End.In(loc).Format("15:04 MST") + " :fire: [" + e.Summary + "](" + e.Location + ")\n"
}

if len(ingest.AbsentPersons) == 0 {
absentees = "*no one*"
} else {
absentees = strings.Join(ingest.AbsentPersons, ", ")
}

if len(ingest.TravellingPersons) == 0 {
travellers = "*no one*"
} else {
travellers = strings.Join(ingest.TravellingPersons, ", ")
}

dailyMessage := map[string]string{
"name": "Foobar",
"text": "#### Welcome to VRP's daily ingest\n" +
formattedEvents +
":airplane: " + strings.Join(ingest.TravellingPersons, ", ") + "\n" +
":palm_tree: " + strings.Join(ingest.AbsentPersons, ", "),
":airplane: " + travellers + "\n" +
":palm_tree: " + absentees,
}

// logger.Info(
Expand Down

0 comments on commit 14c32b4

Please sign in to comment.