【手把手撸一个脚手架】第三步, 获取 github 项目信息

栏目: 编程工具 · 发布时间: 5年前

内容简介:脚手架, 作为一个工具, 主要是用来搬运我们已经准备好的项目模板(webpack 配置, koa 项目雏形等等), 这一步我们就来创建用于搬运的项目模板. 并通过接口获取相关信息ps: 这一步基于 github 若有没使用过的小伙伴, 请加油为了不和自己平时写的各种辣鸡代码混杂在一起, 这里我专门创建了一个 organization 不会创建的兄弟们请度娘

脚手架, 作为一个工具, 主要是用来搬运我们已经准备好的项目模板(webpack 配置, koa 项目雏形等等), 这一步我们就来创建用于搬运的项目模板. 并通过接口获取相关信息 github Api 文档

ps: 这一步基于 github 若有没使用过的小伙伴, 请加油

【手把手撸一个脚手架】第三步, 获取 github 项目信息

创建一个专门用于维护项目模板的项目组

为了不和自己平时写的各种辣鸡代码混杂在一起, 这里我专门创建了一个 organization 不会创建的兄弟们请度娘

  • 目录切换到刚刚创建的 organization 上
【手把手撸一个脚手架】第三步, 获取 github 项目信息
  • 创建一个项目
【手把手撸一个脚手架】第三步, 获取 github 项目信息
  • 向创建的项目中添加一个文件, 上传到 github 并添加版本号
【手把手撸一个脚手架】第三步, 获取 github 项目信息

准备工作完成 ^_^

【手把手撸一个脚手架】第三步, 获取 github 项目信息

通过 github 开放 api 获取项目信息

baseUrl: api.github.com

作为一个开发工具, 我们需要获取的项目信息包含以下几个:

获取组织所属项目列表 文档

我们可以尝试一下获取刚刚创建的 organization 下的项目目录

curl https://api.github.com/orgs/learn-cli-organization/repos

// 返回的结果
[
  {
    "id": 157579674,
    "node_id": "MDEwOlJlcG9zaXRvcnkxNTc1Nzk2NzQ=",
    "name": "demo",
    "full_name": "learn-cli-organization/demo",
    "private": false,
    "owner": {
      "login": "learn-cli-organization",
      "id": 45043923,
      "node_id": "MDEyOk9yZ2FuaXphdGlvbjQ1MDQzOTIz",
      "avatar_url": "https://avatars2.githubusercontent.com/u/45043923?v=4",
      "gravatar_id": "",
      "url": "https://api.github.com/users/learn-cli-organization",
      "html_url": "https://github.com/learn-cli-organization",
      "followers_url": "https://api.github.com/users/learn-cli-organization/followers",
      "following_url": "https://api.github.com/users/learn-cli-organization/following{/other_user}",
      "gists_url": "https://api.github.com/users/learn-cli-organization/gists{/gist_id}",
      "starred_url": "https://api.github.com/users/learn-cli-organization/starred{/owner}{/repo}",
      "subscriptions_url": "https://api.github.com/users/learn-cli-organization/subscriptions",
      "organizations_url": "https://api.github.com/users/learn-cli-organization/orgs",
      "repos_url": "https://api.github.com/users/learn-cli-organization/repos",
      "events_url": "https://api.github.com/users/learn-cli-organization/events{/privacy}",
      "received_events_url": "https://api.github.com/users/learn-cli-organization/received_events",
      "type": "Organization",
      "site_admin": false
    },
    "html_url": "https://github.com/learn-cli-organization/demo",
    "description": null,
    "fork": false,
    "url": "https://api.github.com/repos/learn-cli-organization/demo",
    "forks_url": "https://api.github.com/repos/learn-cli-organization/demo/forks",
    "keys_url": "https://api.github.com/repos/learn-cli-organization/demo/keys{/key_id}",
    "collaborators_url": "https://api.github.com/repos/learn-cli-organization/demo/collaborators{/collaborator}",
    "teams_url": "https://api.github.com/repos/learn-cli-organization/demo/teams",
    "hooks_url": "https://api.github.com/repos/learn-cli-organization/demo/hooks",
    "issue_events_url": "https://api.github.com/repos/learn-cli-organization/demo/issues/events{/number}",
    "events_url": "https://api.github.com/repos/learn-cli-organization/demo/events",
    "assignees_url": "https://api.github.com/repos/learn-cli-organization/demo/assignees{/user}",
    "branches_url": "https://api.github.com/repos/learn-cli-organization/demo/branches{/branch}",
    "tags_url": "https://api.github.com/repos/learn-cli-organization/demo/tags",
    "blobs_url": "https://api.github.com/repos/learn-cli-organization/demo/git/blobs{/sha}",
    "git_tags_url": "https://api.github.com/repos/learn-cli-organization/demo/git/tags{/sha}",
    "git_refs_url": "https://api.github.com/repos/learn-cli-organization/demo/git/refs{/sha}",
    "trees_url": "https://api.github.com/repos/learn-cli-organization/demo/git/trees{/sha}",
    "statuses_url": "https://api.github.com/repos/learn-cli-organization/demo/statuses/{sha}",
    "languages_url": "https://api.github.com/repos/learn-cli-organization/demo/languages",
    "stargazers_url": "https://api.github.com/repos/learn-cli-organization/demo/stargazers",
    "contributors_url": "https://api.github.com/repos/learn-cli-organization/demo/contributors",
    "subscribers_url": "https://api.github.com/repos/learn-cli-organization/demo/subscribers",
    "subscription_url": "https://api.github.com/repos/learn-cli-organization/demo/subscription",
    "commits_url": "https://api.github.com/repos/learn-cli-organization/demo/commits{/sha}",
    "git_commits_url": "https://api.github.com/repos/learn-cli-organization/demo/git/commits{/sha}",
    "comments_url": "https://api.github.com/repos/learn-cli-organization/demo/comments{/number}",
    "issue_comment_url": "https://api.github.com/repos/learn-cli-organization/demo/issues/comments{/number}",
    "contents_url": "https://api.github.com/repos/learn-cli-organization/demo/contents/{+path}",
    "compare_url": "https://api.github.com/repos/learn-cli-organization/demo/compare/{base}...{head}",
    "merges_url": "https://api.github.com/repos/learn-cli-organization/demo/merges",
    "archive_url": "https://api.github.com/repos/learn-cli-organization/demo/{archive_format}{/ref}",
    "downloads_url": "https://api.github.com/repos/learn-cli-organization/demo/downloads",
    "issues_url": "https://api.github.com/repos/learn-cli-organization/demo/issues{/number}",
    "pulls_url": "https://api.github.com/repos/learn-cli-organization/demo/pulls{/number}",
    "milestones_url": "https://api.github.com/repos/learn-cli-organization/demo/milestones{/number}",
    "notifications_url": "https://api.github.com/repos/learn-cli-organization/demo/notifications{?since,all,participating}",
    "labels_url": "https://api.github.com/repos/learn-cli-organization/demo/labels{/name}",
    "releases_url": "https://api.github.com/repos/learn-cli-organization/demo/releases{/id}",
    "deployments_url": "https://api.github.com/repos/learn-cli-organization/demo/deployments",
    "created_at": "2018-11-14T16:41:01Z",
    "updated_at": "2018-11-14T16:42:39Z",
    "pushed_at": "2018-11-14T16:43:18Z",
    "git_url": "git://github.com/learn-cli-organization/demo.git",
    "ssh_url": "git@github.com:learn-cli-organization/demo.git",
    "clone_url": "https://github.com/learn-cli-organization/demo.git",
    "svn_url": "https://github.com/learn-cli-organization/demo",
    "homepage": null,
    "size": 0,
    "stargazers_count": 0,
    "watchers_count": 0,
    "language": "JavaScript",
    "has_issues": true,
    "has_projects": true,
    "has_downloads": true,
    "has_wiki": true,
    "has_pages": false,
    "forks_count": 0,
    "mirror_url": null,
    "archived": false,
    "open_issues_count": 0,
    "license": null,
    "forks": 0,
    "open_issues": 0,
    "watchers": 0,
    "default_branch": "master",
    "permissions": {
      "admin": false,
      "push": false,
      "pull": true
    }
  }
]
复制代码

