Skip to content

Commit 01d4d81

Browse files
committed
init
0 parents  commit 01d4d81

File tree

11 files changed

+4089
-0
lines changed

11 files changed

+4089
-0
lines changed

.editorconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
root = true
2+
3+
[*]
4+
indent_style = space
5+
indent_size = 2
6+
end_of_line = lf
7+
charset = utf-8
8+
trim_trailing_whitespace = true
9+
insert_final_newline = true
10+
11+
[*.md]
12+
trim_trailing_whitespace = false

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules
2+
.DS_Store
3+
*.log
4+
/dist

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) egoist <[email protected]> (https://egoistian.com)
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

README.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# repo-first-commit
2+
3+
[![NPM version](https://img.shields.io/npm/v/repo-first-commit.svg?style=flat)](https://npmjs.com/package/repo-first-commit) [![NPM downloads](https://img.shields.io/npm/dm/repo-first-commit.svg?style=flat)](https://npmjs.com/package/repo-first-commit) [![Build Status](https://img.shields.io/circleci/project/egoist/repo-first-commit/master.svg?style=flat)](https://circleci.com/gh/egoist/repo-first-commit) [![donate](https://img.shields.io/badge/$-donate-ff69b4.svg?maxAge=2592000&style=flat)](https://github.com/egoist/donate)
4+
5+
## Install
6+
7+
```bash
8+
yarn add repo-first-commit
9+
```
10+
11+
## Usage
12+
13+
```js
14+
const repo = require('repo-first-commit')
15+
16+
repo({
17+
owner: 'egoist',
18+
repo: 'vbuild',
19+
sha: '5.0'
20+
}).then(commit => {
21+
console.log(commit.commit.message)
22+
//=> "init"
23+
})
24+
```
25+
26+
## API
27+
28+
### repo(options)
29+
30+
#### options
31+
32+
##### owner
33+
34+
Type: `string`<br>
35+
Required: `true`
36+
37+
GitHub username
38+
39+
##### repo
40+
41+
Type: `string`<br>
42+
Required: `true`
43+
44+
GitHub repo name
45+
46+
##### sha
47+
48+
Type: `string`
49+
50+
SHA or branch to start listing commits from.
51+
52+
##### token
53+
54+
Type: `string`
55+
56+
GitHub API access token.
57+
58+
## Contributing
59+
60+
1. Fork it!
61+
2. Create your feature branch: `git checkout -b my-new-feature`
62+
3. Commit your changes: `git commit -am 'Add some feature'`
63+
4. Push to the branch: `git push origin my-new-feature`
64+
5. Submit a pull request :D
65+
66+
67+
## Author
68+
69+
**repo-first-commit** © [egoist](https://github.com/egoist), Released under the [MIT](./LICENSE) License.<br>
70+
Authored and maintained by egoist with help from contributors ([list](https://github.com/egoist/repo-first-commit/contributors)).
71+
72+
> [egoistian.com](https://egoistian.com) · GitHub [@egoist](https://github.com/egoist) · Twitter [@rem_rin_rin](https://twitter.com/rem_rin_rin)

circle.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
machine:
2+
node:
3+
version: 7
4+
environment:
5+
PATH: "${PATH}:${HOME}/${CIRCLE_PROJECT_REPONAME}/node_modules/.bin"
6+
7+
dependencies:
8+
override:
9+
- yarn
10+
cache_directories:
11+
- ~/.cache/yarn
12+
13+
test:
14+
override:
15+
- yarn test

example.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const repo = require('./')
2+
3+
repo({
4+
owner: 'egoist',
5+
repo: 'vbuild',
6+
sha: '5.0'
7+
}).then(res => {
8+
console.log(res.commit.message)
9+
})

package.json

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"name": "repo-first-commit",
3+
"version": "0.0.0",
4+
"description": "Get the first commit of any GitHub repo.",
5+
"repository": {
6+
"url": "egoist/repo-first-commit",
7+
"type": "git"
8+
},
9+
"main": "dist/repo-first-commit.common.js",
10+
"files": [
11+
"dist"
12+
],
13+
"scripts": {
14+
"test": "jest && npm run lint && npm run build",
15+
"lint": "xo",
16+
"build": "bili"
17+
},
18+
"author": "egoist <[email protected]>",
19+
"license": "MIT",
20+
"jest": {
21+
"testEnvironment": "node"
22+
},
23+
"devDependencies": {
24+
"babel-preset-es2015": "^6.22.0",
25+
"bili": "^0.14.0",
26+
"jest-cli": "^18.1.0",
27+
"xo": "^0.17.1"
28+
},
29+
"xo": {
30+
"space": 2,
31+
"semicolon": false,
32+
"envs": [
33+
"jest"
34+
]
35+
},
36+
"dependencies": {
37+
"axios": "^0.15.3",
38+
"node-fetch": "^1.6.3",
39+
"parse-link-header": "^0.4.1"
40+
},
41+
"babel": {
42+
"presets": [
43+
"es2015"
44+
]
45+
}
46+
}

src/index.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/* eslint-disable camelcase */
2+
import fetch from 'axios'
3+
import parse from 'parse-link-header'
4+
5+
export default function ({
6+
owner,
7+
repo,
8+
token,
9+
sha
10+
} = {}) {
11+
const request = page => fetch.get(`https://api.github.com/repos/${owner}/${repo}/commits`, {
12+
params: {
13+
access_token: token,
14+
sha,
15+
per_page: 100,
16+
page
17+
}
18+
}).then(res => {
19+
const {headers: {link}, data} = res
20+
if (!link || page !== 1) {
21+
return data[data.length - 1]
22+
}
23+
const {last} = parse(link)
24+
return request(last.page)
25+
})
26+
27+
return request(1)
28+
}

test/index.test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/* globals jasmine */
2+
import repo from '../src'
3+
4+
jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000
5+
6+
test('main', () => {
7+
return repo({
8+
owner: 'egoist',
9+
repo: 'vbuild',
10+
sha: '5.0'
11+
}).then(commit => {
12+
expect(commit.commit.message).toBe('init')
13+
})
14+
})

0 commit comments

Comments
 (0)