简体   繁体   English

GitHub 操作:必须具有管理员权限才能触发 workflow_dispatch?

[英]GitHub Actions: Must have admin rights to trigger workflow_dispatch?

Using the github API I am trying to manually start a workflow using:使用 github API 我正在尝试使用以下方法手动启动工作流:

  curl \
  -X POST \
  -H "Accept: application/vnd.github+json" \ 
  -H "Authorization: MY_TOKEN" \
  https://api.github.com/repos/djpr-data/djprdashdata/actions/workflows/refresh-data.yaml/dispatches 

but I keep getting an authentication error:但我不断收到身份验证错误:

{
  "message": "Must have admin rights to Repository.",
  "documentation_url": "https://docs.github.com/rest/reference/actions#create-a-workflow-dispatch-event"
}

This seems to be a similar issue to this question .这似乎是与此问题类似的问题 But my PAT token has all admin and repo scopes selected.但是我的 PAT 令牌选择了所有adminrepo范围。 I also have my user account setup as admin for the repository and I have added a workflow dispatch to the workflow yaml file.我还将我的用户帐户设置为存储库的admin ,并且我已将工作流调度添加到工作流 yaml 文件中。

  workflow_dispatch:
    inputs:
      tags:
        description:
          "run from cmdline"

I have been following the docs at https://docs.github.com/en/rest/actions/workflows#create-a-workflow-dispatch-event and have had no problems using the API to retrieve all previous workflow jobs.我一直在关注 https://docs.github.com/en/rest/actions/workflows#create-a-workflow-dispatch-event上的文档,并且使用 ZDB974238714CA8DE634A 检索所有以前的工作流作业没有问题。 I have also tried the runs and jobs endpoints but get the same error.我也尝试过runsjobs端点,但得到了同样的错误。 So I am now not sure what else I can do.所以我现在不确定我还能做什么。 Is there somewhere else I need to set permissions?还有其他地方我需要设置权限吗?

Thanks谢谢

This is a poor error message to tell you that your request is not formed correctly.这是一条糟糕的错误消息,告诉您您的请求格式不正确。 If you want to pass a PAT as a header, you need to prefix it with token , as described in the docs :如果您想将 PAT 作为 header 传递,您需要在它前面加上token ,如文档中所述:

-H "Authorization: token MY_TOKEN"

Once that's resolved, however, you'll also get an error because you don't pass the required ref payload.但是,一旦解决了这个问题,您也会收到一个错误,因为您没有传递所需的ref有效负载。 Assuming your default branch is main , here's a correct curl command:假设您的默认分支是main ,这是一个正确的 curl 命令:

> export MY_TOKEN=gha_abcdef
> curl \
  -X POST \
  -H "Accept: application/vnd.github+json" \ 
  -H "Authorization: token $MY_TOKEN" \
  -d '{"ref": "main"}' \
  https://api.github.com/repos/djpr-data/djprdashdata/actions/workflows/refresh-data.yaml/dispatches

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM