Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions Code.gs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ var addEventsToCalendar = true; // If you turn this to "false", you ca
var modifyExistingEvents = true; // If you turn this to "false", any event in the feed that was modified after being added to the calendar will not update
var removeEventsFromCalendar = true; // If you turn this to "true", any event created by the script that is not found in the feed will be removed.
var removePastEventsFromCalendar = true; // If you turn this to "false", any event that is in the past will not be removed.
var skipIfEmptyFeed = false; // If you turn this to "true", it will skip sync when feed is empty instead of removing all events from target calendar.
var addAlerts = "yes"; // Whether to add the ics/ical alerts as notifications on the Google Calendar events or revert to the calendar's default reminders ("yes", "no", "default").
var addOrganizerToTitle = false; // Whether to prefix the event name with the event organiser for further clarity
var descriptionAsTitles = false; // Whether to use the ics/ical descriptions as titles (true) or to use the normal titles as titles (false)
Expand Down Expand Up @@ -172,6 +173,10 @@ function startSync(){

//------------------------ Fetch URL items ------------------------
var responses = fetchSourceCalendars(sourceCalendarURLs);
if (responses.length == 0 && skipIfEmptyFeed){
Logger.log("Skipping this sync iteration due to empty feed (assuming temp problem), not modifying " + targetCalendarName);
continue;
}
Logger.log("Syncing " + responses.length + " calendars to " + targetCalendarName);

//------------------------ Get target calendar information------------------------
Expand Down Expand Up @@ -242,8 +247,13 @@ function startSync(){
}
}

if ((addedEvents.length + modifiedEvents.length + removedEvents.length) > 0 && emailSummary){
sendSummary();
if (emailSummary){
if (reportOverallFailure || addedEvents.length || modifiedEvents.length || removedEvents.length){
sendSummary(reportOverallFailure ? 1 : 0);
Logger.log("Email Sent.");
} else {
Logger.log("No Email Sent because there were no errors nor updates to events.");
}
}
Logger.log("Sync finished!");
PropertiesService.getUserProperties().setProperty('LastRun', 0);
Expand Down
9 changes: 7 additions & 2 deletions Helpers.gs
Original file line number Diff line number Diff line change
Expand Up @@ -1185,12 +1185,14 @@ function parseNotificationTime(notificationString){

/**
* Sends an email summary with added/modified/deleted events.
*
* @param {number} numErrors - number of errors to report in email
*/
function sendSummary() {
function sendSummary(numErrors) {
var subject;
var body;

var subject = `${customEmailSubject ? customEmailSubject : "GAS-ICS-Sync Execution Summary"}: ${addedEvents.length} new, ${modifiedEvents.length} modified, ${removedEvents.length} deleted`;
var subject = `${customEmailSubject ? customEmailSubject : "GAS-ICS-Sync Execution Summary"}: ${addedEvents.length} new, ${modifiedEvents.length} modified, ${removedEvents.length} deleted, ${numErrors} errors`;
addedEvents = condenseCalendarMap(addedEvents);
modifiedEvents = condenseCalendarMap(modifiedEvents);
removedEvents = condenseCalendarMap(removedEvents);
Expand Down Expand Up @@ -1243,6 +1245,9 @@ function sendSummary() {
body += "</ul>";
}

if (numErrors) {
body += "<br/><br/>There were errors, see execution logs.";
}
body += "<br/><br/>Do you have any problems or suggestions? Contact us at <a href='https://github.com/derekantrican/GAS-ICS-Sync/'>github</a>.";
var message = {
to: email,
Expand Down