如何在 GitHub 上使用 (pro)bot 编辑文件?

问题描述

我正在使用 probot 框架构建一个 GitHub bot 来编辑存储库的 README.md,但到目前为止我找不到使用 probot 编辑文件方法,也没有使用任何其他 GitHub机器人框架。

那么是否可以在 GitHub 上使用机器人编辑文件?如果是,请给我一些教程链接或参考资料。

例如,我想在每次提交时在 README.md 的末尾添加特定行。

解决方法

我想你可以在这个 Github issue 中找到一些信息:https://github.com/octokit/rest.js/issues/845#issuecomment-386108187

如果您在实施细节方面需要帮助,我认为您可以查找 Octokit 存储库中打开的现有问题或讨论:https://github.com/octokit/rest.js/discussions/categories/q-a

如果您还需要这方面的帮助,请告诉我!

,

我正在添加有关如何使用 probot 的代码,我是在 @OscarDOM 的回答的帮助下完成的,
Index.ts

import { Probot } from "probot";

export = ({ app }: { app: Probot }) => {
  app.on("issues.opened",async (context) => { // You can change the "issues.opened" according to your use
    var sha;
    var a = Buffer.from("ABCd");
    var content = a.toString("base64");
    await context.octokit.repos
      .getContent({
        owner: "your_github_username",repo: "repo_name",path: "file_path",})
      .then((result) => {
        sha = result.data.sha;
      });
    await context.octokit.repos.createOrUpdateFileContents({
      owner: "your_github_username",message: "hilo",content: content,sha: sha,});
  });