Skip to content

Commit 6d25454

Browse files
authored
feat: create notes using HackMD (#30)
* feat: create notes using HackMD * fixup! feat: create notes using HackMD
1 parent 7bfec01 commit 6d25454

11 files changed

Lines changed: 374 additions & 39 deletions

File tree

.github/ISSUE_TEMPLATE/meeting.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Extracted from **<%= agendaLabel %>** labelled issues and pull requests from **<
3131

3232
## Links
3333

34-
* Minutes:
34+
* Minutes: <%= meetingNotes || '' %>
3535

3636
### Joining the meeting
3737

.github/workflows/test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,6 @@ jobs:
5050
createWithin: P2D
5151
labels: meeting, test
5252
agendaLabel: meeting-agenda-test
53+
createNotes: true
5354
- name: clean up issue
5455
run: node ./test/_close-issue.js ${{ secrets.GITHUB_TOKEN }} ${{ steps.maker.outputs.issueNumber }}

action.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ inputs:
3131
description: 'A name of an issue template (found in .github/ISSUE_TEMPLATES)'
3232
default: 'meeting.md'
3333
required: true
34+
createNotes:
35+
description: 'Create meeting notes on HackMD'
36+
default: 'false'
37+
required: false
38+
notesUserTemplate:
39+
description: 'A name of an issue template (found in .github/meet)'
40+
default: 'notes.md'
41+
required: false
3442
outputs:
3543
issueNumber:
3644
description: 'If an issue was created, this will be its number'

lib/default-notes-template.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
'use strict'
2+
3+
module.exports = ({ agendaIssues, agendaLabel, owner, repo, issue }) => {
4+
return `
5+
# ${issue.title}
6+
7+
## Links
8+
9+
* **Recording**:
10+
* **GitHub Issue**: https://github.com/${owner}/${repo}/issues/${issue.number}
11+
12+
## Present
13+
14+
*
15+
16+
## Announcements
17+
18+
## Agenda
19+
20+
*Extracted from **${agendaLabel}** labelled issues and pull requests from the **${owner} org** prior to the meeting.
21+
22+
${agendaIssues.map((i) => {
23+
return `* ${i.title} [#${i.number}](${i.html_url})`
24+
}).join('\n')}
25+
26+
## Q&A, Other
27+
28+
`
29+
}

lib/default-template.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict'
22

3-
module.exports = ({ date, agendaIssues, agendaLabel, owner, repo }) => {
3+
module.exports = ({ date, agendaIssues, agendaLabel, meetingNotes, owner, repo }) => {
44
return `
55
## Date/Time
66
@@ -35,7 +35,7 @@ ${agendaIssues.map((i) => {
3535
3636
## Links
3737
38-
* Minutes:
38+
* Minutes: ${meetingNotes || ''}
3939
4040
### Joining the meeting
4141

lib/issues.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,17 @@ module.exports.create = async function (client, issue) {
1212
return resp
1313
}
1414

15+
module.exports.update = async function (client, issue) {
16+
const resp = await client.issues.update({
17+
owner: issue.owner,
18+
repo: issue.repo,
19+
issue_number: issue.issue_number,
20+
body: issue.body
21+
})
22+
23+
return resp
24+
}
25+
1526
module.exports.getMeetingIssues = async function (client, opts) {
1627
const resp = await client.issues.listForRepo({
1728
owner: opts.owner,

lib/meetings.js

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,37 @@ module.exports.createNextMeeting = async function (client, opts) {
1111
return issues.create(client, meetingToCreate)
1212
}
1313

14+
module.exports.setMeetingIssueBody = async function (client, opts) {
15+
const issue = await getNextIssue(client, opts)
16+
issue.body = typeof opts.template === 'function' ? opts.template(issue) : opts.template
17+
return issues.update(client, issue)
18+
}
19+
20+
async function getNextIssue (client, opts) {
21+
const now = opts.now || DateTime.utc()
22+
const date = getNextScheduledMeeting(opts.schedules, now)
23+
const title = typeof opts.issueTitle === 'function' ? opts.issueTitle({ date }) : opts.issueTitle
24+
25+
const issue = {
26+
owner: opts.owner,
27+
repo: opts.repo,
28+
title,
29+
date,
30+
agendaLabel: opts.agendaLabel,
31+
agendaIssues: opts.agendaIssues,
32+
labels: opts.labels,
33+
meetingNotes: opts.meetingNotes || '',
34+
issue_number: (opts.issue || {}).number || null,
35+
body: ''
36+
}
37+
return issue
38+
}
39+
1440
const shouldCreateNextMeetingIssue = module.exports.shouldCreateNextMeetingIssue = async function (client, opts = {}) {
1541
const now = opts.now || DateTime.utc()
1642
const createWithin = Duration.fromISO(opts.createWithin)
17-
const next = getNextScheduledMeeting(opts.schedules, now)
43+
const issue = getNextIssue(client, opts)
44+
const { date: next, title: nextIssueTitle } = issue
1845

1946
// Further out than the create within limit
2047
if (next > now.plus(createWithin)) {
@@ -27,7 +54,6 @@ const shouldCreateNextMeetingIssue = module.exports.shouldCreateNextMeetingIssue
2754
label: opts.labels
2855
})
2956

30-
const nextIssueTitle = typeof opts.issueTitle === 'function' ? opts.issueTitle({ date: next }) : opts.issueTitle
3157
const shouldCreate = !meetings.find((i) => {
3258
return i.title === nextIssueTitle
3359
})
@@ -36,25 +62,6 @@ const shouldCreateNextMeetingIssue = module.exports.shouldCreateNextMeetingIssue
3662
}
3763

3864
// Load issues for agenda
39-
const agendaLabel = opts.agendaLabel
40-
const agendaResp = await client.issues.listForRepo({
41-
owner: opts.owner,
42-
repo: opts.repo,
43-
state: 'open',
44-
labels: agendaLabel
45-
})
46-
47-
const issue = {
48-
owner: opts.owner,
49-
repo: opts.repo,
50-
title: nextIssueTitle,
51-
date: next,
52-
agendaLabel: agendaLabel,
53-
agendaIssues: agendaResp.data,
54-
labels: opts.labels,
55-
body: null
56-
}
57-
issue.body = typeof opts.template === 'function' ? opts.template(issue) : opts.template
5865
return issue
5966
}
6067

lib/notes.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
'use strict'
2+
3+
const { default: HackMD } = require('@hackmd/api')
4+
const defaultNotesTemplate = require('./default-notes-template')
5+
6+
module.exports.create = function createNote (notesTemplate, opts) {
7+
const note = typeof notesTemplate === 'function' ? notesTemplate(opts) : notesTemplate || defaultNotesTemplate(opts)
8+
const hackmd = new HackMD()
9+
10+
return hackmd.newNote(note)
11+
}
12+
13+
async function getNotesTemplate (client, opts) {
14+
const resp = await client.repos.getContents({
15+
owner: opts.owner,
16+
repo: opts.repo,
17+
path: `.github/meet/${opts.notesTemplate}`
18+
})
19+
if (resp.statusCode === 404) {
20+
return false
21+
}
22+
return Buffer.from(resp.data.content, resp.data.encoding).toString()
23+
}
24+
25+
module.exports.getNotesTemplate = getNotesTemplate

0 commit comments

Comments
 (0)