从 github url 中查找用户、存储库和路径

Find the user, repo and path from a github url

我需要能够从粘贴到表单中的 github url(到回购中的文件)获取用户、回购和路径,以便能够制作api 请求就可以了。例如https://github.com/HubSpot/BuckyClient/blob/master/README.md

我已经开始编写一些正则表达式来尝试定位 url 的部分,但这似乎是一个脆弱的解决方案,因为 github url 有多种格式s.

有没有我没有找到的 api 方法,比如 getRepoFromUrl(),或者我可以从提供的 url 中提取此信息的其他更可靠的方法?我正在使用 node/javascript.

谢谢

不使用正则表达式,您是否可以使用 GitHub API 列出特定的回购协议 url,以便解析 JSON 答案,获取应包括的各种字段您要查找的信息:

"owner": {
      "login": "octocat",

"name": "Hello-World",
"full_name": "octocat/Hello-World", 

由于输入数据是 url,请检查 url 的 html 页面的元数据包含哪些内容。
对于我的回购 https://github.com/VonC/compileEverything,我看到:

<title>VonC/compileEverything</title>
<meta content="VonC/compileEverything" property="og:title" />
...

这应该至少允许取回用户名和存储库名称。