Skip to content

Add JSON Schema for Github API list Organization repositories #28

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
125 changes: 124 additions & 1 deletion __fixtures__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,129 @@ const sampleGithubOrg = {
secret_scanning_push_protection_custom_link_enabled: false
}

// https://docs.github.com/en/rest/reference/repos#list-organization-repositories
const sampleGithubListOrgRepos = [
{
id: 1296269,
node_id: 'MDEwOlJlcG9zaXRvcnkxMjk2MjY5',
name: 'Hello-World',
full_name: 'octocat/Hello-World',
owner: {
login: 'octocat',
id: 1,
node_id: 'MDQ6VXNlcjE=',
avatar_url: 'https://github.com/images/error/octocat_happy.gif',
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',
site_admin: false
},
private: false,
html_url: 'https://github.com/octocat/Hello-World',
description: 'This your first repo!',
fork: false,
url: 'https://api.github.com/repos/octocat/Hello-World',
archive_url: 'https://api.github.com/repos/octocat/Hello-World/{archive_format}{/ref}',
assignees_url: 'https://api.github.com/repos/octocat/Hello-World/assignees{/user}',
blobs_url: 'https://api.github.com/repos/octocat/Hello-World/git/blobs{/sha}',
branches_url: 'https://api.github.com/repos/octocat/Hello-World/branches{/branch}',
collaborators_url: 'https://api.github.com/repos/octocat/Hello-World/collaborators{/collaborator}',
comments_url: 'https://api.github.com/repos/octocat/Hello-World/comments{/number}',
commits_url: 'https://api.github.com/repos/octocat/Hello-World/commits{/sha}',
compare_url: 'https://api.github.com/repos/octocat/Hello-World/compare/{base}...{head}',
contents_url: 'https://api.github.com/repos/octocat/Hello-World/contents/{+path}',
contributors_url: 'https://api.github.com/repos/octocat/Hello-World/contributors',
deployments_url: 'https://api.github.com/repos/octocat/Hello-World/deployments',
downloads_url: 'https://api.github.com/repos/octocat/Hello-World/downloads',
events_url: 'https://api.github.com/repos/octocat/Hello-World/events',
forks_url: 'https://api.github.com/repos/octocat/Hello-World/forks',
git_commits_url: 'https://api.github.com/repos/octocat/Hello-World/git/commits{/sha}',
git_refs_url: 'https://api.github.com/repos/octocat/Hello-World/git/refs{/sha}',
git_tags_url: 'https://api.github.com/repos/octocat/Hello-World/git/tags{/sha}',
git_url: 'git:github.com/octocat/Hello-World.git',
issue_comment_url: 'https://api.github.com/repos/octocat/Hello-World/issues/comments{/number}',
issue_events_url: 'https://api.github.com/repos/octocat/Hello-World/issues/events{/number}',
issues_url: 'https://api.github.com/repos/octocat/Hello-World/issues{/number}',
keys_url: 'https://api.github.com/repos/octocat/Hello-World/keys{/key_id}',
labels_url: 'https://api.github.com/repos/octocat/Hello-World/labels{/name}',
languages_url: 'https://api.github.com/repos/octocat/Hello-World/languages',
merges_url: 'https://api.github.com/repos/octocat/Hello-World/merges',
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}',
pulls_url: 'https://api.github.com/repos/octocat/Hello-World/pulls{/number}',
releases_url: 'https://api.github.com/repos/octocat/Hello-World/releases{/id}',
ssh_url: '[email protected]:octocat/Hello-World.git',
stargazers_url: 'https://api.github.com/repos/octocat/Hello-World/stargazers',
statuses_url: 'https://api.github.com/repos/octocat/Hello-World/statuses/{sha}',
subscribers_url: 'https://api.github.com/repos/octocat/Hello-World/subscribers',
subscription_url: 'https://api.github.com/repos/octocat/Hello-World/subscription',
tags_url: 'https://api.github.com/repos/octocat/Hello-World/tags',
teams_url: 'https://api.github.com/repos/octocat/Hello-World/teams',
trees_url: 'https://api.github.com/repos/octocat/Hello-World/git/trees{/sha}',
clone_url: 'https://github.com/octocat/Hello-World.git',
mirror_url: 'git:git.example.com/octocat/Hello-World',
hooks_url: 'https://api.github.com/repos/octocat/Hello-World/hooks',
svn_url: 'https://svn.github.com/octocat/Hello-World',
homepage: 'https://github.com',
language: null,
forks_count: 9,
stargazers_count: 80,
watchers_count: 80,
size: 108,
default_branch: 'master',
open_issues_count: 0,
is_template: false,
topics: [
'octocat',
'atom',
'electron',
'api'
],
has_issues: true,
has_projects: true,
has_wiki: true,
has_pages: false,
has_downloads: true,
has_discussions: false,
archived: false,
disabled: false,
visibility: 'public',
pushed_at: '2011-01-26T19:06:43Z',
created_at: '2011-01-26T19:01:12Z',
updated_at: '2011-01-26T19:14:43Z',
permissions: {
admin: false,
push: false,
pull: true
},
security_and_analysis: {
advanced_security: {
status: 'enabled'
},
secret_scanning: {
status: 'enabled'
},
secret_scanning_push_protection: {
status: 'disabled'
},
secret_scanning_non_provider_patterns: {
status: 'disabled'
}
}
}
]

module.exports = {
sampleGithubOrg
sampleGithubOrg,
sampleGithubListOrgRepos
}
25 changes: 23 additions & 2 deletions __tests__/schemas.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { sampleGithubOrg } = require('../__fixtures__')
const { validateGithubOrg } = require('../src/schemas')
const { sampleGithubOrg, sampleGithubListOrgRepos } = require('../__fixtures__')
const { validateGithubOrg, validateGithubListOrgRepos } = require('../src/schemas')

describe('schemas', () => {
describe('validateGithubOrg', () => {
Expand All @@ -17,4 +17,25 @@ describe('schemas', () => {
expect(() => validateGithubOrg(invalidData)).toThrow()
})
})
describe('validateGithubListOrgRepos', () => {
test('Should not throw an error with valid data', () => {
expect(() => validateGithubListOrgRepos(sampleGithubListOrgRepos)).not.toThrow()
})

test('Should not throw with additional data', () => {
const additionalData = [
...sampleGithubListOrgRepos,
{ ...sampleGithubListOrgRepos[0], additionalKey: 'value' }
]
expect(() => validateGithubListOrgRepos(additionalData)).not.toThrow()
})

test('Should throw an error with invalid data', () => {
const invalidData = [
...sampleGithubListOrgRepos,
{ ...sampleGithubListOrgRepos[0], id: '123' }
]
expect(() => validateGithubListOrgRepos(invalidData)).toThrow()
})
})
})
Loading
Loading