拿到这个数组说明我们已经能够获取到项目组中的所有项目啦

获取指定项目的版本号 文档

通过前一个接口, 我们成功的获取到了项目组中所有的项目信息, 接下来我们可以通过以下接口获取到指定项目的版本信息(就是 tags)

curl https://api.github.com/repos/learn-cli-organization/demo/tags

// 返回结果
[
  {
    "name": "v0.0.1",
    "zipball_url": "https://api.github.com/repos/learn-cli-organization/demo/zipball/v0.0.1",
    "tarball_url": "https://api.github.com/repos/learn-cli-organization/demo/tarball/v0.0.1",
    "commit": {
      "sha": "00f0dda86e5f922e2ae406c25e19b44b2463f690",
      "url": "https://api.github.com/repos/learn-cli-organization/demo/commits/00f0dda86e5f922e2ae406c25e19b44b2463f690"
    },
    "node_id": "MDM6UmVmMTU3NTc5Njc0OnYwLjAuMQ=="
  }
]
复制代码

下集预告: 到目前为止, 我们已经能够获取到项目信息. 下一步我们会将结合 inquirer.js 实现命令行交互式的动态获取这些信息

【手把手撸一个脚手架】第三步, 获取 github 项目信息

以上所述就是小编给大家介绍的《【手把手撸一个脚手架】第三步, 获取 github 项目信息》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

群体性孤独

群体性孤独

[美] 雪莉·特克尔 / 周逵、刘菁荆 / 浙江人民出版社 / 2014-3-1 / CNY 66.90

[内容简介] ☆ 你是否也熟悉这样的场景:家人在一起,不是交心,而是各自看电脑和手机;朋友聚会,不是叙旧,而是拼命刷新微博、微信;课堂上,老师在讲,学生在网上聊天;会议中,别人在报告,听众在收发信息。所有这些现象都可以归结为“群体性孤独”——我们似乎在一起,但实际上活在自己的“气泡”中。我们期待他人少,期待技术多。不间断的联系,是否让人类陷入了更深的孤独? ☆ 麻省理工学院社会学教授雪......一起来看看 《群体性孤独》 这本书的介绍吧!

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

URL 编码/解码
URL 编码/解码

URL 编码/解码

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具