Socket
Socket
Sign inDemoInstall

@colophon/github-client

Package Overview
Dependencies
Maintainers
3
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@colophon/github-client - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

lib/__tests__/getAuthedClient.test.js

6

index.js

@@ -1,1 +0,5 @@

module.exports = require('./lib/getColophonData')
module.exports = {
getAuthedClient: require('./lib/getAuthedClient'),
getAuthToken: require('./lib/getAuthToken'),
getColophonData: require('./lib/getColophonData')
}

6

lib/__tests__/getAllRepos.test.js

@@ -14,3 +14,3 @@ const getAllRepos = require('../getAllRepos')

it('should call the getForOrg method of the mock authenticated client with the default options passed', async () => {
getAllRepos(mockAuthedClient, 'orgname')
getAllRepos(mockAuthedClient, { org: 'orgname' })
expect(mockAuthedClient.repos.getForOrg).toHaveBeenCalledWith({ org: 'orgname', per_page: 100 });

@@ -20,7 +20,7 @@ })

it('should call the getForOrg method of the mock authenticated client with the custom options passed', async () => {
getAllRepos(mockAuthedClient, 'orgname', 50)
getAllRepos(mockAuthedClient, { org: 'orgname', perPage: 50 })
expect(mockAuthedClient.repos.getForOrg).toHaveBeenCalledWith({ org: 'orgname', per_page: 50 });
})
it('should call the getAll method of the mock authenticated client with the default options passed', async () => {
it('should call the getAll method of the mock authenticated client with the default options', async () => {
getAllRepos(mockAuthedClient)

@@ -27,0 +27,0 @@ expect(mockAuthedClient.repos.getAll).toHaveBeenCalledWith({ affiliation: 'owner', per_page: 100 });

@@ -1,4 +0,2 @@

const pMap = require('p-map')
const getColophonData = require('../getColophonData')
const authenticate = require('../authenticate')
const getAllRepos = require('../getAllRepos')

@@ -26,18 +24,22 @@

jest.mock('../authenticate', () => jest.fn().mockReturnValue({
repos: {
getContent: jest.fn()
.mockReturnValueOnce(null)
.mockReturnValue({ data: { content: 'some-org-repo-id' } })
}
})
)
jest.mock('../getAllRepos', () => jest.fn()
.mockResolvedValue( [ { owner: { login: 'name' }, name: 'name', full_name: 'full_name' } ] ))
jest.mock('../getAllRepos', () => jest.fn().mockResolvedValue( [ { owner: { login: 'name' }, name: 'name', full_name: 'full_name' } ] ))
const mockAuthedClient = {
repos: {
getForOrg: jest.fn().mockReturnValue( { data: [{ id: 'some-org-repo-id' }] } ),
getAll: jest.fn().mockReturnValue( { data: [{ id: 'some-user-repo-id' }] } ),
getContent: jest.fn().mockReturnValueOnce(null)
.mockReturnValue({ data: { content: 'some-repo-id' } })
},
hasNextPage: jest.fn().mockReturnValueOnce(true).mockReturnValueOnce(false),
getNextPage: jest.fn().mockReturnValueOnce( { data: ['c','d'] })
}
describe('getColophonData', () => {
it('returns an empty object if no colophon file found', async () => {
const authOptions = { type: 'oauth', token: 'token' }
const requestOptions = { org: 'orgName', concurrency: 10, perPage: 100 }
const results = await getColophonData(authOptions, requestOptions)
const options = { org: 'orgName', concurrency: 10, perPage: 100 }
const results = await getColophonData(mockAuthedClient, options)
expect(results).toEqual({})

@@ -47,7 +49,5 @@ })

it('should authenticate using the auth and request options passed and fetch all repos', async () => {
const authOptions = { type: 'oauth', token: 'token' }
const requestOptions = { org: 'orgName', concurrency: 10, perPage: 100 }
const results = await getColophonData(authOptions, requestOptions)
expect(authenticate).toHaveBeenCalledWith(authOptions)
expect(getAllRepos).toHaveBeenCalledWith({ repos: expect.any(Object) }, requestOptions.org, requestOptions.perPage)
const options = { org: 'orgName', concurrency: 10, perPage: 100 }
const results = await getColophonData(mockAuthedClient, options)
expect(getAllRepos).toHaveBeenCalledWith(mockAuthedClient, options)
expect(results).toEqual({

@@ -63,7 +63,5 @@ full_name: {

it('should authenticate using the default options and fetch all repos', async () => {
const authOptions = { type: 'oauth', token: 'token' }
const requestOptions = { org: 'orgName' }
const results = await getColophonData(authOptions, requestOptions)
expect(authenticate).toHaveBeenCalledWith(authOptions)
expect(getAllRepos).toHaveBeenCalledWith({ repos: expect.any(Object) }, requestOptions.org, 100)
const options = { org: 'orgName' }
const results = await getColophonData(mockAuthedClient, options)
expect(getAllRepos).toHaveBeenCalledWith(mockAuthedClient, options)
expect(results).toEqual({

@@ -79,7 +77,4 @@ full_name: {

it('should authenticate using the default options and fetch all repos for a user', async () => {
const authOptions = { type: 'oauth', token: 'token' }
const requestOptions = { concurrency: 10, perPage: 100 }
const results = await getColophonData(authOptions, requestOptions)
expect(authenticate).toHaveBeenCalledWith(authOptions)
expect(getAllRepos).toHaveBeenCalledWith({ repos: expect.any(Object) }, null, 100)
const results = await getColophonData(mockAuthedClient)
expect(getAllRepos).toHaveBeenCalledWith(mockAuthedClient, {})
expect(results).toEqual({

@@ -86,0 +81,0 @@ full_name: {

@@ -1,6 +0,7 @@

const getAllGithubRepos = async (authedClient, org, perPage = 100) => {
const getAllRepos = async (authedClient, options = {}) => {
const { org = null, perPage = 100 } = options
const method = org ? authedClient.repos.getForOrg : authedClient.repos.getAll
const options = org ? { org, per_page: perPage } : { affiliation: 'owner', per_page: perPage }
const reqOptions = org ? { org, per_page: perPage } : { affiliation: 'owner', per_page: perPage }
let response = await method(options)
let response = await method(reqOptions)
let { data } = response

@@ -16,2 +17,2 @@

module.exports = getAllGithubRepos
module.exports = getAllRepos
const { safeLoad } = require('js-yaml')
const pMap = require('p-map')
const authenticate = require('./authenticate')
const getAllRepos = require('./getAllRepos')
const getColophonData = async (authOptions, requestOptions) => {
const { org = null, concurrency = 10, perPage = 100 } = requestOptions
const authedClient = authenticate(authOptions)
const repos = await getAllRepos(authedClient, org, perPage)
const getColophonData = async (authedClient, options = {}) => {
const { concurrency = 10 } = options
const repos = await getAllRepos(authedClient, options)
const results = {}

@@ -14,0 +10,0 @@

{
"version": "1.0.0",
"version": "1.1.0",
"name": "@colophon/github-client",

@@ -4,0 +4,0 @@ "description": "@colophon/github-client",

@@ -13,19 +13,16 @@ # @colophon/github-client [![version][npm-version]][npm-url] [![License][license-image]][license-url] [![Build Status][travis-image]][travis-url] [![Downloads][npm-downloads]][npm-url]

Use the exposed methods to:
1. Authenticate your client using `getAuthedClient` (see options [here](https://www.npmjs.com/package/@octokit/rest#authentication)).
2. Create a new authorization and retrieve the personal access token using `getAuthToken`. This token can be stored and then used to simplify consequent requests.
3. Parse all the repositories in your personal or organization's account and retrieve all info found inside Colophon files using `getColophonData`. If not passing any options, the user's personal repositories will be parsed with the default options (perPage - 100, concurrency - 10).
```
const getColophonData = require('@colophon/github-client')
const { getAuthedClient, getAuthToken, getColophonData } = require('./index.js')
const authOptions = {
type: 'oauth',
token: '...'
}
const authedClient = getAuthedClient({ type: 'basic', username: 'username', password: 'password' })
const requestOptions = {
org: 'acme' // if omitted, it will parse Colophon files in the repositories associated with the user/token
concurrency: 5, // defaults to 10
perPage: 10 // defaults to 100
}
const token = await getAuthToken(authedClient) // not using 2FA OR
const token = await getAuthToken(authedClient, otpCode) // if 2FA is on and using a CLI to get the OTP code from the user
// Prints to console
getColophonData(authOptions, requestOptions)
.then(results => console.log('RESULTS', results)
const colophonData = await getColophonData(authedClient, { org: 'acme', perPage: 100, concurrency: 5 })
```

@@ -32,0 +29,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc