Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 14c32b4

Browse files
committed
chore: refactoring
1 parent ded4540 commit 14c32b4

File tree

3 files changed

+33
-9
lines changed

3 files changed

+33
-9
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Bulid
1+
name: Build
22
on:
33
- push
44

README.md

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,28 @@
11
# ics2mattermost
22
> **Note**
33
>
4-
> An ICS (calendar) parser sending todays Events and Absentees to Mattermost.
4+
> An ICS (calendar) parser; sending todays Events and Absentees to Mattermost.
55
6-
This application was created out of need for a Mattermost notification informing
6+
This application was created out of need for a Mattermost notification, informing
77
us of todays appointments.
8-
We wanted to display todays absentees, Meetingslinks and Daily times.
8+
We wanted to display todays absentees, Meetingslinks and Daily/meeting times.
99

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

14+
# Usage
15+
Currently four Env Variables are necessary to run the application:
16+
```sh
17+
export ICS_URL=<url to the ics calendar>
18+
19+
export MATTERMOST_URL=<url to the mattermost incoming webhook>
20+
21+
export ICS_USER=<login name to access the calendar>
22+
export ICS_TOKEN=<personal access token to the calendar>
23+
```
24+
*Remember:* the ics/calendar config is done with confluence in mind
25+
1426
# Development
1527
Setup:
1628
```bash
@@ -24,5 +36,5 @@ Creat a new Incomig Webhook Integration and export that URL as
2436

2537
Run tests:
2638
```bash
27-
go tests ./...
39+
make test
2840
```

icsparser/daily.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ type DailyIngest struct {
1717

1818
func (c *Calendar) gatherRelevantEvents() DailyIngest {
1919

20-
var ingest DailyIngest
20+
var ingest DailyIngest
2121

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

5656
loc := time.Local
57-
var formattedEvents string
57+
var formattedEvents, travellers, absentees string
5858

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

64+
if len(ingest.AbsentPersons) == 0 {
65+
absentees = "*no one*"
66+
} else {
67+
absentees = strings.Join(ingest.AbsentPersons, ", ")
68+
}
69+
70+
if len(ingest.TravellingPersons) == 0 {
71+
travellers = "*no one*"
72+
} else {
73+
travellers = strings.Join(ingest.TravellingPersons, ", ")
74+
}
75+
6476
dailyMessage := map[string]string{
6577
"name": "Foobar",
6678
"text": "#### Welcome to VRP's daily ingest\n" +
6779
formattedEvents +
68-
":airplane: " + strings.Join(ingest.TravellingPersons, ", ") + "\n" +
69-
":palm_tree: " + strings.Join(ingest.AbsentPersons, ", "),
80+
":airplane: " + travellers + "\n" +
81+
":palm_tree: " + absentees,
7082
}
7183

7284
// logger.Info(

0 commit comments

Comments
 (0)