Skip to content

Commit

Permalink
feat: create notes using HackMD (#30)
Browse files Browse the repository at this point in the history
* feat: create notes using HackMD

* fixup! feat: create notes using HackMD
  • Loading branch information
mmarchini authored Nov 19, 2020
1 parent 7bfec01 commit 6d25454
Show file tree
Hide file tree
Showing 11 changed files with 374 additions and 39 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/meeting.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Extracted from **<%= agendaLabel %>** labelled issues and pull requests from **<

## Links

* Minutes:
* Minutes: <%= meetingNotes || '' %>

### Joining the meeting

Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,6 @@ jobs:
createWithin: P2D
labels: meeting, test
agendaLabel: meeting-agenda-test
createNotes: true
- name: clean up issue
run: node ./test/_close-issue.js ${{ secrets.GITHUB_TOKEN }} ${{ steps.maker.outputs.issueNumber }}
8 changes: 8 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ inputs:
description: 'A name of an issue template (found in .github/ISSUE_TEMPLATES)'
default: 'meeting.md'
required: true
createNotes:
description: 'Create meeting notes on HackMD'
default: 'false'
required: false
notesUserTemplate:
description: 'A name of an issue template (found in .github/meet)'
default: 'notes.md'
required: false
outputs:
issueNumber:
description: 'If an issue was created, this will be its number'
Expand Down
29 changes: 29 additions & 0 deletions lib/default-notes-template.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'use strict'

module.exports = ({ agendaIssues, agendaLabel, owner, repo, issue }) => {
return `
# ${issue.title}
## Links
* **Recording**:
* **GitHub Issue**: https://github.com/${owner}/${repo}/issues/${issue.number}
## Present
*
## Announcements
## Agenda
*Extracted from **${agendaLabel}** labelled issues and pull requests from the **${owner} org** prior to the meeting.
${agendaIssues.map((i) => {
return `* ${i.title} [#${i.number}](${i.html_url})`
}).join('\n')}
## Q&A, Other
`
}
4 changes: 2 additions & 2 deletions lib/default-template.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

module.exports = ({ date, agendaIssues, agendaLabel, owner, repo }) => {
module.exports = ({ date, agendaIssues, agendaLabel, meetingNotes, owner, repo }) => {
return `
## Date/Time
Expand Down Expand Up @@ -35,7 +35,7 @@ ${agendaIssues.map((i) => {
## Links
* Minutes:
* Minutes: ${meetingNotes || ''}
### Joining the meeting
Expand Down
11 changes: 11 additions & 0 deletions lib/issues.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@ module.exports.create = async function (client, issue) {
return resp
}

module.exports.update = async function (client, issue) {
const resp = await client.issues.update({
owner: issue.owner,
repo: issue.repo,
issue_number: issue.issue_number,
body: issue.body
})

return resp
}

module.exports.getMeetingIssues = async function (client, opts) {
const resp = await client.issues.listForRepo({
owner: opts.owner,
Expand Down
49 changes: 28 additions & 21 deletions lib/meetings.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,37 @@ module.exports.createNextMeeting = async function (client, opts) {
return issues.create(client, meetingToCreate)
}

module.exports.setMeetingIssueBody = async function (client, opts) {
const issue = await getNextIssue(client, opts)
issue.body = typeof opts.template === 'function' ? opts.template(issue) : opts.template
return issues.update(client, issue)
}

async function getNextIssue (client, opts) {
const now = opts.now || DateTime.utc()
const date = getNextScheduledMeeting(opts.schedules, now)
const title = typeof opts.issueTitle === 'function' ? opts.issueTitle({ date }) : opts.issueTitle

const issue = {
owner: opts.owner,
repo: opts.repo,
title,
date,
agendaLabel: opts.agendaLabel,
agendaIssues: opts.agendaIssues,
labels: opts.labels,
meetingNotes: opts.meetingNotes || '',
issue_number: (opts.issue || {}).number || null,
body: ''
}
return issue
}

const shouldCreateNextMeetingIssue = module.exports.shouldCreateNextMeetingIssue = async function (client, opts = {}) {
const now = opts.now || DateTime.utc()
const createWithin = Duration.fromISO(opts.createWithin)
const next = getNextScheduledMeeting(opts.schedules, now)
const issue = getNextIssue(client, opts)
const { date: next, title: nextIssueTitle } = issue

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

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

// Load issues for agenda
const agendaLabel = opts.agendaLabel
const agendaResp = await client.issues.listForRepo({
owner: opts.owner,
repo: opts.repo,
state: 'open',
labels: agendaLabel
})

const issue = {
owner: opts.owner,
repo: opts.repo,
title: nextIssueTitle,
date: next,
agendaLabel: agendaLabel,
agendaIssues: agendaResp.data,
labels: opts.labels,
body: null
}
issue.body = typeof opts.template === 'function' ? opts.template(issue) : opts.template
return issue
}

Expand Down
25 changes: 25 additions & 0 deletions lib/notes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
'use strict'

const { default: HackMD } = require('@hackmd/api')
const defaultNotesTemplate = require('./default-notes-template')

module.exports.create = function createNote (notesTemplate, opts) {
const note = typeof notesTemplate === 'function' ? notesTemplate(opts) : notesTemplate || defaultNotesTemplate(opts)
const hackmd = new HackMD()

return hackmd.newNote(note)
}

async function getNotesTemplate (client, opts) {
const resp = await client.repos.getContents({
owner: opts.owner,
repo: opts.repo,
path: `.github/meet/${opts.notesTemplate}`
})
if (resp.statusCode === 404) {
return false
}
return Buffer.from(resp.data.content, resp.data.encoding).toString()
}

module.exports.getNotesTemplate = getNotesTemplate
Loading

0 comments on commit 6d25454

Please sign in to comment.