我正在尝试使用GitHub操作在拉取请求中插入常规评论,但似乎无法正确实现。 Octokit,这个底层库,允许您为PR创建reviewComments,但这些是指提交,而不是我想要的简单评论。我想我可以使用octokit.issues.createComment
来实现。然而,似乎不起作用。
这是代码:
import * as core from '@actions/core';
const {GitHub, context} = require('@actions/github')
const parse = require('parse-diff')
async function run() {
try {
// get information on everything
const token = core.getInput('github-token', {required: true})
const github = new GitHub(token, {} )
console.log( context )
const PR_number = context.payload.pull_request.number
// Check if the body contains required string
const bodyContains = core.getInput('bodyContains')
if ( context.payload.pull_request.body.indexOf( bodyContains) < 0 ) {
core.setFailed("The body of the PR does not contain " + bodyContains);
console.log( "Actor " + context.actor + " pr number " PR_number)
const result = await github.issues.createComment({
owner: context.actor,
repo: context.payload.repository.full_name,
issue_number: PR_number,
body: "We need to have the word " + bodyContains + " in the body of the pull request"
});
console.log(result)
} // more irrelevant stuff below
}}
这似乎只是返回“未找到”。我似乎找不出它是否是类型问题,还是其他问题。理论上,所有者,存储库和问题编号以及正文应该是正确的,并且已经正确地打印了。任何帮助都将不胜感激。这可能是GitHub API领域中更一般的问题,而GitHub操作仅是上下文,所以我可能是错的。