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

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

内容简介:脚手架, 作为一个工具, 主要是用来搬运我们已经准备好的项目模板(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 项目信息》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

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

Windows黑客编程技术详解

Windows黑客编程技术详解

甘迪文 / 人民邮电出版社 / 2018-12 / 108

《Windows黑客编程技术详解》介绍的是黑客编程的基础技术,涉及用户层下的Windows编程和内核层下的Rootkit编程。本书分为用户篇和内核篇两部分,用户篇包括11章,配套49个示例程序源码;内核篇包括7章,配套28个示例程序源码。本书介绍的每个技术都有详细的实现原理,以及对应的示例代码(配套代码均支持32位和64位Windows 7、Windows 8.1及Windows 10系统),旨在......一起来看看 《Windows黑客编程技术详解》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

随机密码生成器
随机密码生成器

多种字符组合密码

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试