Skip to content

Commit 49408ee

Browse files
author
Gerit Wagner
committed
update ISSUE_TEMPLATES and calendar generation
1 parent 3838434 commit 49408ee

File tree

5 files changed

+236
-1
lines changed

5 files changed

+236
-1
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
name: Request Onboarding
3+
about: Use this template to start the onboarding process
4+
title: "Request to Join the Team"
5+
labels: onboarding
6+
assignees: geritwagner
7+
---
8+
9+
## Request to Join the Team
10+
11+
**GitHub Username:** <!-- Replace with your GitHub username -->
12+
13+
### Admin Action for Maintainer:
14+
15+
```
16+
@digital-work-labot onboard GITHUB_ID
17+
```
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
name: Request Repository Access
3+
about: Use this template to request access to a private repository
4+
title: "[Access Request] Request for access to repository"
5+
labels: access request
6+
assignees: geritwagner
7+
---
8+
9+
### Requested Repositories
10+
11+
Please list the repository/repositories you would like access to:
12+
13+
```
14+
<Insert repository URL>
15+
```

.github/workflows/generate_ical.js

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
const yaml = require('js-yaml');
4+
const { DateTime } = require('luxon');
5+
const { RRule } = require('rrule');
6+
7+
function parseDateTime(dateTimeString) {
8+
// Parse "YYYY-MM-DD HH:MM" into Berlin timezone [YYYY, MM, DD, HH, MM]
9+
const dateTime = DateTime.fromFormat(dateTimeString, 'yyyy-MM-dd HH:mm', { zone: 'Europe/Berlin' });
10+
if (dateTime.isValid) {
11+
return [
12+
dateTime.year,
13+
dateTime.month,
14+
dateTime.day,
15+
dateTime.hour,
16+
dateTime.minute,
17+
];
18+
} else {
19+
console.warn(`Invalid date-time format: ${dateTimeString}`);
20+
return null; // Return null for invalid date-time
21+
}
22+
}
23+
24+
async function loadEvents() {
25+
try {
26+
const yamlText = fs.readFileSync('./assets/calendar/events.yaml', 'utf8'); // Read the YAML file
27+
const events = yaml.load(yamlText);
28+
29+
if (!Array.isArray(events)) {
30+
throw new Error("Parsed YAML is not an array");
31+
}
32+
33+
const expandedEvents = [];
34+
for (const event of events) {
35+
const startDate = new Date(event.start);
36+
const endDate = new Date(event.end);
37+
38+
if (event.recurrence) {
39+
const rrule = new RRule({
40+
...RRule.parseString(event.recurrence),
41+
dtstart: startDate,
42+
});
43+
44+
rrule.all().forEach(date => {
45+
const end = new Date(date.getTime() + (endDate - startDate));
46+
expandedEvents.push({
47+
start: date.toISOString(),
48+
end: end.toISOString(),
49+
title: event.title,
50+
color: event.color,
51+
location: event.location,
52+
description: event.description,
53+
});
54+
});
55+
} else {
56+
// Non-recurring event
57+
expandedEvents.push({
58+
start: event.start,
59+
end: event.end,
60+
title: event.title,
61+
color: event.color,
62+
location: event.location,
63+
description: event.description,
64+
});
65+
}
66+
}
67+
68+
console.log("Expanded events:", expandedEvents);
69+
return expandedEvents;
70+
} catch (error) {
71+
console.error("Error fetching or parsing YAML:", error);
72+
return [];
73+
}
74+
}
75+
76+
77+
function generateICal(events) {
78+
const vtimezone = `
79+
BEGIN:VTIMEZONE
80+
TZID:Europe/Berlin
81+
BEGIN:STANDARD
82+
DTSTART:20231029T030000
83+
RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU
84+
TZOFFSETFROM:+0200
85+
TZOFFSETTO:+0100
86+
TZNAME:CET
87+
END:STANDARD
88+
BEGIN:DAYLIGHT
89+
DTSTART:20240331T020000
90+
RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU
91+
TZOFFSETFROM:+0100
92+
TZOFFSETTO:+0200
93+
TZNAME:CEST
94+
END:DAYLIGHT
95+
END:VTIMEZONE`;
96+
97+
function parseDate(input) {
98+
try {
99+
if (typeof input === 'string' && input.includes('T')) {
100+
return DateTime.fromISO(input);
101+
} else if (typeof input === 'string') {
102+
return DateTime.fromFormat(input, "yyyy-MM-dd HH:mm");
103+
} else {
104+
throw new Error("Invalid date format");
105+
}
106+
} catch (error) {
107+
console.error("Error parsing date:", input, error);
108+
return null;
109+
}
110+
}
111+
112+
const vevents = events
113+
.map(event => {
114+
const dtstart = parseDate(event.start);
115+
const dtend = parseDate(event.end);
116+
117+
if (!dtstart || !dtend) {
118+
console.error("Skipping event due to invalid dates:", event);
119+
return null;
120+
}
121+
122+
return `
123+
BEGIN:VEVENT
124+
UID:${Math.random().toString(36).substring(2, 15)}
125+
SUMMARY:${event.title}
126+
DTSTAMP:${DateTime.now().toUTC().toFormat("yyyyMMdd'T'HHmmss'Z'")}
127+
DTSTART;TZID=Europe/Berlin:${dtstart.toFormat("yyyyMMdd'T'HHmmss")}
128+
DTEND;TZID=Europe/Berlin:${dtend.toFormat("yyyyMMdd'T'HHmmss")}
129+
DESCRIPTION:${event.description || ''}
130+
LOCATION:${event.location || ''}
131+
END:VEVENT`;
132+
})
133+
.filter(Boolean) // Remove null values
134+
.join("\n");
135+
136+
return `BEGIN:VCALENDAR
137+
VERSION:2.0
138+
CALSCALE:GREGORIAN
139+
PRODID:-//Digital Work Lab//Calendar Export Tool//EN
140+
METHOD:PUBLISH
141+
X-PUBLISHED-TTL:PT1H
142+
${vtimezone}
143+
${vevents}
144+
END:VCALENDAR`;
145+
}
146+
147+
(async () => {
148+
try {
149+
const events = await loadEvents();
150+
console.log('Loaded events:', events); // Log loaded events for debugging
151+
const icalContent = generateICal(events);
152+
153+
const outputPath = path.join('assets/calendar/fs-ise.ical');
154+
fs.writeFileSync(outputPath, icalContent, 'utf8');
155+
console.log('iCal file generated and saved to:', outputPath);
156+
} catch (error) {
157+
console.error('Error during iCal generation:', error);
158+
process.exit(1); // Exit with error
159+
}
160+
})();
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Generate iCal File
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
paths:
7+
- 'assets/calendar/calendar.js'
8+
- 'assets/calendar/events.yaml'
9+
10+
jobs:
11+
generate-ical:
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Checkout repository
16+
uses: actions/checkout@v3
17+
18+
- name: Set up Node.js
19+
uses: actions/setup-node@v3
20+
with:
21+
node-version: '16'
22+
23+
- name: Install dependencies
24+
run: npm install js-yaml ics luxon rrule
25+
26+
- name: Generate iCal File
27+
run: node .github/workflows/generate_ical.js
28+
29+
- name: Commit and Push Changes
30+
run: |
31+
git config --global user.name "github-actions[bot]"
32+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
33+
34+
git add assets/calendar/fs-ise.ical
35+
36+
if git diff --cached --quiet; then
37+
echo "No changes to commit."
38+
else
39+
git commit -m "Update fs-ise.cal"
40+
git push
41+
fi
42+
env:
43+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

assets/calendar/calendar.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ async function initCalendar() {
3838
// Parse events from iCal file
3939
async function loadEventsFromICal() {
4040
try {
41-
const response = await fetch('https://raw.githubusercontent.com/digital-work-lab/handbook/main/docs/calendar/digital_work_cal.ical');
41+
const response = await fetch('https://raw.githubusercontent.com/fs-ise/handbook/main/assets/calendar/fs-ise.ical');
4242
if (!response.ok) {
4343
throw new Error("Network response was not ok: " + response.statusText);
4444
}

0 commit comments

Comments
 (0)