Skip to content

Commit

Permalink
feat: get organization
Browse files Browse the repository at this point in the history
  • Loading branch information
gr2m committed Sep 15, 2017
1 parent 1a9572a commit 1a6c9c3
Show file tree
Hide file tree
Showing 9 changed files with 207 additions and 86 deletions.
62 changes: 62 additions & 0 deletions fixtures/api.github.com/get-organization.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
[
{
"scope": "https://api.github.com:443",
"method": "get",
"path": "/orgs/octokit-fixture-org",
"body": "",
"status": 200,
"response": {
"login": "octokit-fixture-org",
"id": 31898100,
"url": "https://api.github.com/orgs/octokit-fixture-org",
"repos_url": "https://api.github.com/orgs/octokit-fixture-org/repos",
"events_url": "https://api.github.com/orgs/octokit-fixture-org/events",
"hooks_url": "https://api.github.com/orgs/octokit-fixture-org/hooks",
"issues_url": "https://api.github.com/orgs/octokit-fixture-org/issues",
"members_url": "https://api.github.com/orgs/octokit-fixture-org/members{/member}",
"public_members_url": "https://api.github.com/orgs/octokit-fixture-org/public_members{/member}",
"avatar_url": "https://avatars2.githubusercontent.com/u/31898100?v=4",
"description": null,
"has_organization_projects": true,
"has_repository_projects": true,
"public_repos": 42,
"public_gists": 0,
"followers": 0,
"following": 0,
"html_url": "https://github.com/octokit-fixture-org",
"created_at": "2017-10-10T16:00:00Z",
"updated_at": "2017-10-10T16:00:00Z",
"type": "Organization"
},
"reqheaders": {
"accept": "application/vnd.github.v3+json",
"host": "api.github.com"
},
"headers": {
"access-control-allow-origin": "*",
"access-control-expose-headers": "ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval",
"cache-control": "public, max-age=60, s-maxage=60",
"connection": "close",
"content-length": "914",
"content-security-policy": "default-src 'none'",
"content-type": "application/json; charset=utf-8",
"date": "Tue, 10 Oct 2017 16:00:00 GMT",
"etag": "\"00000000000000000000000000000000\"",
"last-modified": "Tue, 10 Oct 2017 16:00:00 GMT",
"status": "200 OK",
"strict-transport-security": "max-age=31536000; includeSubdomains; preload",
"x-content-type-options": "nosniff",
"x-frame-options": "deny",
"x-github-media-type": "github.v3; format=json",
"x-github-request-id": "0000:00000:0000000:0000000:00000000",
"x-ratelimit-limit": "60",
"x-ratelimit-remaining": "59",
"x-ratelimit-reset": "1507651200000",
"x-runtime-rack": "0.000000",
"x-xss-protection": "1; mode=block"
},
"badheaders": [
"authorization"
]
}
]
149 changes: 84 additions & 65 deletions fixtures/api.github.com/get-repository.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,82 +2,82 @@
{
"scope": "https://api.github.com:443",
"method": "get",
"path": "/repos/octocat/hello-world",
"path": "/repos/octokit-fixture-org/hello-world",
"body": "",
"status": 200,
"response": {
"id": 1296269,
"name": "Hello-World",
"full_name": "octocat/Hello-World",
"id": 103703892,
"name": "hello-world",
"full_name": "octokit-fixture-org/hello-world",
"owner": {
"login": "octocat",
"id": 583231,
"avatar_url": "https://avatars3.githubusercontent.com/u/583231?v=4",
"login": "octokit-fixture-org",
"id": 31898100,
"avatar_url": "https://avatars2.githubusercontent.com/u/31898100?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/octocat",
"html_url": "https://github.com/octocat",
"followers_url": "https://api.github.com/users/octocat/followers",
"following_url": "https://api.github.com/users/octocat/following{/other_user}",
"gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",
"starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/octocat/subscriptions",
"organizations_url": "https://api.github.com/users/octocat/orgs",
"repos_url": "https://api.github.com/users/octocat/repos",
"events_url": "https://api.github.com/users/octocat/events{/privacy}",
"received_events_url": "https://api.github.com/users/octocat/received_events",
"type": "User",
"url": "https://api.github.com/users/octokit-fixture-org",
"html_url": "https://github.com/octokit-fixture-org",
"followers_url": "https://api.github.com/users/octokit-fixture-org/followers",
"following_url": "https://api.github.com/users/octokit-fixture-org/following{/other_user}",
"gists_url": "https://api.github.com/users/octokit-fixture-org/gists{/gist_id}",
"starred_url": "https://api.github.com/users/octokit-fixture-org/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/octokit-fixture-org/subscriptions",
"organizations_url": "https://api.github.com/users/octokit-fixture-org/orgs",
"repos_url": "https://api.github.com/users/octokit-fixture-org/repos",
"events_url": "https://api.github.com/users/octokit-fixture-org/events{/privacy}",
"received_events_url": "https://api.github.com/users/octokit-fixture-org/received_events",
"type": "Organization",
"site_admin": false
},
"private": false,
"html_url": "https://github.com/octocat/Hello-World",
"description": "My first repository on GitHub!",
"html_url": "https://github.com/octokit-fixture-org/hello-world",
"description": null,
"fork": false,
"url": "https://api.github.com/repos/octocat/Hello-World",
"forks_url": "https://api.github.com/repos/octocat/Hello-World/forks",
"keys_url": "https://api.github.com/repos/octocat/Hello-World/keys{/key_id}",
"collaborators_url": "https://api.github.com/repos/octocat/Hello-World/collaborators{/collaborator}",
"teams_url": "https://api.github.com/repos/octocat/Hello-World/teams",
"hooks_url": "https://api.github.com/repos/octocat/Hello-World/hooks",
"issue_events_url": "https://api.github.com/repos/octocat/Hello-World/issues/events{/number}",
"events_url": "https://api.github.com/repos/octocat/Hello-World/events",
"assignees_url": "https://api.github.com/repos/octocat/Hello-World/assignees{/user}",
"branches_url": "https://api.github.com/repos/octocat/Hello-World/branches{/branch}",
"tags_url": "https://api.github.com/repos/octocat/Hello-World/tags",
"blobs_url": "https://api.github.com/repos/octocat/Hello-World/git/blobs{/sha}",
"git_tags_url": "https://api.github.com/repos/octocat/Hello-World/git/tags{/sha}",
"git_refs_url": "https://api.github.com/repos/octocat/Hello-World/git/refs{/sha}",
"trees_url": "https://api.github.com/repos/octocat/Hello-World/git/trees{/sha}",
"statuses_url": "https://api.github.com/repos/octocat/Hello-World/statuses/{sha}",
"languages_url": "https://api.github.com/repos/octocat/Hello-World/languages",
"stargazers_url": "https://api.github.com/repos/octocat/Hello-World/stargazers",
"contributors_url": "https://api.github.com/repos/octocat/Hello-World/contributors",
"subscribers_url": "https://api.github.com/repos/octocat/Hello-World/subscribers",
"subscription_url": "https://api.github.com/repos/octocat/Hello-World/subscription",
"commits_url": "https://api.github.com/repos/octocat/Hello-World/commits{/sha}",
"git_commits_url": "https://api.github.com/repos/octocat/Hello-World/git/commits{/sha}",
"comments_url": "https://api.github.com/repos/octocat/Hello-World/comments{/number}",
"issue_comment_url": "https://api.github.com/repos/octocat/Hello-World/issues/comments{/number}",
"contents_url": "https://api.github.com/repos/octocat/Hello-World/contents/{+path}",
"compare_url": "https://api.github.com/repos/octocat/Hello-World/compare/{base}...{head}",
"merges_url": "https://api.github.com/repos/octocat/Hello-World/merges",
"archive_url": "https://api.github.com/repos/octocat/Hello-World/{archive_format}{/ref}",
"downloads_url": "https://api.github.com/repos/octocat/Hello-World/downloads",
"issues_url": "https://api.github.com/repos/octocat/Hello-World/issues{/number}",
"pulls_url": "https://api.github.com/repos/octocat/Hello-World/pulls{/number}",
"milestones_url": "https://api.github.com/repos/octocat/Hello-World/milestones{/number}",
"notifications_url": "https://api.github.com/repos/octocat/Hello-World/notifications{?since,all,participating}",
"labels_url": "https://api.github.com/repos/octocat/Hello-World/labels{/name}",
"releases_url": "https://api.github.com/repos/octocat/Hello-World/releases{/id}",
"deployments_url": "https://api.github.com/repos/octocat/Hello-World/deployments",
"url": "https://api.github.com/repos/octokit-fixture-org/hello-world",
"forks_url": "https://api.github.com/repos/octokit-fixture-org/hello-world/forks",
"keys_url": "https://api.github.com/repos/octokit-fixture-org/hello-world/keys{/key_id}",
"collaborators_url": "https://api.github.com/repos/octokit-fixture-org/hello-world/collaborators{/collaborator}",
"teams_url": "https://api.github.com/repos/octokit-fixture-org/hello-world/teams",
"hooks_url": "https://api.github.com/repos/octokit-fixture-org/hello-world/hooks",
"issue_events_url": "https://api.github.com/repos/octokit-fixture-org/hello-world/issues/events{/number}",
"events_url": "https://api.github.com/repos/octokit-fixture-org/hello-world/events",
"assignees_url": "https://api.github.com/repos/octokit-fixture-org/hello-world/assignees{/user}",
"branches_url": "https://api.github.com/repos/octokit-fixture-org/hello-world/branches{/branch}",
"tags_url": "https://api.github.com/repos/octokit-fixture-org/hello-world/tags",
"blobs_url": "https://api.github.com/repos/octokit-fixture-org/hello-world/git/blobs{/sha}",
"git_tags_url": "https://api.github.com/repos/octokit-fixture-org/hello-world/git/tags{/sha}",
"git_refs_url": "https://api.github.com/repos/octokit-fixture-org/hello-world/git/refs{/sha}",
"trees_url": "https://api.github.com/repos/octokit-fixture-org/hello-world/git/trees{/sha}",
"statuses_url": "https://api.github.com/repos/octokit-fixture-org/hello-world/statuses/{sha}",
"languages_url": "https://api.github.com/repos/octokit-fixture-org/hello-world/languages",
"stargazers_url": "https://api.github.com/repos/octokit-fixture-org/hello-world/stargazers",
"contributors_url": "https://api.github.com/repos/octokit-fixture-org/hello-world/contributors",
"subscribers_url": "https://api.github.com/repos/octokit-fixture-org/hello-world/subscribers",
"subscription_url": "https://api.github.com/repos/octokit-fixture-org/hello-world/subscription",
"commits_url": "https://api.github.com/repos/octokit-fixture-org/hello-world/commits{/sha}",
"git_commits_url": "https://api.github.com/repos/octokit-fixture-org/hello-world/git/commits{/sha}",
"comments_url": "https://api.github.com/repos/octokit-fixture-org/hello-world/comments{/number}",
"issue_comment_url": "https://api.github.com/repos/octokit-fixture-org/hello-world/issues/comments{/number}",
"contents_url": "https://api.github.com/repos/octokit-fixture-org/hello-world/contents/{+path}",
"compare_url": "https://api.github.com/repos/octokit-fixture-org/hello-world/compare/{base}...{head}",
"merges_url": "https://api.github.com/repos/octokit-fixture-org/hello-world/merges",
"archive_url": "https://api.github.com/repos/octokit-fixture-org/hello-world/{archive_format}{/ref}",
"downloads_url": "https://api.github.com/repos/octokit-fixture-org/hello-world/downloads",
"issues_url": "https://api.github.com/repos/octokit-fixture-org/hello-world/issues{/number}",
"pulls_url": "https://api.github.com/repos/octokit-fixture-org/hello-world/pulls{/number}",
"milestones_url": "https://api.github.com/repos/octokit-fixture-org/hello-world/milestones{/number}",
"notifications_url": "https://api.github.com/repos/octokit-fixture-org/hello-world/notifications{?since,all,participating}",
"labels_url": "https://api.github.com/repos/octokit-fixture-org/hello-world/labels{/name}",
"releases_url": "https://api.github.com/repos/octokit-fixture-org/hello-world/releases{/id}",
"deployments_url": "https://api.github.com/repos/octokit-fixture-org/hello-world/deployments",
"created_at": "2017-10-10T16:00:00Z",
"updated_at": "2017-10-10T16:00:00Z",
"pushed_at": "2017-10-10T16:00:00Z",
"git_url": "git://github.com/octocat/Hello-World.git",
"ssh_url": "git@github.com:octocat/Hello-World.git",
"clone_url": "https://github.com/octocat/Hello-World.git",
"svn_url": "https://github.com/octocat/Hello-World",
"homepage": "",
"size": 578,
"git_url": "git://github.com/octokit-fixture-org/hello-world.git",
"ssh_url": "git@github.com:octokit-fixture-org/hello-world.git",
"clone_url": "https://github.com/octokit-fixture-org/hello-world.git",
"svn_url": "https://github.com/octokit-fixture-org/hello-world",
"homepage": null,
"size": 0,
"stargazers_count": 42,
"watchers_count": 42,
"language": null,
Expand All @@ -93,6 +93,25 @@
"open_issues": 42,
"watchers": 42,
"default_branch": "master",
"organization": {
"login": "octokit-fixture-org",
"id": 31898100,
"avatar_url": "https://avatars2.githubusercontent.com/u/31898100?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/octokit-fixture-org",
"html_url": "https://github.com/octokit-fixture-org",
"followers_url": "https://api.github.com/users/octokit-fixture-org/followers",
"following_url": "https://api.github.com/users/octokit-fixture-org/following{/other_user}",
"gists_url": "https://api.github.com/users/octokit-fixture-org/gists{/gist_id}",
"starred_url": "https://api.github.com/users/octokit-fixture-org/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/octokit-fixture-org/subscriptions",
"organizations_url": "https://api.github.com/users/octokit-fixture-org/orgs",
"repos_url": "https://api.github.com/users/octokit-fixture-org/repos",
"events_url": "https://api.github.com/users/octokit-fixture-org/events{/privacy}",
"received_events_url": "https://api.github.com/users/octokit-fixture-org/received_events",
"type": "Organization",
"site_admin": false
},
"network_count": 42,
"subscribers_count": 42
},
Expand All @@ -105,7 +124,7 @@
"access-control-expose-headers": "ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval",
"cache-control": "public, max-age=60, s-maxage=60",
"connection": "close",
"content-length": "4721",
"content-length": "6398",
"content-security-policy": "default-src 'none'",
"content-type": "application/json; charset=utf-8",
"date": "Tue, 10 Oct 2017 16:00:00 GMT",
Expand Down
29 changes: 9 additions & 20 deletions lib/normalize.js → lib/normalize/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
module.exports = normalize

const env = require('./env')
const headers = require('./headers')
const env = require('../env')
const headers = require('../headers')
const setIfExists = require('../set-if-exists')
const toEntityName = require('../to-entity-name')

function normalize (fixture) {
// fixture.rawHeaders is an array in the form of ['key1', 'value1', 'key2', 'value2']
Expand All @@ -14,22 +16,10 @@ function normalize (fixture) {
// set all dates to Universe 2017 Keynote time
setIfExists(fixture.response, 'created_at', '2017-10-10T16:00:00Z')
setIfExists(fixture.response, 'updated_at', '2017-10-10T16:00:00Z')
setIfExists(fixture.response, 'pushed_at', '2017-10-10T16:00:00Z')
setIfExists(fixture.headers, 'date', 'Tue, 10 Oct 2017 16:00:00 GMT')
setIfExists(fixture.headers, 'last-modified', 'Tue, 10 Oct 2017 16:00:00 GMT')
setIfExists(fixture.headers, 'x-ratelimit-reset', '1507651200000')

// set all counts to 42
setIfExists(fixture.response, 'forks', 42)
setIfExists(fixture.response, 'forks_count', 42)
setIfExists(fixture.response, 'open_issues_count', 42)
setIfExists(fixture.response, 'open_issues', 42)
setIfExists(fixture.response, 'network_count', 42)
setIfExists(fixture.response, 'stargazers_count', 42)
setIfExists(fixture.response, 'subscribers_count', 42)
setIfExists(fixture.response, 'watchers', 42)
setIfExists(fixture.response, 'watchers_count', 42)

// Set remaining rate limit to 59 for unauthenticated accounts and
// to 4999 to authenticated accounts
const rateLimitRemaining = parseInt(fixture.headers['x-ratelimit-limit'], 10)
Expand Down Expand Up @@ -62,14 +52,13 @@ function normalize (fixture) {
delete fixture.headers.server
delete fixture.headers.vary

const entityName = toEntityName(fixture.response)
if (entityName) {
require(`./${entityName}`)(fixture)
}

// update content length
fixture.headers['content-length'] = String(JSON.stringify(fixture.response).length)

return fixture
}

function setIfExists (object, key, value) {
if (key in object) {
object[key] = value
}
}
8 changes: 8 additions & 0 deletions lib/normalize/organization.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = normalizeOrganization

const setIfExists = require('../set-if-exists')

function normalizeOrganization (fixture) {
// set all counts to 42
setIfExists(fixture.response, 'public_repos', 42)
}
19 changes: 19 additions & 0 deletions lib/normalize/repository.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module.exports = normalizeRepository

const setIfExists = require('../set-if-exists')

function normalizeRepository (fixture) {
// set all dates to Universe 2017 Keynote time
setIfExists(fixture.response, 'pushed_at', '2017-10-10T16:00:00Z')

// set all counts to 42
setIfExists(fixture.response, 'forks_count', 42)
setIfExists(fixture.response, 'forks', 42)
setIfExists(fixture.response, 'network_count', 42)
setIfExists(fixture.response, 'open_issues_count', 42)
setIfExists(fixture.response, 'open_issues', 42)
setIfExists(fixture.response, 'stargazers_count', 42)
setIfExists(fixture.response, 'subscribers_count', 42)
setIfExists(fixture.response, 'watchers_count', 42)
setIfExists(fixture.response, 'watchers', 42)
}
7 changes: 7 additions & 0 deletions lib/set-if-exists.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = setIfExists

function setIfExists (object, key, value) {
if (key in object) {
object[key] = value
}
}
10 changes: 10 additions & 0 deletions lib/to-entity-name.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = toEntityName

function toEntityName (object) {
if (object.type === 'Organization') {
return 'organization'
}
if ('forks' in object) {
return 'repository'
}
}
7 changes: 7 additions & 0 deletions scenarios/api.github.com/get-organization.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
method: 'get',
url: '/orgs/octokit-fixture-org',
headers: {
Accept: 'application/vnd.github.v3+json'
}
}
2 changes: 1 addition & 1 deletion scenarios/api.github.com/get-repository.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = {
method: 'get',
url: '/repos/octocat/hello-world',
url: '/repos/octokit-fixture-org/hello-world',
headers: {
Accept: 'application/vnd.github.v3+json'
}
Expand Down

0 comments on commit 1a6c9c3

Please sign in to comment.