-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
198 additions
and
274 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,89 @@ | ||
// const chrono = require('chrono-node') | ||
// | ||
// const matcher = /^remind @?([^\s]+)(?: to )?(.*)$/ | ||
// | ||
// const parser = new chrono.Chrono() | ||
// parser.refiners.push(require('./lib/refiners/start-of-day')) | ||
// | ||
// const options = { | ||
// forwardDate: true, | ||
// startOfDay: 9 | ||
// } | ||
// | ||
// module.exports = (input, from) => { | ||
// const match = input.match(matcher) | ||
// if (!match) { | ||
// // This doesn't look like a reminder, so bail early | ||
// return null | ||
// } | ||
// | ||
// // Pull out the initial matches | ||
// let [, who, what] = match | ||
// | ||
// // Use chrono to extract the `when` from the `what` | ||
// const when = parser.parse(what, from, options) | ||
// | ||
// if (when.length < 1) { | ||
// // What kind of reminder doesn't have a date? | ||
// return null | ||
// } | ||
// | ||
// // Remove any time expressions from the `what` | ||
// when.forEach(w => { | ||
// what = what.replace(w.text, '') | ||
// }) | ||
// | ||
// // Clean up whitespace and common connecting words | ||
// what = what.trim() | ||
// what = what.replace(/^(to|that) /, '').replace(/ on$/, '') | ||
// | ||
// return {who, what, when: when[0].start.date()} | ||
const nlp = require('compromise') | ||
|
||
const validContributionTypes = [ | ||
'blog', | ||
'bug', | ||
'code', | ||
'design', | ||
'doc', | ||
'eventOrganizing', | ||
'example', | ||
'financial', | ||
'fundingFinding', | ||
'ideas', | ||
'infra', | ||
'platform', | ||
'plugin', | ||
'question', | ||
'review', | ||
'security', | ||
'talk', | ||
'test', | ||
'tool', | ||
'translation', | ||
'tutorial', | ||
'userTesting', | ||
'video', | ||
] | ||
|
||
// TODO | ||
// const contributionTypeMappings = { | ||
// 'event organizing': 'eventOrganizing', | ||
// 'funding finding': 'fundingFinding', | ||
// 'user testing': 'user testing', | ||
// } | ||
|
||
const Contributions = {} | ||
|
||
validContributionTypes.forEach(type => { | ||
Contributions[type] = 'Contribution' | ||
}) | ||
|
||
const plugin = { | ||
words: { | ||
...Contributions, | ||
}, | ||
patterns: { | ||
// 'add #person for #Contribution': 'AddContributor', | ||
// "i can't (log|sign|get) in to my? #Software": 'LoginIssue' | ||
}, | ||
} | ||
nlp.plugin(plugin) | ||
|
||
function parseAddComment(doc, action) { | ||
const who = doc.match(`${action} [.]`).data()[0].normal | ||
|
||
// TODO: handle plurals (e.g. some said docs) | ||
const contributions = doc | ||
.match('#Contribution') | ||
.data() | ||
.map(data => { | ||
// This removes whitespace, commas etc | ||
return data.normal | ||
}) | ||
|
||
return { | ||
action: 'add', | ||
who, | ||
contributions, | ||
} | ||
} | ||
|
||
function parseComment(message) { | ||
const doc = nlp(message) | ||
|
||
if (doc.verbs().data().length === 0) { | ||
return {} | ||
} | ||
|
||
const action = doc.verbs().data()[0].normal | ||
if (action === 'add') { | ||
return parseAddComment(doc, action) | ||
} | ||
|
||
return { | ||
action, | ||
} | ||
} | ||
|
||
module.exports = parseComment |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,111 +1,28 @@ | ||
describe('parse-comment', () => { | ||
test('Example test', () => { | ||
expect(true).toBe(true) | ||
const parseComment = require('../../../src/utils/parse-comment') | ||
const { GIHUB_BOT_NAME } = require('../../../src//utils/settings') | ||
|
||
describe('parseComment', () => { | ||
test('Basic intent to add', () => { | ||
expect( | ||
parseComment( | ||
`@${GIHUB_BOT_NAME} please add jakebolam for doc, infra and code`, | ||
), | ||
).toEqual({ | ||
action: 'add', | ||
who: 'jakebolam', | ||
contributions: ['doc', 'infra', 'code'], | ||
}) | ||
}) | ||
// | ||
// test('Basic intent to add (with plurals)', () => { | ||
// expect( | ||
// parseComment( | ||
// `@${GIHUB_BOT_NAME} please add jakebolam for docs, infra and code`, | ||
// ), | ||
// ).toEqual({ | ||
// action: 'add', | ||
// who: 'jakebolam', | ||
// contributions: ['doc', 'infra', 'code'], | ||
// }) | ||
// }) | ||
}) | ||
|
||
// process.env.TZ = 'UTC' | ||
// | ||
// const expect = require('expect') | ||
// const parseReminder = require('..') | ||
// | ||
// // All time expressions will be relative to Wednesday, July 5 at 4:03:02.0 UTC | ||
// const REFERENCE_DATE = new Date(2017, 6, 5, 4, 3, 2, 0) | ||
// | ||
// describe('parse-reminder', () => { | ||
// const examples = { | ||
// 'nothing to see here': null, | ||
// | ||
// 'remind me nope': null, | ||
// | ||
// 'remind me to call the doctor tomorrow': { | ||
// who: 'me', when: new Date(2017, 6, 6, 9, 0, 0, 0), what: 'call the doctor' | ||
// }, | ||
// | ||
// 'remind me to send invites at 3pm tomorrow': { | ||
// who: 'me', when: new Date(2017, 6, 6, 15, 0, 0, 0), what: 'send invites' | ||
// }, | ||
// | ||
// 'remind me 8/28 to wish Jamie happy birthday': { | ||
// who: 'me', when: new Date(2017, 7, 28, 9, 0, 0, 0), what: 'wish Jamie happy birthday' | ||
// }, | ||
// | ||
// 'remind me to wish Jamie happy birthday on 8/28': { | ||
// who: 'me', when: new Date(2017, 7, 28, 9, 0, 0, 0), what: 'wish Jamie happy birthday' | ||
// }, | ||
// | ||
// 'remind me in 10 minutes to change the laundry': { | ||
// who: 'me', when: new Date(2017, 6, 5, 4, 13, 2, 0), what: 'change the laundry' | ||
// }, | ||
// | ||
// 'remind me tomorrow 10 PM to eat': { | ||
// who: 'me', when: new Date(2017, 6, 6, 22, 0, 0, 0), what: 'eat' | ||
// }, | ||
// | ||
// 'remind me on 18 Feb to be alive': { | ||
// who: 'me', when: new Date(2018, 1, 18, 9, 0, 0, 0), what: 'be alive' | ||
// }, | ||
// | ||
// 'remind me Tuesday to watch pogo': { | ||
// who: 'me', when: new Date(2017, 6, 11, 9, 0, 0, 0), what: 'watch pogo' | ||
// }, | ||
// | ||
// 'remind me Tuesday': { | ||
// who: 'me', when: new Date(2017, 6, 11, 9, 0, 0, 0), what: '' | ||
// }, | ||
// | ||
// 'remind me to go to the dentist on Aug 4 at 3': { | ||
// // FIXME: add refiner to prefer work hours for times without am/pm | ||
// who: 'me', when: new Date(2017, 7, 4, 3, 0, 0, 0), what: 'go to the dentist' | ||
// }, | ||
// | ||
// 'remind me to followup with Kathy in 2 weeks': { | ||
// who: 'me', when: new Date(2017, 6, 19, 9, 0, 0, 0), what: 'followup with Kathy' | ||
// }, | ||
// | ||
// 'remind me in 2 weeks to followup with Kathy': { | ||
// who: 'me', when: new Date(2017, 6, 19, 9, 0, 0, 0), what: 'followup with Kathy' | ||
// }, | ||
// | ||
// 'remind me at 4:00 to check in with Dan': { | ||
// // FIXME: fix future refiner to work with times later in the day | ||
// who: 'me', when: new Date(2017, 6, 5, 4, 0, 0, 0), what: 'check in with Dan' | ||
// }, | ||
// | ||
// 'remind me 10am to go to work': { | ||
// // FIXME: fix future refiner to work with times later in the day | ||
// who: 'me', when: new Date(2017, 6, 5, 10, 0, 0, 0), what: 'go to work' | ||
// }, | ||
// | ||
// 'remind me that the oil needs changed on Oct 4': { | ||
// who: 'me', when: new Date(2017, 9, 4, 9, 0, 0, 0), what: 'the oil needs changed' | ||
// }, | ||
// | ||
// 'remind me next Friday to open the pod bay doors': { | ||
// who: 'me', when: new Date(2017, 6, 14, 9, 0, 0, 0), what: 'open the pod bay doors' | ||
// }, | ||
// | ||
// 'remind me tomorrow at noon to buy the new iPhone': { | ||
// who: 'me', when: new Date(2017, 6, 6, 12, 0, 0, 0), what: 'buy the new iPhone' | ||
// }, | ||
// | ||
// 'remind someone to have coffee tomorrow at noon': { | ||
// who: 'someone', when: new Date(2017, 6, 6, 12, 0, 0, 0), what: 'have coffee' | ||
// }, | ||
// | ||
// 'remind @meaku to have coffee tomorrow at noon': { | ||
// who: 'meaku', when: new Date(2017, 6, 6, 12, 0, 0, 0), what: 'have coffee' | ||
// }, | ||
// | ||
// 'remind @probot/everyone to have coffee tomorrow at noon': { | ||
// who: 'probot/everyone', when: new Date(2017, 6, 6, 12, 0, 0, 0), what: 'have coffee' | ||
// } | ||
// } | ||
// | ||
// // eslint-disable-next-line guard-for-in | ||
// for (const example in examples) { | ||
// it(`parses "${example}"`, () => { | ||
// expect(parseReminder(example, REFERENCE_DATE)).toEqual(examples[example]) | ||
// }) | ||
// } | ||
// }) |
Oops, something went wrong.