-
-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathcreate-node-meeting-artifacts.mjs
More file actions
144 lines (122 loc) · 4.23 KB
/
Copy pathcreate-node-meeting-artifacts.mjs
File metadata and controls
144 lines (122 loc) · 4.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/usr/bin/env node
/**
* Node.js Meeting Artifacts Creator
*
* Creates a GitHub issue and a HackMD minutes document for a Node.js meeting,
* driven entirely by a JSON config in meetings/<group>.meeting.json.
*
* Usage:
* npx . tsc
* node --env-file=.env create-node-meeting-artifacts.mjs tsc --dry-run
*/
import { Command } from 'commander';
import * as calendar from './src/calendar.mjs';
import environmentConfig from './src/config.mjs';
import * as github from './src/github.mjs';
import * as hackmd from './src/hackmd.mjs';
import * as meetings from './src/meeting.mjs';
const program = new Command();
program
.argument('<group>', 'Meeting group (the meetings/<group>.meeting.json stem)')
.option('--dry-run', 'Show output without creating/updating anything', false)
.option('--force', 'Create a new issue even if one already exists', false)
.option('--verbose', 'Show debug output')
.parse(process.argv);
// All dates are computed and rendered in UTC.
process.env.TZ = 'UTC';
/** @type {import('./src/types.d.ts').AppConfig} */
const config = {
...environmentConfig,
...program.opts(),
meetingGroup: program.args[0],
};
// Load the meeting configuration from its JSON file.
const meeting = await meetings.load(config.meetingGroup);
console.debug('Meeting config loaded', meeting);
// Initialize API clients.
const githubClient = github.createGitHubClient(config);
const hackmdClient = hackmd.createHackMDClient(config, meeting);
// Collect agenda issues for the meeting.
const agendaIssues = await github.getAgendaIssues(githubClient, meeting);
console.debug('Found agenda issues', agendaIssues);
if (config.dryRun) {
const now = new Date();
const title = meetings.generateMeetingTitle(meeting, now);
const issueContent = await meetings.render(
meetings.createTemplateContext(
meeting,
now,
agendaIssues,
[{ title: 'Minutes', url: 'https://hackmd.io/<dry-run>' }],
{ title }
)
);
console.log(issueContent);
process.exit(0);
}
// Find the next meeting occurrence in the calendar.
const events = await calendar.getEventsFromCalendar(meeting.calendar.url);
const meetingDate = await calendar.findNextMeetingDate(events, meeting);
console.debug('Next meeting date', meetingDate);
// If no meeting is found, exit gracefully (expected for non-weekly meetings).
if (!meetingDate) {
const [weekStart, weekEnd] = calendar.getNextWeek();
console.log(
`No meeting found for ${meeting.name} ` +
`in the next week (${weekStart.toISOString().split('T')[0]} to ${weekEnd.toISOString().split('T')[0]}). ` +
`This is expected for bi-weekly meetings or meetings that don't occur every week.`
);
process.exit(0);
}
// Build the meeting title.
const meetingTitle = meetings.generateMeetingTitle(meeting, meetingDate);
console.debug('Meeting title', meetingTitle);
// Create (or fetch) the HackMD minutes document and resolve its link.
const hackmdNote = await hackmd.getOrCreateMeetingNotesDocument(
hackmdClient,
meetingTitle,
config
);
const minutesDocLink =
hackmdNote.publishLink || `https://hackmd.io/${hackmdNote.id}`;
console.debug('HackMD document created/retrieved', minutesDocLink);
// Render and publish the GitHub issue.
const issueContent = await meetings.render(
meetings.createTemplateContext(
meeting,
meetingDate,
agendaIssues,
[{ title: 'Minutes', url: minutesDocLink }],
{ title: meetingTitle }
)
);
const githubIssue = await github.createOrUpdateGitHubIssue(
githubClient,
config,
meeting,
meetingTitle,
issueContent
);
console.debug('GitHub issue created/updated', githubIssue.html_url);
// Render the minutes (identical format, plus a back-link to the issue) and
// store it in the HackMD document.
const minutesContent = await meetings.render(
meetings.createTemplateContext(
meeting,
meetingDate,
agendaIssues,
[
{ title: 'Minutes', url: minutesDocLink },
{ title: 'GitHub Issue', url: githubIssue.html_url },
],
{ isMinutes: true, title: meetingTitle }
)
);
await hackmd.updateMeetingNotesDocument(
hackmdClient,
hackmdNote.id,
minutesContent
);
// Output success information with links.
console.log(`Created GitHub issue: ${githubIssue.html_url}`);
console.log(`Created HackMD document: ${minutesDocLink}`);