我很难在用类型记录编写的probot上编写自定义HTTP路由。
文档中唯一的示例是纯JS,但我不知道如何将其转换为TS。
module.exports = (app, { getRouter }) => {
// Get an express router to expose new HTTP endpoints
const router = getRouter("/my-app");
// Use any middleware
router.use(require("express").static("public"));
// Add a new route
router.get("/hello-world", (req, res) => {
res.send("Hello World");
});
};发布于 2022-04-27 17:46:07
这应该能起作用:
import { ApplicationFunctionOptions, Probot, } from "probot"
export default (app: Probot, { getRouter }: ApplicationFunctionOptions) => {
if (!getRouter) return
const router = getRouter("/my-app");
router.use(require("express").static("public"));
// Add a new route
router.get("/hello-world", (req, res) => {
res.send("Hello World");
});
}在ApplicationFunctionOptions中,getRouter是可选的。这就是为什么我在函数的开头添加了一个快速检查。
发布于 2022-04-27 17:47:24
我设法让它发挥作用:
import {ApplicationFunctionOptions, Probot} from "probot";
export = (app: Probot, { getRouter }: ApplicationFunctionOptions) => {
// Get an express router to expose new HTTP endpoints
if (getRouter) {
const router = getRouter()
// Use any middleware
router.use(require("express").static("public"));
// Add a new route
// @ts-ignore
router.get("/hello-world", (req: any, res: any) => {
res.send("Hello World");
});
}
app.on("issues.opened", async (context) => {
const issueComment = context.issue({
body: "Thanks for opening this issue!",
});
await context.octokit.issues.createComment(issueComment);
});
...发布于 2022-10-08 13:50:51
你可以用axios。
例如:
import axios from "axios"
export class GithubServices {
public async writeCommentPR(repositoryName: string, numberPR: number, comment: string) {
try {
const url = `https://api.github.com/repos/${repositoryName}/issues/${numberPR}/comments`
const options = {
headers: {
Authorization: process.env.GITHUB_PAT || "",
Accept: 'application/vnd.github.v3+json',
ContentType: "application/json"
}
}
const payload = {
"body": comment
};
const response = await axios.post(
url,
payload,
options
)
} catch (error) {
console.log(error)
}
}https://stackoverflow.com/questions/72032934
复制相似问题