Skip to content

[DO NOT MERGE] add HackMD integration #92

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 17 additions & 37 deletions create-node-meeting-artifacts.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ const child_process = require('child_process');
const GitHubApi = require("github");
const ghauth = require('ghauth');
const parser = require('properties-parser');
const gcal = require('google-calendar');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does removing the gcal integration remove the auto generation based on google calendar events?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, gcal was just unused

const googleAuth = require('google-auth-wrapper');
const gdriveWrapper = require('google-drive-wrapper');
const {createGitHubIssueCallback} = require('./lib/create-gh-issue');

const meetingGroup = process.argv[2] || 'tsc';

const authOptions = { configName: 'iojs-tools', scopes: [ 'user', 'repo' ] };
const repos = [];

let githubOrg = 'nodejs';

Expand Down Expand Up @@ -45,7 +44,9 @@ ghauth(authOptions, (err, authData) => {
meetingGroup));
const meetingProperties = parser.parse(baseMeetingInfo);

var meetingGroupForTag = meetingGroup;
const uploader = meetingProperties.USE_HACKMD ? require('./lib/hackmd') : require('./lib/google-docs');

let meetingGroupForTag = meetingGroup;
if (meetingProperties.AGENDA_TAG) {
meetingGroupForTag = meetingProperties.AGENDA_TAG.replace('-agenda', '');
}
Expand Down Expand Up @@ -116,41 +117,20 @@ ghauth(authOptions, (err, authData) => {
minutesDoc = minutesDoc.replace('$OBSERVERS$', observers);
const minutesDocName = path.join(__dirname, 'minutes_temp.txt');
fs.writeFileSync( minutesDocName, minutesDoc);

// upload the minutes doc
const wrapper = new gdriveWrapper(googleAuthToken, google, 'dummy' );
wrapper.getMetaForFilename('/nodejs-meetings', function(err, parentMeta) {
if (err !== null) {
console.log('Directory called "nodejs-meetings" does not exist, exiting');
process.exit(-1);
const githubIssueCallback = createGitHubIssueCallback(title, newIssue, meetingProperties, (err) => {
if (err) {
console.log('Failed with error:');
console.log(err);
process.exitCode = 1;
return;
}

wrapper.uploadFile(title, minutesDocName,
{ parent: parentMeta.id,
compress: false,
encrypt: false,
convert: true,
mimeType: 'application/vnd.google-apps.document' },
function(err, meta) {
if (err !== null) {
console.log('Failed to upload minutes file');
console.log(err);
} else {
// create the issue in github
newIssue = newIssue.toString().replace(
/\* \*\*Minutes Google Doc\*\*: <>/,
'* Minutes Google Doc: <https://docs.google.com/document/d/' + meta.id + '/edit>');
newIssue = newIssue.replace(/\* _Previous Minutes Google Doc: <>_/,'');
github.issues.create({
owner: meetingProperties.USER.replace(/"/g, ''),
repo: meetingProperties.REPO.replace(/"/g, ''),
title: title,
body: newIssue,
assignee: "mhdawson"
});
}
});
console.log('Success');
});

uploader.upload(minutesDocName, {
title, newIssue, meetingProperties, googleAuthToken, googleApi
}, githubIssueCallback);
}
});
});
Expand Down
20 changes: 20 additions & 0 deletions lib/create-gh-issue.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict';

/**
* Creates a callback function which accepts an issue `body` argument.
* `body` will be used in a new GitHub issue containing meeting information.
*/
exports.createGithubIssueCallback = (title, meetingProperties, done) => (err, body) => {
if (err) {
err.message = `Failed to upload minutes file:\n${err.message}`;
return done(err);
}
github.issues.create({
owner: meetingProperties.USER.replace(/"/g, ''),
repo: meetingProperties.REPO.replace(/"/g, ''),
title: title,
body,
assignee: 'mhdawson',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol @mhdawson

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah @mhdawson is the only one who can run this script 😄

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I'm the only one who could, but the setup required is non-trivial to do the first time.

});
done();
};
46 changes: 46 additions & 0 deletions lib/google-docs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
'use strict';

const gdriveWrapper = require('google-drive-wrapper');

/**
* Creates a new Google doc from the meeting template.
* Calls `done(err, body)` with the body of a to-be-created GitHub issue.
*/
exports.upload = (
minutesDocName,
{title, googleAuthToken, googleApi, newIssue} = {},
done
) => {
const wrapper = new gdriveWrapper(googleAuthToken, googleApi, 'dummy');
wrapper.getMetaForFilename('/nodejs-meetings', function (err, parentMeta) {
if (err !== null) {
return done(
new Error('Directory called "nodejs-meetings" does not exist, exiting')
);
}

wrapper.uploadFile(
title,
minutesDocName,
{
parent: parentMeta.id,
compress: false,
encrypt: false,
convert: true,
mimeType: 'application/vnd.google-apps.document',
},
(meta) => {
newIssue = newIssue
.toString()
.replace(
/\* \*\*Minutes Google Doc\*\*: <>/,
'* Minutes Google Doc: <https://docs.google.com/document/d/' +
meta.id +
'/edit>'
)
.replace(/\* _Previous Minutes Google Doc: <>_/, '');
done(null, newIssue);
}
);
});
};
44 changes: 44 additions & 0 deletions lib/hackmd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
'use strict';

const {execSync, spawnSync} = require('child_process');

/**
* Creates a new HackMD doc from the meeting template.
* Calls `done(err, body)` with the body of a to-be-created GitHub issue.
*
* For this to work, `process.env` must contain `CMD_CLI_ID=<email>` where `<email>` is
* a HackMD username, and `CMD_CLI_PASSWORD=<password>` where `<password>` is the HackMD
* user's password.
*
* @see https://npm.im/@hackmd/codimd-cli
*/
exports.upload = (filepath, {newIssue: body} = {}, done) => {
console.log('Logging in to HackMD...');
try {
// this places a token in ~/.codimd/cookies.json
spawnSync('node', ['node_modules/.bin/codimd-cli', 'login']);
} catch (err) {
return done(err);
}
console.log('Importing minutes doc...');
try {
const result = execSync(
`cat "${filepath}" | node_modules/.bin/codimd-cli`
).toString('utf8');
// the result will be a string containing a URL. grab it
const url = result.match(/(https:.+?)[\s\S]/)[1];
if (!url) {
return done(new Error(`Could not parse URL from codimd-cli result:\n${result}`));
}
body = body
.toString()
.replace(
/\* \*\*Minutes(?:[\s\S]+?)Doc\*\*: <>/,
`* Minutes HackMD Doc: ${url}`
)
.replace(/\* _Previous Minutes(?:[\s\S]+?)Doc: <>_/, '');
done(null, body);
} catch (err) {
done(err);
}
};
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
"name": "create-node-meeting-artifacts",
"version": "0.0.1",
"description": "Creates issue and minutes doc for node meeting",
"main": "index.js",
"main": "lib/create-node-meeting-artifacts.js",
"bin": {
"create-meeting": "./bin/create-meeting"
},
"dependencies": {
"@hackmd/codimd-cli": "^1.0.3",
"ghauth": "^3.2.1",
"github": "^11.0.0",
"google-auth-wrapper": "^0.5.0",
"google-calendar": "^1.3.2",
"google-drive-wrapper": "^0.6.0",
"make-node-meeting": "^1.0.11",
"node-meeting-agenda": "^1.0.4",
Expand Down
15 changes: 8 additions & 7 deletions templates/minutes_base_tooling
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
USE_HACKMD=1

# $TITLE$

## Links

* **Recording**:
* **Recording**: $RECORDING_URL$
* **GitHub Issue**: $GITHUB_ISSUE$
* **Minutes Google Doc**: $MINUTES_DOC$
* **Minutes Doc**: $MINUTES_DOC$

## Present

$INVITED$
$OBSERVERS$

## Agenda

## Announcements

*Extracted from **tooling-agenda** labelled issues and pull requests from the **nodejs org** prior to the meeting.
> Extracted from issues labeled `tooling-agenda` in the [Node.js Tooling Group issue tracker](https://github.com/nodejs/tooling/issues) prior to the meeting.

$AGENDA_CONTENT$

## Q&A, Other

## Upcoming Meetings

* **Node.js Foundation Calendar**: https://nodejs.org/calendar
Node.js Tooling Group meetings occur every two (2) weeks.

* See the [Node.js Foundation Calendar](https://nodejs.org/calendar)

Click `+GoogleCalendar` at the bottom right to add to your own Google calendar.