小编kro*_*c97的帖子

使用 POST 请求触发 Github 操作(Github REST API)

我有一个托管在 GitHub 组织中的私有 GitHub 存储库。\n该存储库包含带有选项的 GitHub 操作workflow_dispatch\n(参见GitHub 文档)。

\n

操作 YAML 文件摘录:

\n
on:\n  # Allows you to run this workflow manually from the Actions tab\n  workflow_dispatch:\n\njobs:\n  build:\n    runs-on: ubuntu-latest\n
Run Code Online (Sandbox Code Playgroud)\n

我可以从 GitHub Actions 选项卡成功触发此操作。

\n

不过,我希望能够通过POST对 GitHub API 的请求来触发此操作。\n这应该可以使用 GitHub API 实现。\n相关的 API 端点似乎如\n文档/repos/{owner}/{repo}/actions/workflows/{workflow_id}/dispatches中所述。

\n

该文件进一步指出:

\n
\n

您必须使用具有存储库范围的访问令牌进行身份验证才能使用此端点。

\n
\n

因此,在我的个人帐户设置中的“开发人员设置”\xe2\x86\x92“个人访问令牌”下,\n我创建了一个令牌并授予对所有“存储库”项以及“工作流”项的访问权限。

\n

我已测试通过使用PostmanPOST发出请求来触发 GitHub Action 。\n为此,我根据\n GitHub 文档使用以下参数:curl

\n
    \n
  • accept:(application/vnd.github.v3+json根据 …

rest curl github github-actions

9
推荐指数
1
解决办法
2万
查看次数

由于“不安全存储库”错误,GitHub Action 无法推送

我有一个私有 GitHub 存储库,其中有一个 GitHub Action,它将在 Action 运行时创建的文件推送到存储库。从昨天(2022-04-12)开始,操作在以下步骤失败:

    - name: Push data to repo
      uses: github-actions-x/commit@v2.8
      with:
        push-branch: 'main'
        commit-message: 'Add current data'
        force-add: 'true'
        files: *.zip
        name: autoupdate
Run Code Online (Sandbox Code Playgroud)

运行此步骤会触发以下错误消息:

Command line: | /usr/bin/git checkout -B main
Stderr:       | fatal: unsafe repository ('/github/workspace' is owned by someone else)
              | To add an exception for this directory, call:
              | 
              |     git config --global --add safe.directory /github/workspace
Run Code Online (Sandbox Code Playgroud)

根据错误消息,我将以下内容添加到我的 GitHub Action 中:

    - name: Fix issue with repository ownership
      run: |
        git config --global …
Run Code Online (Sandbox Code Playgroud)

github repository git-push github-actions

3
推荐指数
1
解决办法
4814
查看次数

标签 统计

github ×2

github-actions ×2

curl ×1

git-push ×1

repository ×1

rest ×1