【问题标题】:How do I capture the latest GitHub release of a project from the API?如何从 API 捕获项目的最新 GitHub 版本?
【发布时间】:2020-06-27 15:31:05
【问题描述】:

我正在尝试从 GitHub API page 获取最新版本的下载 url。

我首先需要捕获所有以browser_download_url 开头的行,并进一步抓取其中包含linux64 的行。

当前应该捕获的目标链接 - https://github.com/mozilla/geckodriver/releases/download/v0.26.0/geckodriver-v0.26.0-linux64.tar.gz

经过一番研究,我尝试做以下 -

curl -s https://api.github.com/repos/mozilla/geckodriver/releases/latest | grep "browser_download_url | grep 'linux64[.]gz' | head -n 1 | cut -d '"' -f 4

但它似乎不起作用。

另外,它不一定是我尝试的编辑,我不介意答案中是否使用了 awk、sed 等

【问题讨论】:

  • 您可以参考外部链接来支持您的问题,但请在问题本身中添加示例输入和预期输出以清晰和易于测试
  • 使用'jq',而不是grep。这是 JSON

标签: github


【解决方案1】:

像这样:

curl -s 'https://api.github.com/repos/mozilla/geckodriver/releases/latest' | 
    jq -r '.assets[].browser_download_url' |
    grep linux64

https://github.com/mozilla/geckodriver/releases/download/v0.26.0/geckodriver-v0.26.0-linux64.tar.gz

【讨论】:

  • 我试过了,但是file.json由于某种原因是空的
猜你喜欢
  • 1970-01-01
  • 2021-10-20
  • 1970-01-01
  • 2023-03-20
  • 1970-01-01
  • 2015-03-29
  • 2016-06-30
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多