#javascript #express #github #github-api #probot
#javascript #экспресс #github #github-api #probot
Вопрос:
Возможно ли использовать Probot для создания проблемы при ответе с экспресс-маршрута? Я пробовал следующее, но их асинхронная функция не может получить доступ к context.github.
const createIssue = async function (issue, context) {
const owner = issue.owner; const repo = issue.repo; const title = issue.title; const body = issue.body; const assignees = issue.assignees; const labels = issue.labels
return context.github.issues.create({ owner, repo, title, body, labels, assignees })
}
const router = app.route('/robot')
router.use(require('express').static('public'))
router.get('/test', (req, res) => {
const issue = {
repo: 'reponame',
owner: 'ownername',
title: req.query.title,
labels: req.query.lab,
body: req.query.body,
assignees: req.query.as
}
createIssue(issue, context).then(
res.send('Success')
).catch(err => console.log(err))
})
Ответ №1:
Я думаю, это может быть то, что вы ищете: https://probot.github.io/api/latest/classes/application.html#auth
const createIssue = async function (issue, app) {
const github = await app.auth();
const owner = issue.owner; const repo = issue.repo; const title = issue.title; const body = issue.body; const assignees = issue.assignees; const labels = issue.labels
return github.issues.create({ owner, repo, title, body, labels, assignees })
}
const router = app.route('/robot')
router.use(require('express').static('public'))
router.get('/test', (req, res) => {
const issue = {
repo: 'reponame',
owner: 'ownername',
title: req.query.title,
labels: req.query.lab,
body: req.query.body,
assignees: req.query.as
}
const
createIssue(issue, app).then(
res.send('Success')
).catch(err => console.log(err))
})