繁体   English   中英

使用 Octokit API 从 GitHub Actions 获取最新的工作流程

[英]Get the latest workflow run from GitHub Actions using the Octokit API

我正在使用Octokit API请求运行特定的工作流。 我可以在 文档中看到,我可以通过提供工作流运行 ID 来请求特定的工作流运行。 但是我想总是请求最新的工作流程运行。 如果我不知道 ID 是什么,我该如何实现?

例如, workflow-run-latest的值总是在变化。

octokit.actions.getWorkflowRun({
    owner: owner,
    repo: repo-name,
    run_id: workflow-run-latest,
});

谢谢!

在使用列表 API 时,在我看来,最新的总是列表中的第一个。 因此,一种选择可能是将per_page设置为1进行请求,以便您只能获得最新的。

octokit.actions.listWorkflowRunsForRepo({
  owner: owner,
  repo: repo-name,
  per_page: 1,
});

只需在此处发布解决我问题的代码片段,以防将来对任何人有所帮助:)

var workflowRuns = octokit.actions.listWorkflowRuns({
    owner: owner,
    repo: 'repo-name',
    workflow_file_name: 'file-name.yaml',
    per_page: 1
});

暂无
暂无

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

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