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

系列文章:

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

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

2018-11-15-00-33-46

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

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

  • 目录切换到刚刚创建的 organization 上
2018-11-15-00-38-51
  • 创建一个项目
2018-11-15-00-39-18
  • 向创建的项目中添加一个文件, 上传到 github 并打好 tag
2018-11-15-00-44-17

准备工作完成 _

2018-11-15-00-49-08

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

baseUrl: https://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
    }
  }
]

拿到这个数组说明我们已经能够获取到项目组中的所有项目啦, 一波猝不及防的商业互吹 _

16705bca01c5e44c

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

通过前一个接口, 我们成功的获取到了项目组中所有的项目信息, 接下来我们可以通过以下接口获取到指定项目的版本信息(就是 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 实现命令行交互式的动态获取这些信息

2018-11-15-01-19-33
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 214,444评论 6 496
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 91,421评论 3 389
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 160,036评论 0 349
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 57,363评论 1 288
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 66,460评论 6 386
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 50,502评论 1 292
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,511评论 3 412
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,280评论 0 270
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,736评论 1 307
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,014评论 2 328
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,190评论 1 342
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,848评论 5 338
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,531评论 3 322
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,159评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,411评论 1 268
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 47,067评论 2 365
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,078评论 2 352