如何通过GitHub REST API获取触发Workflow运行的事件详情?
如何通过GitHub REST API关联Workflow运行与触发它的具体Issue事件?
我尝试在Workflow运行结束后,通过命令行调用GitHub REST API查询触发某次Workflow运行的具体事件详情,但无法找到各API端点资源间的关联。
示例
编号为52的Workflow运行实例,是由Issue 5被添加contribution标签触发的。尽管该标签添加操作与其他标签操作同时发生,但可确定是contribution标签的分配触发了此次Workflow运行,因为它是该Workflow所有Issue触发的运行实例中:
- 关联目标Issue(《为空间交换数据准备项目》的反馈)的实例;
- 未因Workflow定义中单个Job的
if条件(检查分配的标签是否为contribution)而被跳过的实例。
API可获取的数据
通过以下命令可查看Issue 5的事件:
gh api \ repos/SAP-docs/sap-datasphere/issues/5/events \ | jq -r ' sort_by(.created_at)[] | [.id, .created_at, .event, .label.name // "N/A"] | @tsv ' \ | column -t
输出结果(箭头标注目标事件):
9257336498 2023-05-16T12:10:11Z assigned N/A 9257337593 2023-05-16T12:10:18Z labeled follow-up-with/dev 9257337604 2023-05-16T12:10:18Z labeled in-discussion 9350701703 2023-05-26T13:11:24Z unassigned N/A 9350745853 2023-05-26T13:16:10Z unlabeled follow-up-with/dev 9350745859 2023-05-26T13:16:10Z unlabeled in-discussion 9350745865 2023-05-26T13:16:10Z labeled needs-more-info 9399724555 2023-06-01T07:54:23Z assigned N/A 9399860518 2023-06-01T08:06:51Z labeled size/s 9512993115 2023-06-13T08:43:36Z unlabeled needs-more-info 9512993122 2023-06-13T08:43:36Z labeled contribution <-- 9512993130 2023-06-13T08:43:36Z labeled type/clarity 9512998765 2023-06-13T08:44:02Z closed N/A
目标事件ID为9512993122,但通过Workflow runs API端点无法找到指向该事件ID的关联数据。
通过以下命令获取目标Workflow的ID为47098817:
gh api \ repos/SAP-docs/sap-datasphere/actions/workflows \ | jq ' .workflows[] | select(.path | contains("community-id-requester")).id ' # 返回47098817
无法获取Workflow运行的事件数据
将该Workflow ID传入Workflow runs API端点,筛选出编号为52的运行实例后,返回结果中无任何指向触发事件的信息:
gh api \ repos/SAP-docs/sap-datasphere/actions/workflows/47098817/runs \ | jq -c ' .workflow_runs[] | select(.run_number == 52) | keys '
返回的顶级属性如下:
[ "actor", "artifacts_url", "cancel_url", "check_suite_id", "check_suite_node_id", "check_suite_url", "conclusion", "created_at", "display_title", "event", "head_branch", "head_commit", "head_repository", "head_sha", "html_url", "id", "jobs_url", "logs_url", "name", "node_id", "path", "previous_attempt_url", "pull_requests", "referenced_workflows", "repository", "rerun_url", "run_attempt", "run_number", "run_started_at", "status", "triggering_actor", "updated_at", "url", "workflow_id", "workflow_url" ]
其中event字段的值仅为字符串"issues",无法提供更具体的事件信息。
请问我遗漏了什么?
内容的提问来源于stack exchange,提问作者qmacro
相关产品推荐
相关产品推荐

