使用Probot根据快递路线的响应创建Github问题

时间:2019-03-22 16:01:58

标签: javascript express 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 个答案:

答案 0 :(得分:0)

我认为这可能是您要寻找的: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))
  })