ghteams 0.3.0 → 1.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.
@@ -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,9 @@
1
+ ## [1.0.0](https://github.com/rvagg/ghteams/compare/v0.3.0...v1.0.0) (2026-01-27)
2
+
3
+ ### ⚠ BREAKING CHANGES
4
+
5
+ * modernise, ESM, promises, update deps, GHA, auto-release (#1)
6
+
7
+ ### Features
8
+
9
+ * modernise, ESM, promises, update deps, GHA, auto-release ([#1](https://github.com/rvagg/ghteams/issues/1)) ([ca8a576](https://github.com/rvagg/ghteams/commit/ca8a576841101a846abbd0999ca96ff59d0bd8be))
package/README.md CHANGED
@@ -1,86 +1,93 @@
1
1
  # ghteams
2
2
 
3
- [![Build Status](https://secure.travis-ci.org/rvagg/ghteams.png)](http://travis-ci.org/rvagg/ghteams)
3
+ **A Node.js library to interact with the GitHub organisation teams API**
4
4
 
5
- **A node library to interact with the GitHub organisation teams API**
5
+ [![NPM](https://nodei.co/npm/ghteams.svg?style=flat&data=n,v&color=blue)](https://nodei.co/npm/ghteams/)
6
6
 
7
- [![NPM](https://nodei.co/npm/ghteams.png?mini=true)](https://nodei.co/npm/ghteams/)
7
+ ## Requirements
8
+
9
+ - Node.js >= 20
8
10
 
9
11
  ## Example usage
10
12
 
11
13
  ```js
12
- const ghteams = require('ghteams')
13
- , authOptions = { user: 'rvagg', token: '24d5dee258c64aef38a66c0c5eca459c379901c2' }
14
- // note the auth token needs the 'user' scope to deal with org teams
14
+ import * as ghteams from 'ghteams'
15
15
 
16
+ const auth = { token: 'your-github-token' }
17
+ // note: the auth token needs the 'user' scope to deal with org teams
16
18
 
17
19
  // list all teams in an organisation
20
+ const teams = await ghteams.list(auth, 'myorg')
21
+ console.log(teams)
18
22
 
19
- ghteams.list(authOptions, 'myorg', function (err, teamlist) {
20
- // Array of team data for 'myorg'
21
- console.log(teamlist)
22
- })
23
+ // get team data by team name in an organisation
24
+ const team = await ghteams.get(auth, 'myorg', 'myteam')
25
+ console.log(team)
23
26
 
27
+ // get team data by team id (quicker)
28
+ const teamById = await ghteams.get(auth, 123456)
29
+ console.log(teamById)
24
30
 
25
- // get team data by team name in an organisation
31
+ // get team members by team name in an organisation
32
+ const members = await ghteams.members(auth, 'myorg', 'myteam')
33
+ console.log(members)
26
34
 
27
- ghteams.get(authOptions, 'myorg', 'myteam', function (err, team) {
28
- // object containing full team data for myorg/myteam
29
- console.log(team)
30
- })
35
+ // get team members by team id (quicker)
36
+ const membersById = await ghteams.members(auth, 123456)
37
+ console.log(membersById)
38
+
39
+ // get teams the authenticated user belongs to
40
+ const myTeams = await ghteams.userTeams(auth)
41
+ console.log(myTeams)
42
+ ```
31
43
 
44
+ The auth data is compatible with [ghauth](https://github.com/rvagg/ghauth) so you can connect them together:
32
45
 
33
- // get team data by team id (quicker)
34
- ghteams.get(authOptions, 123456, function (err, team) {
35
- // object containing full team data team #123456
36
- console.log(team)
46
+ ```js
47
+ import ghauth from 'ghauth'
48
+ import * as ghteams from 'ghteams'
49
+
50
+ const auth = await ghauth({
51
+ configName: 'team-lister',
52
+ scopes: ['user']
37
53
  })
38
54
 
55
+ const teams = await ghteams.list(auth, 'myorg')
56
+ console.log('Teams in "myorg":', teams.map((t) => t.name).join(', '))
57
+ ```
39
58
 
40
- // get team members by team name in an organisation
59
+ ## API
41
60
 
42
- ghteams.members(authOptions, 'myorg', 'myteam', function (err, members) {
43
- // Array containing full list of team members for myorg/myteam
44
- console.log(members)
45
- })
61
+ All methods return Promises.
46
62
 
63
+ ### ghteams.list(auth, org, options)
47
64
 
48
- // get team members by team id (quicker)
49
- ghteams.members(authOptions, 123456, function (err, members) {
50
- // Array containing full list of team members team #123456
51
- console.log(members)
52
- })
65
+ List all teams in an organisation.
53
66
 
67
+ ### ghteams.get(auth, org, name, options)
54
68
 
55
- // get teams to which the user represented by `authOptions` is a member of
56
- ghteams.userTeams(authOptions, function (err, teams) {
57
- // Array cotnaining full list of teams to which the current
58
- // authenticated user belongs
59
- console.log(teams)
60
- })
61
- ```
69
+ Get team data by team name in an organisation. If `name` is omitted and `org` is a numeric team ID, fetches the team directly by ID (quicker).
62
70
 
71
+ ### ghteams.members(auth, org, name, options)
63
72
 
64
- The auth data is compatible with [ghauth](https://github.com/rvagg/ghauth) so you can just connect them together to make a simple command-line application:
73
+ Get team members by team name in an organisation. If `name` is omitted and `org` is a numeric team ID, fetches members directly by ID (quicker).
65
74
 
66
- ```js
67
- const ghauth = require('ghauth')
68
- , ghteams = require('ghteams')
69
- , authOptions = {
70
- configName : 'team-lister'
71
- , scopes : [ 'user' ]
72
- }
73
-
74
- ghauth(authOptions, function (err, authData) {
75
- ghteams.list(authData, 'myorg', function (err, list) {
76
- console.log('Teams in "myorg": ', list.map(function (t) {
77
- return t.name
78
- }).join(', '))
79
- })
80
- })
81
- ```
75
+ ### ghteams.userTeams(auth, options)
76
+
77
+ Get all teams the authenticated user belongs to.
78
+
79
+ ## Authentication
80
+
81
+ 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 ghteams methods.
82
+
83
+ ## See also
82
84
 
85
+ * [ghissues](https://github.com/rvagg/ghissues) - interact with the GitHub issues API
86
+ * [ghusers](https://github.com/rvagg/ghusers) - interact with the GitHub users API
87
+ * [ghpulls](https://github.com/rvagg/ghpulls) - interact with the GitHub pull requests API
88
+ * [ghrepos](https://github.com/rvagg/ghrepos) - interact with the GitHub repos API
89
+ * [ghauth](https://github.com/rvagg/ghauth) - GitHub authentication
83
90
 
84
91
  ## License
85
92
 
86
- **ghteams** is Copyright (c) 2014 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.
93
+ **ghteams** 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.
package/ghteams.js CHANGED
@@ -1,97 +1,53 @@
1
- const jsonist = require('jsonist')
2
- , ghutils = require('ghutils')
1
+ import { ghget, lister } from 'ghutils'
3
2
 
3
+ const defaultApiUrl = 'https://api.github.com'
4
4
 
5
- function list (auth, org, options, callback) {
6
- if (typeof options == 'function') { // no options
7
- callback = options
8
- options = {}
9
- }
10
-
11
- var urlbase = 'https://api.github.com/orgs/' + org + '/teams'
12
-
13
- ghutils.lister(auth, urlbase, options, callback)
5
+ export async function list (auth, org, options = {}) {
6
+ const apiUrl = options._apiUrl || defaultApiUrl
7
+ const url = `${apiUrl}/orgs/${org}/teams`
8
+ return lister(auth, url, options)
14
9
  }
15
10
 
16
-
17
- function teamIdByName (auth, org, name, callback) {
18
- list(auth, org, function (err, teams) {
19
- if (err)
20
- return callback(err)
21
-
22
- var team = teams.filter(function (team) {
23
- return team.name == name
24
- })[0]
25
-
26
- if (!team)
27
- return callback(new Error('No such team [' + name + '] for org [' + org + ']'))
28
-
29
- callback(null, team.id)
30
- })
31
- }
32
-
33
-
34
- function getById (auth, id, options, callback) {
35
- if (typeof options == 'function') { // no options
36
- callback = options
37
- options = {}
11
+ async function teamIdByName (auth, org, name, options = {}) {
12
+ const teams = await list(auth, org, options)
13
+ const team = teams.find((t) => t.name === name)
14
+ if (!team) {
15
+ throw new Error(`No such team [${name}] for org [${org}]`)
38
16
  }
39
-
40
- ghutils.ghget(auth, 'https://api.github.com/teams/' + id, options, callback)
17
+ return team.id
41
18
  }
42
19
 
43
-
44
- function get (auth, org, name, callback) {
45
- if (typeof name == 'function')
46
- return getById(auth, org, name)
47
-
48
- teamIdByName(auth, org, name, function (err, id) {
49
- if (err)
50
- return callback(err)
51
-
52
- getById(auth, id, callback)
53
- })
20
+ async function getById (auth, id, options = {}) {
21
+ const apiUrl = options._apiUrl || defaultApiUrl
22
+ const url = `${apiUrl}/teams/${id}`
23
+ const { data } = await ghget(auth, url, options)
24
+ return data
54
25
  }
55
26
 
56
-
57
- function membersById (auth, id, options, callback) {
58
- if (typeof options == 'function') { // no options
59
- callback = options
60
- options = {}
27
+ export async function get (auth, org, name, options = {}) {
28
+ if (name === undefined) {
29
+ return getById(auth, org, options)
61
30
  }
62
-
63
- var urlbase = 'https://api.github.com/teams/' + id + '/members'
64
-
65
- ghutils.lister(auth, urlbase, options, callback)
31
+ const id = await teamIdByName(auth, org, name, options)
32
+ return getById(auth, id, options)
66
33
  }
67
34
 
68
-
69
- function members (auth, org, name, callback) {
70
- if (typeof name == 'function')
71
- return membersById(auth, org, name)
72
-
73
- teamIdByName(auth, org, name, function (err, id) {
74
- if (err)
75
- return callback(err)
76
-
77
- membersById(auth, id, callback)
78
- })
35
+ async function membersById (auth, id, options = {}) {
36
+ const apiUrl = options._apiUrl || defaultApiUrl
37
+ const url = `${apiUrl}/teams/${id}/members`
38
+ return lister(auth, url, options)
79
39
  }
80
40
 
81
-
82
- function userTeams (auth, options, callback) {
83
- if (typeof options == 'function') { // no options
84
- callback = options
85
- options = {}
41
+ export async function members (auth, org, name, options = {}) {
42
+ if (name === undefined) {
43
+ return membersById(auth, org, options)
86
44
  }
87
-
88
- var urlbase = 'https://api.github.com/user/teams'
89
-
90
- ghutils.lister(auth, urlbase, options, callback)
45
+ const id = await teamIdByName(auth, org, name, options)
46
+ return membersById(auth, id, options)
91
47
  }
92
48
 
93
-
94
- module.exports.list = list
95
- module.exports.get = get
96
- module.exports.members = members
97
- module.exports.userTeams = userTeams
49
+ export async function userTeams (auth, options = {}) {
50
+ const apiUrl = options._apiUrl || defaultApiUrl
51
+ const url = `${apiUrl}/user/teams`
52
+ return lister(auth, url, options)
53
+ }
package/package.json CHANGED
@@ -1,10 +1,17 @@
1
1
  {
2
2
  "name": "ghteams",
3
- "version": "0.3.0",
3
+ "version": "1.0.0",
4
4
  "description": "Interact with the GitHub organisation teams API",
5
- "main": "ghteams.js",
5
+ "type": "module",
6
+ "exports": "./ghteams.js",
7
+ "engines": {
8
+ "node": ">=20"
9
+ },
6
10
  "scripts": {
7
- "test": "node test.js | faucet"
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",
@@ -23,12 +30,98 @@
23
30
  },
24
31
  "homepage": "https://github.com/rvagg/ghteams",
25
32
  "dependencies": {
26
- "ghutils": "~1.2.1",
27
- "jsonist": "~1.0.2"
33
+ "ghutils": "^5.0.0"
28
34
  },
29
35
  "devDependencies": {
30
- "faucet": "0.0.1",
31
- "tape": "~4.0.0",
32
- "xtend": "~4.0.0"
36
+ "@semantic-release/changelog": "^6.0.3",
37
+ "@semantic-release/commit-analyzer": "^13.0.0",
38
+ "@semantic-release/git": "^10.0.1",
39
+ "@semantic-release/github": "^12.0.0",
40
+ "@semantic-release/npm": "^13.0.0",
41
+ "@semantic-release/release-notes-generator": "^14.0.1",
42
+ "conventional-changelog-conventionalcommits": "^9.0.0",
43
+ "semantic-release": "^25.0.0",
44
+ "standard": "^17.1.2"
45
+ },
46
+ "release": {
47
+ "branches": [
48
+ "master"
49
+ ],
50
+ "plugins": [
51
+ [
52
+ "@semantic-release/commit-analyzer",
53
+ {
54
+ "preset": "conventionalcommits",
55
+ "releaseRules": [
56
+ {
57
+ "breaking": true,
58
+ "release": "major"
59
+ },
60
+ {
61
+ "revert": true,
62
+ "release": "patch"
63
+ },
64
+ {
65
+ "type": "feat",
66
+ "release": "minor"
67
+ },
68
+ {
69
+ "type": "fix",
70
+ "release": "patch"
71
+ },
72
+ {
73
+ "type": "chore",
74
+ "release": "patch"
75
+ },
76
+ {
77
+ "type": "docs",
78
+ "release": "patch"
79
+ },
80
+ {
81
+ "type": "test",
82
+ "release": "patch"
83
+ },
84
+ {
85
+ "scope": "no-release",
86
+ "release": false
87
+ }
88
+ ]
89
+ }
90
+ ],
91
+ [
92
+ "@semantic-release/release-notes-generator",
93
+ {
94
+ "preset": "conventionalcommits",
95
+ "presetConfig": {
96
+ "types": [
97
+ {
98
+ "type": "feat",
99
+ "section": "Features"
100
+ },
101
+ {
102
+ "type": "fix",
103
+ "section": "Bug Fixes"
104
+ },
105
+ {
106
+ "type": "chore",
107
+ "section": "Trivial Changes"
108
+ },
109
+ {
110
+ "type": "docs",
111
+ "section": "Trivial Changes"
112
+ },
113
+ {
114
+ "type": "test",
115
+ "section": "Tests"
116
+ }
117
+ ]
118
+ }
119
+ }
120
+ ],
121
+ "@semantic-release/changelog",
122
+ "@semantic-release/npm",
123
+ "@semantic-release/github",
124
+ "@semantic-release/git"
125
+ ]
33
126
  }
34
127
  }
package/test.js CHANGED
@@ -1,143 +1,139 @@
1
- const ghutils = require('ghutils/test')
2
- , ghteams = require('./')
3
- , test = require('tape')
4
- , xtend = require('xtend')
5
-
6
-
7
- test('test list teams', function (t) {
8
- t.plan(10)
9
-
10
- var auth = { user: 'authuser', token: 'authtoken' }
11
- , org = 'testorg'
12
- , testData = [ [ { test: 'data' } ], [] ]
13
-
14
- ghutils.makeServer(testData)
15
- .on('ready', function () {
16
- ghteams.list(xtend(auth), org, ghutils.verifyData(t, testData[0]))
1
+ import { test } from 'node:test'
2
+ import assert from 'node:assert'
3
+ import { createMockServer, createMockServerWithHandler } from 'ghutils/test-util'
4
+ import * as ghteams from './ghteams.js'
5
+
6
+ test('list teams', async () => {
7
+ const auth = { token: 'test-token' }
8
+ const testData = [{ id: 1, name: 'Team A' }, { id: 2, name: 'Team B' }]
9
+
10
+ const server = await createMockServer({ response: testData })
11
+ try {
12
+ const results = await ghteams.list(auth, 'testorg', {
13
+ _apiUrl: server.baseUrl
17
14
  })
18
- .on('request', ghutils.verifyRequest(t, auth))
19
- .on('get' , ghutils.verifyUrl(t, [
20
- 'https://api.github.com/orgs/testorg/teams?page=1'
21
- , 'https://api.github.com/orgs/testorg/teams?page=2'
22
- ]))
23
- .on('close' , ghutils.verifyClose(t))
15
+ assert.deepStrictEqual(results, testData)
16
+ assert.ok(server.requests[0].url.includes('/orgs/testorg/teams'))
17
+ } finally {
18
+ await server.close()
19
+ }
24
20
  })
25
21
 
22
+ test('get team by id', async () => {
23
+ const auth = { token: 'test-token' }
24
+ const testData = { id: 101, name: 'My Team' }
26
25
 
27
- test('test get team by id', function (t) {
28
- t.plan(7)
29
-
30
- var auth = { user: 'authuser2', token: 'authtoken2' }
31
- , teamId = 101
32
- , testData = [ { test: 'team data' } ]
33
-
34
- ghutils.makeServer(testData)
35
- .on('ready', function () {
36
- ghteams.get(xtend(auth), teamId, ghutils.verifyData(t, testData[0]))
26
+ const server = await createMockServer({ response: testData })
27
+ try {
28
+ const result = await ghteams.get(auth, 101, undefined, {
29
+ _apiUrl: server.baseUrl
37
30
  })
38
- .on('request', ghutils.verifyRequest(t, auth))
39
- .on('get' , ghutils.verifyUrl(t, [ 'https://api.github.com/teams/' + teamId ]))
40
- .on('close' , ghutils.verifyClose(t))
31
+ assert.deepStrictEqual(result, testData)
32
+ assert.ok(server.requests[0].url.includes('/teams/101'))
33
+ } finally {
34
+ await server.close()
35
+ }
41
36
  })
42
37
 
43
-
44
- test('test get members by id', function (t) {
45
- t.plan(10)
46
-
47
- var auth = { user: 'authuser2', token: 'authtoken2' }
48
- , teamId = 101
49
- , testData = [ [ { test: 'team data' } ], [] ]
50
-
51
- ghutils.makeServer(testData)
52
- .on('ready', function () {
53
- ghteams.members(xtend(auth), teamId, ghutils.verifyData(t, testData[0]))
38
+ test('get team by org and name', async () => {
39
+ const auth = { token: 'test-token' }
40
+ const teamList = [{ id: 101, name: 'foo' }, { id: 202, name: 'myteam' }, { id: 303, name: 'bar' }]
41
+ const teamData = { id: 202, name: 'myteam', description: 'My Team' }
42
+
43
+ let requestCount = 0
44
+ const mock = await createMockServerWithHandler((req, res) => {
45
+ requestCount++
46
+ if (requestCount === 1) {
47
+ res.end(JSON.stringify(teamList))
48
+ } else {
49
+ res.end(JSON.stringify(teamData))
50
+ }
51
+ })
52
+
53
+ try {
54
+ const result = await ghteams.get(auth, 'myorg', 'myteam', {
55
+ _apiUrl: mock.baseUrl
54
56
  })
55
- .on('request', ghutils.verifyRequest(t, auth))
56
- .on('get' , ghutils.verifyUrl(t, [
57
- 'https://api.github.com/teams/' + teamId + '/members?page=1'
58
- , 'https://api.github.com/teams/' + teamId + '/members?page=2'
59
- ]))
60
- .on('close' , ghutils.verifyClose(t))
57
+ assert.deepStrictEqual(result, teamData)
58
+ assert.strictEqual(requestCount, 2)
59
+ } finally {
60
+ await mock.close()
61
+ }
61
62
  })
62
63
 
64
+ test('get team by name throws for unknown team', async () => {
65
+ const auth = { token: 'test-token' }
66
+ const teamList = [{ id: 101, name: 'foo' }]
67
+
68
+ const server = await createMockServer({ response: teamList })
69
+ try {
70
+ await assert.rejects(
71
+ ghteams.get(auth, 'myorg', 'nonexistent', { _apiUrl: server.baseUrl }),
72
+ (err) => {
73
+ assert.ok(err.message.includes('No such team'))
74
+ assert.ok(err.message.includes('nonexistent'))
75
+ return true
76
+ }
77
+ )
78
+ } finally {
79
+ await server.close()
80
+ }
81
+ })
63
82
 
64
- test('test get team by org & name', function (t) {
65
- t.plan(13)
66
-
67
- var auth = { user: 'authuser2', token: 'authtoken2' }
68
- , org = 'myorg'
69
- , name = 'myteamname'
70
- , teamId = 202
71
- , testData = [
72
- [ { name: 'foo', id: 101 }, { name: name, id: teamId }, { name: 'bar', id: 303 } ]
73
- , []
74
- , { test: 'team data' }
75
- ]
83
+ test('get members by id', async () => {
84
+ const auth = { token: 'test-token' }
85
+ const memberData = [{ id: 1, login: 'user1' }, { id: 2, login: 'user2' }]
76
86
 
77
- var server = ghutils.makeServer(testData)
78
- .on('ready', function () {
79
- ghteams.get(xtend(auth), org, name, ghutils.verifyData(t, testData[2]))
80
- })
81
- .on('request', ghutils.verifyRequest(t, auth))
82
- .once('get' , function (url) {
83
- ghutils.verifyUrl(t, [ 'https://api.github.com/orgs/' + org + '/teams?page=1' ])(url)
84
- server.once('get' , function (url) {
85
- ghutils.verifyUrl(t, [ 'https://api.github.com/orgs/' + org + '/teams?page=2' ])(url)
86
- server.once('get', ghutils.verifyUrl(t, [ 'https://api.github.com/teams/' + teamId ]))
87
- })
87
+ const server = await createMockServer({ response: memberData })
88
+ try {
89
+ const results = await ghteams.members(auth, 101, undefined, {
90
+ _apiUrl: server.baseUrl
88
91
  })
89
- .on('close' , ghutils.verifyClose(t))
92
+ assert.deepStrictEqual(results, memberData)
93
+ assert.ok(server.requests[0].url.includes('/teams/101/members'))
94
+ } finally {
95
+ await server.close()
96
+ }
90
97
  })
91
98
 
92
-
93
- test('test get members by org & name', function (t) {
94
- t.plan(15)
95
-
96
- var auth = { user: 'authuser3', token: 'authtoken3' }
97
- , org = 'myorg2'
98
- , name = 'myteamname2'
99
- , teamId = 100001
100
- , testData = [
101
- [ { name: name, id: teamId } ]
102
- , []
103
- , [ { test: 'team data 3' } ]
104
- , []
105
- ]
106
-
107
- var server = ghutils.makeServer(testData)
108
- .on('ready', function () {
109
- ghteams.members(xtend(auth), org, name, ghutils.verifyData(t, testData[2]))
110
- })
111
- .on('request', ghutils.verifyRequest(t, auth))
112
- .once('get' , function (url) {
113
- ghutils.verifyUrl(t, [ 'https://api.github.com/orgs/' + org + '/teams?page=1' ])(url)
114
- server.once('get' , function (url) {
115
- ghutils.verifyUrl(t, [ 'https://api.github.com/orgs/' + org + '/teams?page=2' ])(url)
116
- server.once('get', ghutils.verifyUrl(t, [
117
- 'https://api.github.com/teams/' + teamId + '/members?page=1'
118
- , 'https://api.github.com/teams/' + teamId + '/members?page=2'
119
- ]))
120
- })
99
+ test('get members by org and name', async () => {
100
+ const auth = { token: 'test-token' }
101
+ const teamList = [{ id: 202, name: 'myteam' }]
102
+ const memberData = [{ id: 1, login: 'user1' }]
103
+
104
+ let requestCount = 0
105
+ const mock = await createMockServerWithHandler((req, res) => {
106
+ requestCount++
107
+ if (requestCount === 1) {
108
+ res.end(JSON.stringify(teamList))
109
+ } else {
110
+ res.end(JSON.stringify(memberData))
111
+ }
112
+ })
113
+
114
+ try {
115
+ const results = await ghteams.members(auth, 'myorg', 'myteam', {
116
+ _apiUrl: mock.baseUrl
121
117
  })
122
- .on('close' , ghutils.verifyClose(t))
118
+ assert.deepStrictEqual(results, memberData)
119
+ assert.strictEqual(requestCount, 2)
120
+ } finally {
121
+ await mock.close()
122
+ }
123
123
  })
124
124
 
125
+ test('user teams', async () => {
126
+ const auth = { token: 'test-token' }
127
+ const testData = [{ id: 1, name: 'Team A' }]
125
128
 
126
- test('test get teams for auth user', function (t) {
127
- t.plan(10)
128
-
129
- var auth = { user: 'authuser2', token: 'authtoken2' }
130
- , teamId = 101
131
- , testData = [ [ { test: 'team data' } ], [] ]
132
-
133
- ghutils.makeServer(testData)
134
- .on('ready', function () {
135
- ghteams.userTeams(xtend(auth), ghutils.verifyData(t, testData[0]))
129
+ const server = await createMockServer({ response: testData })
130
+ try {
131
+ const results = await ghteams.userTeams(auth, {
132
+ _apiUrl: server.baseUrl
136
133
  })
137
- .on('request', ghutils.verifyRequest(t, auth))
138
- .on('get' , ghutils.verifyUrl(t, [
139
- 'https://api.github.com/user/teams?page=1'
140
- , 'https://api.github.com/user/teams?page=2'
141
- ]))
142
- .on('close' , ghutils.verifyClose(t))
134
+ assert.deepStrictEqual(results, testData)
135
+ assert.ok(server.requests[0].url.includes('/user/teams'))
136
+ } finally {
137
+ await server.close()
138
+ }
143
139
  })
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
@@ -1 +0,0 @@
1
- node_modules/
package/.travis.yml DELETED
@@ -1,10 +0,0 @@
1
- language: node_js
2
- node_js:
3
- - "0.10"
4
- branches:
5
- only:
6
- - master
7
- notifications:
8
- email:
9
- - rod@vagg.org
10
- script: npm test
package/example.js DELETED
@@ -1,13 +0,0 @@
1
- const ghauth = require('../ghauth')
2
- , ghteams = require('./')
3
-
4
- ghauth({ configName: 'nodejs', scopes: [ 'read:org' ] }, function (err, authData) {
5
- if (err) throw err
6
-
7
- ghteams.list(authData, 'nodejs', function (err, teamlist) {
8
- if (err) throw err
9
-
10
- console.log(teamlist.map(function (t) { return { id: t.id, slug: t.slug, desc: t.description } }))
11
- console.log(teamlist.filter(function (t) { return !/^iojs-/.test(t.slug) }).map(function (t) { return `@nodejs/${t.slug}` }).join(', '))
12
- })
13
- })