MCPcopy
hub / github.com/callumalpass/tasknotes / createTaskFromICS

Method createTaskFromICS

src/services/ICSNoteService.ts:224–285  ·  view source on GitHub ↗

* Create a new task from an ICS event

(
		icsEvent: ICSEvent,
		overrides?: Partial<TaskCreationData>
	)

Source from the content-addressed store, hash-verified

222 * Create a new task from an ICS event
223 */
224 async createTaskFromICS(
225 icsEvent: ICSEvent,
226 overrides?: Partial<TaskCreationData>
227 ): Promise<{ file: TFile; taskInfo: TaskInfo }> {
228 try {
229 // Get the subscription name for context
230 const subscription = this.plugin.icsSubscriptionService
231 .getSubscriptions()
232 .find((sub) => sub.id === icsEvent.subscriptionId);
233 const subscriptionName = subscription?.name || "Unknown Calendar";
234
235 // Convert ICS event to task creation data
236 const scheduledValue =
237 overrides?.scheduled !== undefined
238 ? overrides.scheduled
239 : this.computeScheduledFromICSEvent(icsEvent);
240
241 const taskData: TaskCreationData = {
242 title: overrides?.title || icsEvent.title,
243 status: overrides?.status || this.plugin.settings.defaultTaskStatus,
244 priority: overrides?.priority || this.plugin.settings.defaultTaskPriority,
245 due:
246 overrides?.due !== undefined
247 ? overrides.due
248 : this.plugin.settings.icsIntegration?.useICSEndAsDue
249 ? this.computeDueFromICSEnd(icsEvent)
250 : undefined,
251 // Safe date handling per guidelines:
252 // - all-day: YYYY-MM-DD (UTC-anchored calendar day)
253 // - timed: YYYY-MM-DDTHH:mm (local)
254 scheduled: scheduledValue,
255 contexts:
256 overrides?.contexts || (icsEvent.location ? [icsEvent.location] : undefined),
257 projects: overrides?.projects,
258 tags: overrides?.tags || [this.plugin.fieldMapper.toUserField("icsEventTag")],
259 timeEstimate: overrides?.timeEstimate || this.calculateEventDuration(icsEvent),
260 details:
261 overrides?.details || this.buildICSEventDetails(icsEvent, subscriptionName),
262 icsEventId: [icsEvent.id],
263 creationContext: "ics-event",
264 dateCreated: getCurrentTimestamp(),
265 dateModified: getCurrentTimestamp(),
266 // Spread overrides but exclude 'due' since we handle it specially above
267 ...Object.fromEntries(
268 Object.entries(overrides || {}).filter(([key]) => key !== "due")
269 ),
270 };
271
272 // Create the task using the existing TaskService
273 // Disable defaults since ICS events have their own data
274 return await this.plugin.taskService.createTask(taskData, { applyDefaults: false });
275 } catch (error) {
276 const errorMessage = error instanceof Error ? error.message : String(error);
277 tasknotesLogger.error("Error creating task from ICS event:", {
278 category: "provider",
279 operation: "creating-task-ics-event",
280 details: { icsEventId: icsEvent.id, icsEventTitle: icsEvent.title },
281 error: errorMessage,

Callers 3

createTaskFromEventMethod · 0.80
createTaskDirectlyMethod · 0.80

Calls 9

computeDueFromICSEndMethod · 0.95
buildICSEventDetailsMethod · 0.95
getCurrentTimestampFunction · 0.90
errorMethod · 0.80
toUserFieldMethod · 0.65
createTaskMethod · 0.65
getSubscriptionsMethod · 0.45

Tested by

no test coverage detected