Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export async function prNumberToTitleByApi (
org: string,
repo: string,
pr: number,
): Promise {
const fileBox = FileBox.fromUrl(
// https://stackoverflow.com/a/34601082/1123955
`https://api.github.com/repos/${org}/${repo}/pulls/${pr}`,
'pr.json',
{
'User-Agent': 'FileBox',
}
)
const prJsonText = (await fileBox.toBuffer()).toString()
// console.log(prJsonText)
const prJson = JSON.parse(prJsonText)
const prTitle = prJson.title as string
return prTitle
}
export async function prNumberToTitle (
org: string,
repo: string,
pr: number,
): Promise {
const fileBox = FileBox.fromUrl(
`https://github.com/${org}/${repo}/pull/${pr}`,
'pr.json',
)
const prHtml = (await fileBox.toBuffer()).toString()
// console.log(prHtml)
const matches = prHtml.match(/.+?<title>(.+?) by .+? · Pull Request #\d+.+?<\/title>/si)
if (!matches) {
throw new Error('no matches for pr title')
}
const prTitle = matches[1]
return prTitle
}
</title>
/* && !msg.self() */
) {
console.info('Message discarded because it does not match ding/ping/bing/code')
return
}
/**
* 1. reply 'dong'
*/
await msg.say('dong')
console.info('REPLY: dong')
/**
* 2. reply image(qrcode image)
*/
const fileBox = FileBox.fromUrl('https://chatie.io/wechaty/images/bot-qr-code.png')
await msg.say(fileBox)
console.info('REPLY: %s', fileBox.toString())
/**
* 3. reply 'scan now!'
*/
await msg.say([
'Join Wechaty Developers Community\n\n',
'Scan now, because other Wechaty developers want to talk with you too!\n\n',
'(secret code: wechaty)',
].join(''))
}