Skip to content

Commit 0bdee79

Browse files
committed
chore: fixed some things regarding apis
1 parent 9b0c37c commit 0bdee79

File tree

4 files changed

+80
-35
lines changed

4 files changed

+80
-35
lines changed

create-node-meeting-artifacts.mjs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,18 @@ import * as meetings from './src/meeting.mjs';
1818
// Step 1: Application configuration
1919
const config = getConfig();
2020

21-
// Step 2: Initialize Google Calendar client with API Key
21+
// Step 2: Initialize HackMD client with meeting configuration
22+
const hackmdClient = hackmd.createHackMDClient(config);
23+
24+
// Step 3: Initialize Google Calendar client with API Key
2225
const calendarClient = google.createCalendarClient(config.google);
2326

24-
// Step 3: Initialize GitHub client
27+
// Step 4: Initialize GitHub client
2528
const githubClient = github.createGitHubClient(config);
2629

27-
// Step 4: Read meeting configuration from templates
30+
// Step 5: Read meeting configuration from templates
2831
const meetingConfig = await meetings.readMeetingConfig(config);
2932

30-
// Step 5: Initialize HackMD client with meeting configuration
31-
const hackmdClient = hackmd.createHackMDClient(config, meetingConfig);
32-
3333
// Step 6: Find next meeting event in calendar
3434
const event = await google.findNextMeetingEvent(calendarClient, meetingConfig);
3535

@@ -56,11 +56,12 @@ const meetingAgenda = meetings.generateMeetingAgenda(
5656
meetingConfig
5757
);
5858

59-
// Step 11: Create HackMD document with meeting notes
59+
// Step 11: Create HackMD document with meeting notes and tags
6060
const hackmdNote = await hackmd.createMeetingNotesDocument(
6161
hackmdClient,
6262
meetingTitle,
63-
''
63+
'',
64+
meetingConfig
6465
);
6566

6667
// Step 12: Get the HackMD document link
@@ -76,7 +77,7 @@ const issueContent = await meetings.generateMeetingIssue(
7677
minutesDocLink
7778
);
7879

