【问题标题】:Get the latest workflow run from GitHub Actions using the Octokit API使用 Octokit API 从 GitHub Actions 获取最新的工作流程
【发布时间】:2021-01-29 12:15:37
【问题描述】:
我正在使用Octokit API 请求运行特定的工作流。我可以在documentation 中看到,我可以通过提供工作流运行 ID 来请求运行特定的工作流。但是,我想始终要求运行 最新 工作流程。如果我不知道 ID 是什么,我该如何实现?
例如这里workflow-run-latest 的值会一直在变化。
octokit.actions.getWorkflowRun({
owner: owner,
repo: repo-name,
run_id: workflow-run-latest,
});
谢谢!
【问题讨论】:
标签:
github
github-api
github-actions
octokit
【解决方案1】:
当使用列表 API 时,我觉得最新的总是列表中的第一个。因此,一种选择可能是将per_page 设置为1 进行请求,这样您就只能获得最新的。
octokit.actions.listWorkflowRunsForRepo({
owner: owner,
repo: repo-name,
per_page: 1,
});
【解决方案2】:
只是在这里发布我的代码 sn-p 解决了我的问题,以防将来对任何人有帮助:)
var workflowRuns = octokit.actions.listWorkflowRuns({
owner: owner,
repo: 'repo-name',
workflow_file_name: 'file-name.yaml',
per_page: 1
});