ghrepos 2.0.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/dependabot.yml +20 -0
- package/.github/workflows/test-and-release.yml +56 -0
- package/CHANGELOG.md +13 -0
- package/README.md +70 -96
- package/examples/commit-comments.js +13 -0
- package/ghrepos.js +53 -85
- package/package.json +101 -7
- package/test.js +202 -290
- package/.jshintrc +0 -59
- package/.npmignore +0 -2
- package/.travis.yml +0 -17
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
version: 2
|
|
2
|
+
updates:
|
|
3
|
+
- package-ecosystem: 'github-actions'
|
|
4
|
+
directory: '/'
|
|
5
|
+
schedule:
|
|
6
|
+
interval: 'weekly'
|
|
7
|
+
commit-message:
|
|
8
|
+
prefix: 'chore'
|
|
9
|
+
include: 'scope'
|
|
10
|
+
cooldown:
|
|
11
|
+
default-days: 5
|
|
12
|
+
- package-ecosystem: 'npm'
|
|
13
|
+
directory: '/'
|
|
14
|
+
schedule:
|
|
15
|
+
interval: 'weekly'
|
|
16
|
+
commit-message:
|
|
17
|
+
prefix: 'chore'
|
|
18
|
+
include: 'scope'
|
|
19
|
+
cooldown:
|
|
20
|
+
default-days: 5
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
name: Test & Maybe Release
|
|
2
|
+
on: [push, pull_request]
|
|
3
|
+
|
|
4
|
+
jobs:
|
|
5
|
+
test:
|
|
6
|
+
strategy:
|
|
7
|
+
fail-fast: false
|
|
8
|
+
matrix:
|
|
9
|
+
node: [lts/*, current]
|
|
10
|
+
os: [macos-latest, ubuntu-latest, windows-latest]
|
|
11
|
+
runs-on: ${{ matrix.os }}
|
|
12
|
+
steps:
|
|
13
|
+
- name: Checkout Repository
|
|
14
|
+
uses: actions/checkout@v6
|
|
15
|
+
- name: Use Node.js ${{ matrix.node }}
|
|
16
|
+
uses: actions/setup-node@v6
|
|
17
|
+
with:
|
|
18
|
+
node-version: ${{ matrix.node }}
|
|
19
|
+
- name: Install Dependencies
|
|
20
|
+
run: npm install --no-progress
|
|
21
|
+
- name: Check build is up to date
|
|
22
|
+
run: |
|
|
23
|
+
npm run build
|
|
24
|
+
git diff --exit-code || (echo "::error::Build artifacts not committed. Run 'npm run build' and commit the changes." && exit 1)
|
|
25
|
+
- name: Run tests
|
|
26
|
+
run: npm test
|
|
27
|
+
|
|
28
|
+
release:
|
|
29
|
+
name: Release
|
|
30
|
+
needs: test
|
|
31
|
+
runs-on: ubuntu-latest
|
|
32
|
+
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
|
|
33
|
+
permissions:
|
|
34
|
+
contents: write
|
|
35
|
+
issues: write
|
|
36
|
+
pull-requests: write
|
|
37
|
+
id-token: write
|
|
38
|
+
steps:
|
|
39
|
+
- name: Checkout
|
|
40
|
+
uses: actions/checkout@v6
|
|
41
|
+
with:
|
|
42
|
+
fetch-depth: 0
|
|
43
|
+
- name: Setup Node.js
|
|
44
|
+
uses: actions/setup-node@v6
|
|
45
|
+
with:
|
|
46
|
+
node-version: lts/*
|
|
47
|
+
registry-url: 'https://registry.npmjs.org'
|
|
48
|
+
- name: Install dependencies
|
|
49
|
+
run: npm install --no-progress --no-package-lock --no-save
|
|
50
|
+
- name: Build
|
|
51
|
+
run: npm run build
|
|
52
|
+
- name: Release
|
|
53
|
+
env:
|
|
54
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
55
|
+
NPM_CONFIG_PROVENANCE: true
|
|
56
|
+
run: npx semantic-release
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
## [3.0.0](https://github.com/rvagg/ghrepos/compare/v2.1.0...v3.0.0) (2026-01-27)
|
|
2
|
+
|
|
3
|
+
### ⚠ BREAKING CHANGES
|
|
4
|
+
|
|
5
|
+
* modernise, ESM, promises, update deps, GHA, auto-release (#7)
|
|
6
|
+
|
|
7
|
+
### Bug Fixes
|
|
8
|
+
|
|
9
|
+
* add release config ([8fcbd12](https://github.com/rvagg/ghrepos/commit/8fcbd128551da685b0f227289dfe1e441b90ece1))
|
|
10
|
+
|
|
11
|
+
### Trivial Changes
|
|
12
|
+
|
|
13
|
+
* modernise, ESM, promises, update deps, GHA, auto-release ([#7](https://github.com/rvagg/ghrepos/issues/7)) ([8ad433d](https://github.com/rvagg/ghrepos/commit/8ad433d162b20c64f0331cdd1e2afd369027db87))
|
package/README.md
CHANGED
|
@@ -1,145 +1,119 @@
|
|
|
1
1
|
# ghrepos
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**A Node.js library to interact with the GitHub repos API**
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
[](https://nodei.co/npm/ghrepos/)
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
## Requirements
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
- Node.js >= 20
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
* https://github.com/rvagg/ghusers
|
|
13
|
-
* https://github.com/rvagg/ghteams
|
|
14
|
-
* https://github.com/rvagg/ghauth
|
|
11
|
+
## Example usage
|
|
15
12
|
|
|
16
|
-
|
|
13
|
+
```js
|
|
14
|
+
import * as ghrepos from 'ghrepos'
|
|
17
15
|
|
|
18
|
-
|
|
16
|
+
const auth = { token: 'your-github-token' }
|
|
19
17
|
|
|
20
|
-
|
|
18
|
+
// list all repos for a user
|
|
19
|
+
const repos = await ghrepos.listUser(auth, 'rvagg')
|
|
20
|
+
console.log(repos)
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
// list all repos for an org
|
|
23
|
+
const orgRepos = await ghrepos.listOrg(auth, 'nodejs')
|
|
24
|
+
console.log(orgRepos)
|
|
23
25
|
|
|
24
|
-
|
|
25
|
-
const
|
|
26
|
-
|
|
26
|
+
// get branch data
|
|
27
|
+
const branch = await ghrepos.getBranch(auth, 'nodejs', 'node', 'main')
|
|
28
|
+
console.log(branch)
|
|
27
29
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
30
|
+
// get commit comments
|
|
31
|
+
const comments = await ghrepos.getCommitComments(auth, 'nodejs', 'node', '75318e46b')
|
|
32
|
+
console.log(comments)
|
|
31
33
|
```
|
|
32
34
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
List all repos for a organisation. If `org` and `options` are omitted the current org is assumed.
|
|
36
|
-
|
|
37
|
-
List all repos for org `'nodejs'`:
|
|
35
|
+
The auth data is compatible with [ghauth](https://github.com/rvagg/ghauth) so you can connect them together:
|
|
38
36
|
|
|
39
37
|
```js
|
|
40
|
-
|
|
41
|
-
|
|
38
|
+
import ghauth from 'ghauth'
|
|
39
|
+
import * as ghrepos from 'ghrepos'
|
|
40
|
+
|
|
41
|
+
const auth = await ghauth({
|
|
42
|
+
configName: 'repo-lister',
|
|
43
|
+
scopes: ['user']
|
|
44
|
+
})
|
|
42
45
|
|
|
43
|
-
ghrepos.
|
|
44
|
-
|
|
46
|
+
const repos = await ghrepos.listUser(auth, 'rvagg')
|
|
47
|
+
console.log('Repos for rvagg:')
|
|
48
|
+
repos.forEach((r) => {
|
|
49
|
+
console.log('%s: %s (fork: %s)', r.name, r.description, r.fork)
|
|
45
50
|
})
|
|
46
51
|
```
|
|
47
52
|
|
|
48
|
-
|
|
53
|
+
## API
|
|
49
54
|
|
|
50
|
-
|
|
55
|
+
All methods return Promises.
|
|
51
56
|
|
|
52
|
-
|
|
57
|
+
### ghrepos.listUser(auth, user, options)
|
|
53
58
|
|
|
54
|
-
|
|
55
|
-
ghrepos.listRefs(authOptions, 'nodejs', 'io.js', function (err, refData) {
|
|
56
|
-
// data containing ref information including sha and github url
|
|
57
|
-
console.log(refData)
|
|
58
|
-
})
|
|
59
|
-
```
|
|
59
|
+
List all repos for a user. If `user` is falsy, lists repos for the authenticated user.
|
|
60
60
|
|
|
61
|
-
###
|
|
61
|
+
### ghrepos.listOrg(auth, org, options)
|
|
62
62
|
|
|
63
|
-
|
|
63
|
+
List all repos for an organisation.
|
|
64
64
|
|
|
65
|
-
|
|
65
|
+
### ghrepos.listRefs(auth, org, repo, options)
|
|
66
66
|
|
|
67
|
-
|
|
68
|
-
ghrepos.listBranches(authOptions, 'nodejs', 'io.js', function (err, refData) {
|
|
69
|
-
// data containing branch information including sha and github API url
|
|
70
|
-
console.log(refData)
|
|
71
|
-
})
|
|
72
|
-
```
|
|
67
|
+
Get git ref data for all refs in a repo.
|
|
73
68
|
|
|
74
|
-
### listTags(auth, org, repo
|
|
69
|
+
### ghrepos.listTags(auth, org, repo, options)
|
|
75
70
|
|
|
76
|
-
|
|
71
|
+
List git tags for a repo.
|
|
77
72
|
|
|
78
|
-
|
|
73
|
+
### ghrepos.listBranches(auth, org, repo, options)
|
|
79
74
|
|
|
80
|
-
|
|
81
|
-
ghrepos.listTags(authOptions, 'nodejs', 'io.js', function (err, refData) {
|
|
82
|
-
// data containing tag information including sha and github API url
|
|
83
|
-
console.log(refData)
|
|
84
|
-
})
|
|
85
|
-
```
|
|
75
|
+
List git branches for a repo.
|
|
86
76
|
|
|
87
|
-
###
|
|
77
|
+
### ghrepos.listCommits(auth, org, repo, options)
|
|
88
78
|
|
|
89
|
-
|
|
79
|
+
List git commits for a repo.
|
|
90
80
|
|
|
91
|
-
|
|
81
|
+
### ghrepos.getRef(auth, org, repo, ref, options)
|
|
92
82
|
|
|
93
|
-
|
|
94
|
-
ghrepos.getRef(authOptions, 'nodejs', 'io.js', 'heads/v1.x', function (err, refData) {
|
|
95
|
-
// data containing ref information including sha and github url
|
|
96
|
-
console.log(refData)
|
|
97
|
-
})
|
|
98
|
-
```
|
|
83
|
+
Get git ref data for a particular ref string. The `refs/` prefix is automatically stripped if present.
|
|
99
84
|
|
|
100
|
-
### getBranch(auth, org, repo, branch
|
|
85
|
+
### ghrepos.getBranch(auth, org, repo, branch, options)
|
|
101
86
|
|
|
102
|
-
Get git branch data for a given branch name
|
|
87
|
+
Get git branch data for a given branch name.
|
|
103
88
|
|
|
104
|
-
|
|
89
|
+
### ghrepos.getCommit(auth, org, repo, sha, options)
|
|
105
90
|
|
|
106
|
-
|
|
107
|
-
ghrepos.getBranch(authOptions, 'nodejs', 'io.js', 'v1.x', function (err, refData) {
|
|
108
|
-
// data containing branch information including sha and github API url
|
|
109
|
-
console.log(refData)
|
|
110
|
-
})
|
|
111
|
-
```
|
|
91
|
+
Get git commit data for a given SHA.
|
|
112
92
|
|
|
113
|
-
###
|
|
93
|
+
### ghrepos.getCommitComments(auth, org, repo, sha, options)
|
|
114
94
|
|
|
115
|
-
|
|
95
|
+
Get commit comments for a given SHA.
|
|
116
96
|
|
|
117
|
-
|
|
97
|
+
### ghrepos.createLister(type)
|
|
118
98
|
|
|
99
|
+
Creates a function that lists sub-resources under `/repos/:org/:repo/:type`, e.g. `'issues'`, `'pulls'` or `'releases'`. The returned function has the signature: `async function (auth, org, repo, options)`.
|
|
119
100
|
|
|
120
|
-
|
|
101
|
+
### ghrepos.baseUrl(org, repo, options)
|
|
121
102
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
ghauth(authOptions, function (err, authData) {
|
|
131
|
-
ghrepos.listUser(authData, 'rvagg', function (err, list) {
|
|
132
|
-
console.log('Repos for rvagg:')
|
|
133
|
-
console.log(util.inspect(list.map(function (i) { return {
|
|
134
|
-
name: i.name
|
|
135
|
-
, desc: i.description
|
|
136
|
-
, fork: i.fork
|
|
137
|
-
}})))
|
|
138
|
-
})
|
|
139
|
-
})
|
|
140
|
-
```
|
|
103
|
+
Returns the base API URL for a repo: `https://api.github.com/repos/:org/:repo`.
|
|
104
|
+
|
|
105
|
+
## Authentication
|
|
106
|
+
|
|
107
|
+
See [ghauth](https://github.com/rvagg/ghauth) for an easy way to obtain and cache GitHub authentication tokens. The `auth` object returned by ghauth is directly compatible with all ghrepos methods.
|
|
108
|
+
|
|
109
|
+
## See also
|
|
141
110
|
|
|
111
|
+
* [ghissues](https://github.com/rvagg/ghissues) - interact with the GitHub issues API
|
|
112
|
+
* [ghusers](https://github.com/rvagg/ghusers) - interact with the GitHub users API
|
|
113
|
+
* [ghteams](https://github.com/rvagg/ghteams) - interact with the GitHub teams API
|
|
114
|
+
* [ghpulls](https://github.com/rvagg/ghpulls) - interact with the GitHub pull requests API
|
|
115
|
+
* [ghauth](https://github.com/rvagg/ghauth) - GitHub authentication
|
|
142
116
|
|
|
143
117
|
## License
|
|
144
118
|
|
|
145
|
-
**ghrepos** is Copyright (c)
|
|
119
|
+
**ghrepos** is Copyright (c) 2014-2025 Rod Vagg [@rvagg](https://github.com/rvagg) and licensed under the MIT licence. All rights not explicitly granted in the MIT license are reserved. See the included LICENSE file for more details.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import ghauth from 'ghauth'
|
|
2
|
+
import { getCommitComments } from '../ghrepos.js'
|
|
3
|
+
|
|
4
|
+
const authData = await ghauth({
|
|
5
|
+
configName: 'lister',
|
|
6
|
+
clientId: 'your-client-id',
|
|
7
|
+
scopes: ['user']
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
const comments = await getCommitComments(authData, 'nodejs', 'node', '75318e46b')
|
|
11
|
+
console.log(JSON.stringify(comments.map((i) => {
|
|
12
|
+
return { user: i.user.login, body: i.body }
|
|
13
|
+
}), null, 2))
|
package/ghrepos.js
CHANGED
|
@@ -1,104 +1,72 @@
|
|
|
1
|
-
|
|
2
|
-
, apiRoot = ghutils.apiRoot
|
|
1
|
+
import { apiRoot, ghget, lister } from 'ghutils'
|
|
3
2
|
|
|
3
|
+
const defaultApiUrl = apiRoot
|
|
4
4
|
|
|
5
|
-
function
|
|
6
|
-
|
|
5
|
+
export function baseUrl (org, repo, options = {}) {
|
|
6
|
+
const api = options._apiUrl || defaultApiUrl
|
|
7
|
+
return `${api}/repos/${org}/${repo}`
|
|
7
8
|
}
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
export async function listUser (auth, user, options = {}) {
|
|
11
|
+
const api = options._apiUrl || defaultApiUrl
|
|
12
|
+
const url = user ? `${api}/users/${user}/repos` : `${api}/user/repos`
|
|
13
|
+
return lister(auth, url, options)
|
|
12
14
|
}
|
|
13
15
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
options = {}
|
|
19
|
-
org = null
|
|
20
|
-
} else if (typeof options == 'function') { // no options
|
|
21
|
-
callback = options
|
|
22
|
-
options = {}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
var urlbase = apiRoot
|
|
26
|
-
|
|
27
|
-
if (org == null) {
|
|
28
|
-
urlbase += '/user/repos'
|
|
29
|
-
} else {
|
|
30
|
-
if (type == 'org')
|
|
31
|
-
urlbase += '/orgs/' + org + '/repos?'
|
|
32
|
-
else
|
|
33
|
-
urlbase += '/users/' + org + '/repos?'
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
ghutils.lister(auth, urlbase, options, callback)
|
|
16
|
+
export async function listOrg (auth, org, options = {}) {
|
|
17
|
+
const api = options._apiUrl || defaultApiUrl
|
|
18
|
+
const url = `${api}/orgs/${org}/repos`
|
|
19
|
+
return lister(auth, url, options)
|
|
37
20
|
}
|
|
38
21
|
|
|
22
|
+
export async function listRefs (auth, org, repo, options = {}) {
|
|
23
|
+
const url = baseUrl(org, repo, options) + '/git/refs'
|
|
24
|
+
return lister(auth, url, options)
|
|
25
|
+
}
|
|
39
26
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
if (typeof options == 'function') { // no options
|
|
45
|
-
callback = options
|
|
46
|
-
options = {}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
var url = refsBaseUrl(org, repo, type)
|
|
50
|
-
ghutils.lister(auth, url, options, callback)
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
module.exports['list' + type[0].toUpperCase() + type.substring(1)] = lister
|
|
54
|
-
|
|
55
|
-
if (type == 'tag')
|
|
56
|
-
return
|
|
57
|
-
|
|
58
|
-
// no getTag API
|
|
59
|
-
var getter = function (auth, org, repo, ref, options, callback) {
|
|
60
|
-
if (typeof options == 'function') {
|
|
61
|
-
callback = options
|
|
62
|
-
options = {}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// a valid ref but we're not using this format
|
|
66
|
-
ref = ref.replace(/^refs\//, '')
|
|
67
|
-
|
|
68
|
-
var url = refsBaseUrl(org, repo, type) + '/' + ref
|
|
69
|
-
ghutils.ghget(auth, url, options, callback)
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
module.exports['get' + singular[0].toUpperCase() + singular.substring(1)] = getter
|
|
73
|
-
})
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
function createLister (type) {
|
|
77
|
-
return function list (auth, org, repo, options, callback) {
|
|
78
|
-
if (typeof options == 'function') {
|
|
79
|
-
callback = options
|
|
80
|
-
options = {}
|
|
81
|
-
}
|
|
27
|
+
export async function listTags (auth, org, repo, options = {}) {
|
|
28
|
+
const url = baseUrl(org, repo, options) + '/tags'
|
|
29
|
+
return lister(auth, url, options)
|
|
30
|
+
}
|
|
82
31
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
32
|
+
export async function listBranches (auth, org, repo, options = {}) {
|
|
33
|
+
const url = baseUrl(org, repo, options) + '/branches'
|
|
34
|
+
return lister(auth, url, options)
|
|
86
35
|
}
|
|
87
36
|
|
|
37
|
+
export async function listCommits (auth, org, repo, options = {}) {
|
|
38
|
+
const url = baseUrl(org, repo, options) + '/commits'
|
|
39
|
+
return lister(auth, url, options)
|
|
40
|
+
}
|
|
88
41
|
|
|
89
|
-
function
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
42
|
+
export async function getRef (auth, org, repo, ref, options = {}) {
|
|
43
|
+
ref = ref.replace(/^refs\//, '')
|
|
44
|
+
const url = baseUrl(org, repo, options) + '/git/refs/' + ref
|
|
45
|
+
const { data } = await ghget(auth, url, options)
|
|
46
|
+
return data
|
|
93
47
|
}
|
|
94
48
|
|
|
49
|
+
export async function getBranch (auth, org, repo, branch, options = {}) {
|
|
50
|
+
const url = baseUrl(org, repo, options) + '/branches/' + branch
|
|
51
|
+
const { data } = await ghget(auth, url, options)
|
|
52
|
+
return data
|
|
53
|
+
}
|
|
95
54
|
|
|
96
|
-
function
|
|
97
|
-
|
|
55
|
+
export async function getCommit (auth, org, repo, sha, options = {}) {
|
|
56
|
+
const url = baseUrl(org, repo, options) + '/commits/' + sha
|
|
57
|
+
const { data } = await ghget(auth, url, options)
|
|
58
|
+
return data
|
|
98
59
|
}
|
|
99
60
|
|
|
61
|
+
export async function getCommitComments (auth, org, repo, sha, options = {}) {
|
|
62
|
+
const url = baseUrl(org, repo, options) + '/commits/' + sha + '/comments'
|
|
63
|
+
const { data } = await ghget(auth, url, options)
|
|
64
|
+
return data
|
|
65
|
+
}
|
|
100
66
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
67
|
+
export function createLister (type) {
|
|
68
|
+
return async function (auth, org, repo, options = {}) {
|
|
69
|
+
const url = baseUrl(org, repo, options) + '/' + type
|
|
70
|
+
return lister(auth, url, options)
|
|
71
|
+
}
|
|
72
|
+
}
|
package/package.json
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ghrepos",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "Interact with the GitHub repos API",
|
|
5
|
-
"
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": "./ghrepos.js",
|
|
7
|
+
"engines": {
|
|
8
|
+
"node": ">=20"
|
|
9
|
+
},
|
|
6
10
|
"scripts": {
|
|
7
|
-
"
|
|
11
|
+
"lint": "standard",
|
|
12
|
+
"build": "true",
|
|
13
|
+
"test:unit": "node --test test.js",
|
|
14
|
+
"test": "npm run lint && npm run test:unit"
|
|
8
15
|
},
|
|
9
16
|
"repository": {
|
|
10
17
|
"type": "git",
|
|
@@ -19,11 +26,98 @@
|
|
|
19
26
|
"author": "Rod Vagg <r@va.gg>",
|
|
20
27
|
"license": "MIT",
|
|
21
28
|
"dependencies": {
|
|
22
|
-
"ghutils": "
|
|
29
|
+
"ghutils": "^5.0.0"
|
|
23
30
|
},
|
|
24
31
|
"devDependencies": {
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"
|
|
32
|
+
"@semantic-release/changelog": "^6.0.3",
|
|
33
|
+
"@semantic-release/commit-analyzer": "^13.0.0",
|
|
34
|
+
"@semantic-release/git": "^10.0.1",
|
|
35
|
+
"@semantic-release/github": "^12.0.0",
|
|
36
|
+
"@semantic-release/npm": "^13.0.0",
|
|
37
|
+
"@semantic-release/release-notes-generator": "^14.0.1",
|
|
38
|
+
"conventional-changelog-conventionalcommits": "^9.0.0",
|
|
39
|
+
"semantic-release": "^25.0.0",
|
|
40
|
+
"standard": "^17.1.2"
|
|
41
|
+
},
|
|
42
|
+
"release": {
|
|
43
|
+
"branches": [
|
|
44
|
+
"master"
|
|
45
|
+
],
|
|
46
|
+
"plugins": [
|
|
47
|
+
[
|
|
48
|
+
"@semantic-release/commit-analyzer",
|
|
49
|
+
{
|
|
50
|
+
"preset": "conventionalcommits",
|
|
51
|
+
"releaseRules": [
|
|
52
|
+
{
|
|
53
|
+
"breaking": true,
|
|
54
|
+
"release": "major"
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
"revert": true,
|
|
58
|
+
"release": "patch"
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
"type": "feat",
|
|
62
|
+
"release": "minor"
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
"type": "fix",
|
|
66
|
+
"release": "patch"
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
"type": "chore",
|
|
70
|
+
"release": "patch"
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
"type": "docs",
|
|
74
|
+
"release": "patch"
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
"type": "test",
|
|
78
|
+
"release": "patch"
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
"scope": "no-release",
|
|
82
|
+
"release": false
|
|
83
|
+
}
|
|
84
|
+
]
|
|
85
|
+
}
|
|
86
|
+
],
|
|
87
|
+
[
|
|
88
|
+
"@semantic-release/release-notes-generator",
|
|
89
|
+
{
|
|
90
|
+
"preset": "conventionalcommits",
|
|
91
|
+
"presetConfig": {
|
|
92
|
+
"types": [
|
|
93
|
+
{
|
|
94
|
+
"type": "feat",
|
|
95
|
+
"section": "Features"
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
"type": "fix",
|
|
99
|
+
"section": "Bug Fixes"
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
"type": "chore",
|
|
103
|
+
"section": "Trivial Changes"
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
"type": "docs",
|
|
107
|
+
"section": "Trivial Changes"
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
"type": "test",
|
|
111
|
+
"section": "Tests"
|
|
112
|
+
}
|
|
113
|
+
]
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
],
|
|
117
|
+
"@semantic-release/changelog",
|
|
118
|
+
"@semantic-release/npm",
|
|
119
|
+
"@semantic-release/github",
|
|
120
|
+
"@semantic-release/git"
|
|
121
|
+
]
|
|
28
122
|
}
|
|
29
123
|
}
|
package/test.js
CHANGED
|
@@ -1,340 +1,252 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
response : [ { test3: 'data3' }, { test4: 'data4' } ]
|
|
15
|
-
, headers : { link: '<https://somenexturl>; rel="next"' }
|
|
16
|
-
}
|
|
17
|
-
, []
|
|
18
|
-
]
|
|
19
|
-
, server
|
|
20
|
-
|
|
21
|
-
server = ghutils.makeServer(testData)
|
|
22
|
-
.on('ready', function () {
|
|
23
|
-
var result = testData[0].response
|
|
24
|
-
ghrepos.listUser(xtend(auth), user, ghutils.verifyData(t, result))
|
|
1
|
+
import { test } from 'node:test'
|
|
2
|
+
import assert from 'node:assert'
|
|
3
|
+
import { createMockServer, createMockServerWithHandler } from 'ghutils/test-util'
|
|
4
|
+
import * as ghrepos from './ghrepos.js'
|
|
5
|
+
|
|
6
|
+
test('list repos for user', async () => {
|
|
7
|
+
const auth = { token: 'test-token' }
|
|
8
|
+
const testData = [{ id: 1, name: 'repo1' }, { id: 2, name: 'repo2' }]
|
|
9
|
+
|
|
10
|
+
const server = await createMockServer({ response: testData })
|
|
11
|
+
try {
|
|
12
|
+
const results = await ghrepos.listUser(auth, 'testuser', {
|
|
13
|
+
_apiUrl: server.baseUrl
|
|
25
14
|
})
|
|
26
|
-
.
|
|
27
|
-
.
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
15
|
+
assert.deepStrictEqual(results, testData)
|
|
16
|
+
assert.ok(server.requests[0].url.includes('/users/testuser/repos'))
|
|
17
|
+
assert.strictEqual(server.requests[0].headers.authorization, 'Bearer test-token')
|
|
18
|
+
} finally {
|
|
19
|
+
await server.close()
|
|
20
|
+
}
|
|
32
21
|
})
|
|
33
22
|
|
|
34
|
-
test('
|
|
35
|
-
|
|
23
|
+
test('list repos for authed user (no user arg)', async () => {
|
|
24
|
+
const auth = { token: 'test-token' }
|
|
25
|
+
const testData = [{ id: 1, name: 'repo1' }]
|
|
36
26
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
response : [ { test3: 'data3' }, { test4: 'data4' } ]
|
|
42
|
-
, headers : { link: '<https://somenexturl>; rel="next"' }
|
|
43
|
-
}
|
|
44
|
-
, []
|
|
45
|
-
]
|
|
46
|
-
, server
|
|
47
|
-
|
|
48
|
-
server = ghutils.makeServer(testData)
|
|
49
|
-
.on('ready', function () {
|
|
50
|
-
var result = testData[0].response
|
|
51
|
-
ghrepos.listOrg(xtend(auth), org, ghutils.verifyData(t, result))
|
|
27
|
+
const server = await createMockServer({ response: testData })
|
|
28
|
+
try {
|
|
29
|
+
const results = await ghrepos.listUser(auth, null, {
|
|
30
|
+
_apiUrl: server.baseUrl
|
|
52
31
|
})
|
|
53
|
-
.
|
|
54
|
-
.
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
.on('close' , ghutils.verifyClose(t))
|
|
32
|
+
assert.deepStrictEqual(results, testData)
|
|
33
|
+
assert.ok(server.requests[0].url.includes('/user/repos'))
|
|
34
|
+
} finally {
|
|
35
|
+
await server.close()
|
|
36
|
+
}
|
|
59
37
|
})
|
|
60
38
|
|
|
61
|
-
test('
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
var auth = { user: 'authuser', token: 'authtoken' }
|
|
65
|
-
, testData = [
|
|
66
|
-
{
|
|
67
|
-
response : [ { test3: 'data3' }, { test4: 'data4' } ]
|
|
68
|
-
, headers : { link: '<https://somenexturl>; rel="next"' }
|
|
69
|
-
}
|
|
70
|
-
, []
|
|
71
|
-
]
|
|
72
|
-
, server
|
|
39
|
+
test('list repos for org', async () => {
|
|
40
|
+
const auth = { token: 'test-token' }
|
|
41
|
+
const testData = [{ id: 1, name: 'repo1' }]
|
|
73
42
|
|
|
74
|
-
server =
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
43
|
+
const server = await createMockServer({ response: testData })
|
|
44
|
+
try {
|
|
45
|
+
const results = await ghrepos.listOrg(auth, 'testorg', {
|
|
46
|
+
_apiUrl: server.baseUrl
|
|
78
47
|
})
|
|
79
|
-
.
|
|
80
|
-
.
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
.on('close' , ghutils.verifyClose(t))
|
|
48
|
+
assert.deepStrictEqual(results, testData)
|
|
49
|
+
assert.ok(server.requests[0].url.includes('/orgs/testorg/repos'))
|
|
50
|
+
} finally {
|
|
51
|
+
await server.close()
|
|
52
|
+
}
|
|
85
53
|
})
|
|
86
54
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
var result = testData[0].response.concat(testData[1].response)
|
|
108
|
-
ghrepos.listUser(xtend(auth), ghutils.verifyData(t, result))
|
|
55
|
+
test('list repos with pagination', async () => {
|
|
56
|
+
const auth = { token: 'test-token' }
|
|
57
|
+
const page1 = [{ id: 1 }, { id: 2 }]
|
|
58
|
+
const page2 = [{ id: 3 }, { id: 4 }]
|
|
59
|
+
|
|
60
|
+
let requestCount = 0
|
|
61
|
+
const mock = await createMockServerWithHandler((req, res) => {
|
|
62
|
+
requestCount++
|
|
63
|
+
const port = mock.address().port
|
|
64
|
+
if (requestCount === 1) {
|
|
65
|
+
res.setHeader('link', `<http://127.0.0.1:${port}/page2>; rel="next"`)
|
|
66
|
+
res.end(JSON.stringify(page1))
|
|
67
|
+
} else {
|
|
68
|
+
res.end(JSON.stringify(page2))
|
|
69
|
+
}
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
try {
|
|
73
|
+
const results = await ghrepos.listUser(auth, 'testuser', {
|
|
74
|
+
_apiUrl: mock.baseUrl
|
|
109
75
|
})
|
|
110
|
-
.
|
|
111
|
-
.
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
]))
|
|
116
|
-
.on('close' , ghutils.verifyClose(t))
|
|
76
|
+
assert.deepStrictEqual(results, [...page1, ...page2])
|
|
77
|
+
assert.strictEqual(requestCount, 2)
|
|
78
|
+
} finally {
|
|
79
|
+
await mock.close()
|
|
80
|
+
}
|
|
117
81
|
})
|
|
118
82
|
|
|
83
|
+
test('list refs', async () => {
|
|
84
|
+
const auth = { token: 'test-token' }
|
|
85
|
+
const refs = [{ ref: 'refs/heads/main' }, { ref: 'refs/tags/v1' }]
|
|
119
86
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
, testData = [ [] ]
|
|
125
|
-
, server
|
|
126
|
-
|
|
127
|
-
server = ghutils.makeServer(testData)
|
|
128
|
-
.on('ready', function () {
|
|
129
|
-
ghrepos.listUser(xtend(auth), ghutils.verifyData(t, []))
|
|
87
|
+
const server = await createMockServer({ response: refs })
|
|
88
|
+
try {
|
|
89
|
+
const results = await ghrepos.listRefs(auth, 'testorg', 'testrepo', {
|
|
90
|
+
_apiUrl: server.baseUrl
|
|
130
91
|
})
|
|
131
|
-
.
|
|
132
|
-
.
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
92
|
+
assert.deepStrictEqual(results, refs)
|
|
93
|
+
assert.ok(server.requests[0].url.includes('/repos/testorg/testrepo/git/refs'))
|
|
94
|
+
} finally {
|
|
95
|
+
await server.close()
|
|
96
|
+
}
|
|
136
97
|
})
|
|
137
98
|
|
|
99
|
+
test('list tags', async () => {
|
|
100
|
+
const auth = { token: 'test-token' }
|
|
101
|
+
const tags = [{ name: 'v1.0.0' }, { name: 'v2.0.0' }]
|
|
138
102
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
, org = 'testorg'
|
|
144
|
-
, repo = 'testrepo'
|
|
145
|
-
, testData = [
|
|
146
|
-
{
|
|
147
|
-
response : [ { test3: 'data3' }, { test4: 'data4' } ]
|
|
148
|
-
, headers : { link: '<https://somenexturl>; rel="next"' }
|
|
149
|
-
}
|
|
150
|
-
, {
|
|
151
|
-
response : [ { test5: 'data5' }, { test6: 'data6' } ]
|
|
152
|
-
, headers : { link: '<https://somenexturl2>; rel="next"' }
|
|
153
|
-
}
|
|
154
|
-
, []
|
|
155
|
-
]
|
|
156
|
-
, server
|
|
157
|
-
|
|
158
|
-
server = ghutils.makeServer(testData)
|
|
159
|
-
.on('ready', function () {
|
|
160
|
-
var result = testData[0].response.concat(testData[1].response)
|
|
161
|
-
ghrepos.listRefs(xtend(auth), org, repo, ghutils.verifyData(t, result))
|
|
103
|
+
const server = await createMockServer({ response: tags })
|
|
104
|
+
try {
|
|
105
|
+
const results = await ghrepos.listTags(auth, 'testorg', 'testrepo', {
|
|
106
|
+
_apiUrl: server.baseUrl
|
|
162
107
|
})
|
|
163
|
-
.
|
|
164
|
-
.
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
]))
|
|
169
|
-
.on('close' , ghutils.verifyClose(t))
|
|
108
|
+
assert.deepStrictEqual(results, tags)
|
|
109
|
+
assert.ok(server.requests[0].url.includes('/repos/testorg/testrepo/tags'))
|
|
110
|
+
} finally {
|
|
111
|
+
await server.close()
|
|
112
|
+
}
|
|
170
113
|
})
|
|
171
114
|
|
|
115
|
+
test('list branches', async () => {
|
|
116
|
+
const auth = { token: 'test-token' }
|
|
117
|
+
const branches = [{ name: 'main' }, { name: 'dev' }]
|
|
172
118
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
, org = 'testorg'
|
|
178
|
-
, repo = 'testrepo'
|
|
179
|
-
, testData = [
|
|
180
|
-
{
|
|
181
|
-
response : [ { test3: 'data3' }, { test4: 'data4' } ]
|
|
182
|
-
, headers : { link: '<https://somenexturl>; rel="next"' }
|
|
183
|
-
}
|
|
184
|
-
, {
|
|
185
|
-
response : [ { test5: 'data5' }, { test6: 'data6' } ]
|
|
186
|
-
, headers : { link: '<https://somenexturl2>; rel="next"' }
|
|
187
|
-
}
|
|
188
|
-
, []
|
|
189
|
-
]
|
|
190
|
-
, server
|
|
191
|
-
|
|
192
|
-
server = ghutils.makeServer(testData)
|
|
193
|
-
.on('ready', function () {
|
|
194
|
-
var result = testData[0].response.concat(testData[1].response)
|
|
195
|
-
ghrepos.listBranches(xtend(auth), org, repo, ghutils.verifyData(t, result))
|
|
119
|
+
const server = await createMockServer({ response: branches })
|
|
120
|
+
try {
|
|
121
|
+
const results = await ghrepos.listBranches(auth, 'testorg', 'testrepo', {
|
|
122
|
+
_apiUrl: server.baseUrl
|
|
196
123
|
})
|
|
197
|
-
.
|
|
198
|
-
.
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
]))
|
|
203
|
-
.on('close' , ghutils.verifyClose(t))
|
|
124
|
+
assert.deepStrictEqual(results, branches)
|
|
125
|
+
assert.ok(server.requests[0].url.includes('/repos/testorg/testrepo/branches'))
|
|
126
|
+
} finally {
|
|
127
|
+
await server.close()
|
|
128
|
+
}
|
|
204
129
|
})
|
|
205
130
|
|
|
131
|
+
test('list commits', async () => {
|
|
132
|
+
const auth = { token: 'test-token' }
|
|
133
|
+
const commits = [{ sha: 'abc123' }, { sha: 'def456' }]
|
|
206
134
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
, org = 'testorg'
|
|
212
|
-
, repo = 'testrepo'
|
|
213
|
-
, testData = [
|
|
214
|
-
{
|
|
215
|
-
response : [ { test3: 'data3' }, { test4: 'data4' } ]
|
|
216
|
-
, headers : { link: '<https://somenexturl>; rel="next"' }
|
|
217
|
-
}
|
|
218
|
-
, {
|
|
219
|
-
response : [ { test5: 'data5' }, { test6: 'data6' } ]
|
|
220
|
-
, headers : { link: '<https://somenexturl2>; rel="next"' }
|
|
221
|
-
}
|
|
222
|
-
, []
|
|
223
|
-
]
|
|
224
|
-
, server
|
|
225
|
-
|
|
226
|
-
server = ghutils.makeServer(testData)
|
|
227
|
-
.on('ready', function () {
|
|
228
|
-
var result = testData[0].response.concat(testData[1].response)
|
|
229
|
-
ghrepos.listTags(xtend(auth), org, repo, ghutils.verifyData(t, result))
|
|
135
|
+
const server = await createMockServer({ response: commits })
|
|
136
|
+
try {
|
|
137
|
+
const results = await ghrepos.listCommits(auth, 'testorg', 'testrepo', {
|
|
138
|
+
_apiUrl: server.baseUrl
|
|
230
139
|
})
|
|
231
|
-
.
|
|
232
|
-
.
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
]))
|
|
237
|
-
.on('close' , ghutils.verifyClose(t))
|
|
140
|
+
assert.deepStrictEqual(results, commits)
|
|
141
|
+
assert.ok(server.requests[0].url.includes('/repos/testorg/testrepo/commits'))
|
|
142
|
+
} finally {
|
|
143
|
+
await server.close()
|
|
144
|
+
}
|
|
238
145
|
})
|
|
239
146
|
|
|
147
|
+
test('get ref', async () => {
|
|
148
|
+
const auth = { token: 'test-token' }
|
|
149
|
+
const refData = { ref: 'refs/heads/main', object: { sha: 'abc123' } }
|
|
240
150
|
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
, org = 'testorg'
|
|
246
|
-
, repo = 'testrepo'
|
|
247
|
-
, ref = 'head/testref'
|
|
248
|
-
, testData = [
|
|
249
|
-
{ test3: 'data3' }
|
|
250
|
-
]
|
|
251
|
-
, server
|
|
252
|
-
|
|
253
|
-
server = ghutils.makeServer(testData)
|
|
254
|
-
.on('ready', function () {
|
|
255
|
-
ghrepos.getRef(xtend(auth), org, repo, ref, ghutils.verifyData(t, testData[0]))
|
|
151
|
+
const server = await createMockServer({ response: refData })
|
|
152
|
+
try {
|
|
153
|
+
const result = await ghrepos.getRef(auth, 'testorg', 'testrepo', 'heads/main', {
|
|
154
|
+
_apiUrl: server.baseUrl
|
|
256
155
|
})
|
|
257
|
-
.
|
|
258
|
-
.
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
156
|
+
assert.deepStrictEqual(result, refData)
|
|
157
|
+
assert.ok(server.requests[0].url.includes('/repos/testorg/testrepo/git/refs/heads/main'))
|
|
158
|
+
} finally {
|
|
159
|
+
await server.close()
|
|
160
|
+
}
|
|
262
161
|
})
|
|
263
162
|
|
|
163
|
+
test('get ref strips refs/ prefix', async () => {
|
|
164
|
+
const auth = { token: 'test-token' }
|
|
165
|
+
const refData = { ref: 'refs/heads/main' }
|
|
264
166
|
|
|
265
|
-
|
|
266
|
-
|
|
167
|
+
const server = await createMockServer({ response: refData })
|
|
168
|
+
try {
|
|
169
|
+
await ghrepos.getRef(auth, 'testorg', 'testrepo', 'refs/heads/main', {
|
|
170
|
+
_apiUrl: server.baseUrl
|
|
171
|
+
})
|
|
172
|
+
assert.ok(server.requests[0].url.includes('/git/refs/heads/main'))
|
|
173
|
+
assert.ok(!server.requests[0].url.includes('/git/refs/refs/'))
|
|
174
|
+
} finally {
|
|
175
|
+
await server.close()
|
|
176
|
+
}
|
|
177
|
+
})
|
|
267
178
|
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
, branch = 'testbranch'
|
|
272
|
-
, testData = [
|
|
273
|
-
{ test3: 'data3' }
|
|
274
|
-
]
|
|
275
|
-
, server
|
|
179
|
+
test('get branch', async () => {
|
|
180
|
+
const auth = { token: 'test-token' }
|
|
181
|
+
const branchData = { name: 'main', commit: { sha: 'abc123' } }
|
|
276
182
|
|
|
277
|
-
server =
|
|
278
|
-
|
|
279
|
-
|
|
183
|
+
const server = await createMockServer({ response: branchData })
|
|
184
|
+
try {
|
|
185
|
+
const result = await ghrepos.getBranch(auth, 'testorg', 'testrepo', 'main', {
|
|
186
|
+
_apiUrl: server.baseUrl
|
|
280
187
|
})
|
|
281
|
-
.
|
|
282
|
-
.
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
188
|
+
assert.deepStrictEqual(result, branchData)
|
|
189
|
+
assert.ok(server.requests[0].url.includes('/repos/testorg/testrepo/branches/main'))
|
|
190
|
+
} finally {
|
|
191
|
+
await server.close()
|
|
192
|
+
}
|
|
286
193
|
})
|
|
287
194
|
|
|
195
|
+
test('get commit', async () => {
|
|
196
|
+
const auth = { token: 'test-token' }
|
|
197
|
+
const commitData = { sha: 'abc123', author: { login: 'testuser' } }
|
|
288
198
|
|
|
289
|
-
|
|
290
|
-
|
|
199
|
+
const server = await createMockServer({ response: commitData })
|
|
200
|
+
try {
|
|
201
|
+
const result = await ghrepos.getCommit(auth, 'testorg', 'testrepo', 'abc123', {
|
|
202
|
+
_apiUrl: server.baseUrl
|
|
203
|
+
})
|
|
204
|
+
assert.deepStrictEqual(result, commitData)
|
|
205
|
+
assert.ok(server.requests[0].url.includes('/repos/testorg/testrepo/commits/abc123'))
|
|
206
|
+
} finally {
|
|
207
|
+
await server.close()
|
|
208
|
+
}
|
|
209
|
+
})
|
|
291
210
|
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
, ref = 'head/testref'
|
|
296
|
-
, testData = [
|
|
297
|
-
{ test3: 'data3' }
|
|
298
|
-
]
|
|
299
|
-
, server
|
|
211
|
+
test('get commit comments', async () => {
|
|
212
|
+
const auth = { token: 'test-token' }
|
|
213
|
+
const comments = [{ id: 1, body: 'nice' }]
|
|
300
214
|
|
|
301
|
-
server =
|
|
302
|
-
|
|
303
|
-
|
|
215
|
+
const server = await createMockServer({ response: comments })
|
|
216
|
+
try {
|
|
217
|
+
const result = await ghrepos.getCommitComments(auth, 'testorg', 'testrepo', 'abc123', {
|
|
218
|
+
_apiUrl: server.baseUrl
|
|
304
219
|
})
|
|
305
|
-
.
|
|
306
|
-
.
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
220
|
+
assert.deepStrictEqual(result, comments)
|
|
221
|
+
assert.ok(server.requests[0].url.includes('/repos/testorg/testrepo/commits/abc123/comments'))
|
|
222
|
+
} finally {
|
|
223
|
+
await server.close()
|
|
224
|
+
}
|
|
310
225
|
})
|
|
311
226
|
|
|
227
|
+
test('createLister produces working lister', async () => {
|
|
228
|
+
const auth = { token: 'test-token' }
|
|
229
|
+
const data = [{ id: 1 }, { id: 2 }]
|
|
230
|
+
const customLister = ghrepos.createLister('footype')
|
|
312
231
|
|
|
313
|
-
|
|
314
|
-
|
|
232
|
+
const server = await createMockServer({ response: data })
|
|
233
|
+
try {
|
|
234
|
+
const results = await customLister(auth, 'testorg', 'testrepo', {
|
|
235
|
+
_apiUrl: server.baseUrl
|
|
236
|
+
})
|
|
237
|
+
assert.deepStrictEqual(results, data)
|
|
238
|
+
assert.ok(server.requests[0].url.includes('/repos/testorg/testrepo/footype'))
|
|
239
|
+
} finally {
|
|
240
|
+
await server.close()
|
|
241
|
+
}
|
|
242
|
+
})
|
|
315
243
|
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
{
|
|
321
|
-
response : [ { test3: 'data3' }, { test4: 'data4' } ]
|
|
322
|
-
, headers : { link: '<https://somenexturl>; rel="next"' }
|
|
323
|
-
}
|
|
324
|
-
, []
|
|
325
|
-
]
|
|
326
|
-
, lister = ghrepos.createLister('footype')
|
|
327
|
-
, server
|
|
244
|
+
test('baseUrl returns correct URL', () => {
|
|
245
|
+
const url = ghrepos.baseUrl('myorg', 'myrepo')
|
|
246
|
+
assert.strictEqual(url, 'https://api.github.com/repos/myorg/myrepo')
|
|
247
|
+
})
|
|
328
248
|
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
lister(xtend(auth), org, repo, ghutils.verifyData(t, result))
|
|
333
|
-
})
|
|
334
|
-
.on('request', ghutils.verifyRequest(t, auth))
|
|
335
|
-
.on('get', ghutils.verifyUrl(t, [
|
|
336
|
-
'https://api.github.com/repos/' + org + '/' + repo + '/footype'
|
|
337
|
-
, 'https://somenexturl'
|
|
338
|
-
]))
|
|
339
|
-
.on('close' , ghutils.verifyClose(t))
|
|
249
|
+
test('baseUrl respects _apiUrl option', () => {
|
|
250
|
+
const url = ghrepos.baseUrl('myorg', 'myrepo', { _apiUrl: 'http://localhost:3000' })
|
|
251
|
+
assert.strictEqual(url, 'http://localhost:3000/repos/myorg/myrepo')
|
|
340
252
|
})
|
package/.jshintrc
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"predef": [ ]
|
|
3
|
-
, "bitwise": false
|
|
4
|
-
, "camelcase": false
|
|
5
|
-
, "curly": false
|
|
6
|
-
, "eqeqeq": false
|
|
7
|
-
, "forin": false
|
|
8
|
-
, "immed": false
|
|
9
|
-
, "latedef": false
|
|
10
|
-
, "noarg": true
|
|
11
|
-
, "noempty": true
|
|
12
|
-
, "nonew": true
|
|
13
|
-
, "plusplus": false
|
|
14
|
-
, "quotmark": true
|
|
15
|
-
, "regexp": false
|
|
16
|
-
, "undef": true
|
|
17
|
-
, "unused": true
|
|
18
|
-
, "strict": false
|
|
19
|
-
, "trailing": true
|
|
20
|
-
, "maxlen": 120
|
|
21
|
-
, "asi": true
|
|
22
|
-
, "boss": true
|
|
23
|
-
, "debug": true
|
|
24
|
-
, "eqnull": true
|
|
25
|
-
, "esnext": true
|
|
26
|
-
, "evil": true
|
|
27
|
-
, "expr": true
|
|
28
|
-
, "funcscope": false
|
|
29
|
-
, "globalstrict": false
|
|
30
|
-
, "iterator": false
|
|
31
|
-
, "lastsemic": true
|
|
32
|
-
, "laxbreak": true
|
|
33
|
-
, "laxcomma": true
|
|
34
|
-
, "loopfunc": true
|
|
35
|
-
, "multistr": false
|
|
36
|
-
, "onecase": false
|
|
37
|
-
, "proto": false
|
|
38
|
-
, "regexdash": false
|
|
39
|
-
, "scripturl": true
|
|
40
|
-
, "smarttabs": false
|
|
41
|
-
, "shadow": false
|
|
42
|
-
, "sub": true
|
|
43
|
-
, "supernew": false
|
|
44
|
-
, "validthis": true
|
|
45
|
-
, "browser": true
|
|
46
|
-
, "couch": false
|
|
47
|
-
, "devel": false
|
|
48
|
-
, "dojo": false
|
|
49
|
-
, "mootools": false
|
|
50
|
-
, "node": true
|
|
51
|
-
, "nonstandard": true
|
|
52
|
-
, "prototypejs": false
|
|
53
|
-
, "rhino": false
|
|
54
|
-
, "worker": true
|
|
55
|
-
, "wsh": false
|
|
56
|
-
, "nomen": false
|
|
57
|
-
, "onevar": false
|
|
58
|
-
, "passfail": false
|
|
59
|
-
}
|
package/.npmignore
DELETED