79-
// Step 14: Create GitHub issue with HackMD link
80+
// // Step 14: Create GitHub issue with HackMD link
8081
const githubIssue = await github.createGitHubIssue(
8182
githubClient,
8283
meetingConfig,
@@ -98,7 +99,8 @@ const minutesContent = await meetings.generateMeetingMinutes(
9899
await hackmd.updateMeetingNotesDocument(
99100
hackmdClient,
100101
hackmdNote.id,
101-
minutesContent
102+
minutesContent,
103+
meetingConfig
102104
);
103105

104106
// Output success information with links

global.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55

66
import type { calendar_v3 } from '@googleapis/calendar';
77
import type { RestEndpointMethodTypes } from '@octokit/rest';
8-
import type { HackMDAPI } from '@hackmd/api';
8+
import type { API } from '@hackmd/api';
99
import type { SingleNote } from '@hackmd/api/dist/type.d.ts';
1010

1111
declare global {
1212
// Google API type aliases
1313
type CalendarEvent = calendar_v3.Schema$Event;
1414
type CalendarClient = calendar_v3.Calendar;
15-
type HackMDClient = HackMDAPI;
15+
type HackMDClient = API;
1616
type HackMDNote = SingleNote;
1717

1818
// GitHub API type aliases

src/google.mjs

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { calendar } from '@googleapis/calendar';
22

3-
import { TIME_CONSTANTS } from './constants.mjs';
4-
53
/**
64
* Creates an authenticated Google Calendar client using API Key
75
* @param {import('./types.d.ts').GoogleConfig} gConfig - Google configuration object
@@ -11,21 +9,33 @@ export const createCalendarClient = ({ apiKey: auth }) =>
119
calendar({ version: 'v3', auth });
1210

1311
/**
14-
* Finds the next meeting event in Google Calendar within the next week
12+
* Finds the next meeting event in Google Calendar for the current week
1513
* @param {import('@googleapis/calendar').calendar_v3.Calendar} calendarClient - Google Calendar client
1614
* @param {import('./types.d.ts').MeetingConfig} meetingConfig - Meeting configuration object
1715
* @returns {Promise<CalendarEvent>} Calendar event object
1816
*/
1917
export const findNextMeetingEvent = async (calendarClient, meetingConfig) => {
2018
const now = new Date();
2119

22-
const nextWeek = new Date(now.getTime() + TIME_CONSTANTS.WEEK_IN_MS);
20+
// Calculate the start of the current week (Saturday 00:00:00 UTC)
21+
// This handles the scenario where we want a full week from Saturday to Friday
22+
const daysSinceStartOfWeek = (now.getUTCDay() + 1) % 7; // Saturday = 0, Sunday = 1, ..., Friday = 6
23+
const weekStart = new Date(now);
24+
25+
weekStart.setUTCDate(now.getUTCDate() - daysSinceStartOfWeek);
26+
weekStart.setUTCHours(0, 0, 0, 0);
27+
28+
// Calculate the end of the week (Friday 23:59:59 UTC)
29+
const weekEnd = new Date(weekStart);
30+
31+
weekEnd.setUTCDate(weekStart.getUTCDate() + 6);
32+
weekEnd.setUTCHours(23, 59, 59, 999);
2333

2434
// Search for events in the specified calendar using the filter text
2535
const response = await calendarClient.events.list({
2636
calendarId: meetingConfig.properties.CALENDAR_ID?.replace(/"/g, ''),
27-
timeMin: now.toISOString(),
28-
timeMax: nextWeek.toISOString(),
37+
timeMin: weekStart.toISOString(),
38+
timeMax: weekEnd.toISOString(),
2939
singleEvents: true,
3040
// Replace spaces with dots for Google Calendar search compatibility
3141
q: meetingConfig.properties.CALENDAR_FILTER?.replace(/"/g, '').replace(
@@ -36,7 +46,11 @@ export const findNextMeetingEvent = async (calendarClient, meetingConfig) => {
3646

3747
// Ensure we found at least one event
3848
if (!response.data.items || response.data.items.length === 0) {
39-
throw new Error('Could not find calendar event for the next week');
49+
throw new Error(
50+
`No meeting found for ${meetingConfig?.properties?.GROUP_NAME || 'this group'} ` +
51+
`in the current week (${weekStart.toISOString().split('T')[0]} to ${weekEnd.toISOString().split('T')[0]}). ` +
52+
`This is expected for bi-weekly meetings or meetings that don't occur every week.`
53+
);
4054
}
4155

4256
// Return the first (next) event found

src/hackmd.mjs

Lines changed: 45 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,36 +5,65 @@ import { HACKMD_DEFAULT_PERMISSIONS } from './constants.mjs';
55
/**
66
* Creates a HackMD API client
77
* @param {import('./types.d.ts').AppConfig} config - Application configuration
8-
* @param {import('./types.d.ts').MeetingConfig} meetingConfig - Meeting configuration
98
* @returns {HackMDClient} Configured HackMD API client
109
*/
11-
export const createHackMDClient = ({ hackmd: { apiToken } }, meetingConfig) => {
12-
// Use team-specific API endpoint if teamName is provided in meeting config
13-
const teamName = meetingConfig.properties.HACKMD_TEAM_NAME;
14-
15-
const baseURL = teamName
16-
? `https://api.hackmd.io/v1/teams/${teamName}`
17-
: 'https://api.hackmd.io/v1';
18-
19-
return new HackMDAPI(apiToken, baseURL);
10+
export const createHackMDClient = ({ hackmd: { apiToken } }) => {
11+
return new HackMDAPI(apiToken);
2012
};
2113

2214
/**
23-
* Creates a new meeting notes document in HackMD
15+
* Creates a new meeting notes document in HackMD with appropriate tags
2416
* @param {HackMDAPI} hackmdClient - HackMD API client
2517
* @param {string} title - Document title
2618
* @param {string} content - Document content in Markdown
19+
* @param {import('./types.d.ts').MeetingConfig} meetingConfig - Meeting configuration for tags
2720
* @returns {Promise<HackMDNote>} Created note data with ID and URLs
2821
*/
29-
export const createMeetingNotesDocument = (hackmdClient, title, content) =>
30-
hackmdClient.createNote({ title, content, ...HACKMD_DEFAULT_PERMISSIONS });
22+
export const createMeetingNotesDocument = (
23+
hackmdClient,
24+
title,
25+
content,
26+
meetingConfig
27+
) => {
28+
const meetingTag =
29+
meetingConfig?.properties?.GROUP_NAME ??
30+
meetingConfig?.properties?.AGENDA_TAG;
31+
32+
const teamName = meetingConfig?.properties?.HACKMD_TEAM_NAME;
33+
34+
const noteOptions = {
35+
title,
36+
content,
37+
tags: [meetingTag, 'Meetings'],
38+
...HACKMD_DEFAULT_PERMISSIONS,
39+
};
40+
41+
if (teamName) {
42+
return hackmdClient.createTeamNote(teamName, noteOptions);
43+
}
44+
45+
return hackmdClient.createNote(noteOptions);
46+
};
3147

3248
/**
33-
* Updates an existing meeting notes document in HackMD
49+
* Updates an existing meeting notes document in HackMD with retry logic
3450
* @param {HackMDClient} hackmdClient - HackMD API client
3551
* @param {string} noteId - HackMD note ID
3652
* @param {string} content - Updated document content in Markdown
53+
* @param {import('./types.d.ts').MeetingConfig} meetingConfig - Meeting configuration for team context
3754
* @returns {Promise<HackMDNote>} Updated note data
3855
*/
39-
export const updateMeetingNotesDocument = (hackmdClient, noteId, content) =>
40-
hackmdClient.updateNote(noteId, { content });
56+
export const updateMeetingNotesDocument = (
57+
hackmdClient,
58+
noteId,
59+
content,
60+
meetingConfig
61+
) => {
62+
const teamName = meetingConfig?.properties?.HACKMD_TEAM_NAME;
63+
64+
if (teamName) {
65+
return hackmdClient.updateTeamNote(teamName, noteId, { content });
66+
}
67+
68+
return hackmdClient.updateNote(noteId, { content });
69+
};

0 commit comments

Comments
 (0)