getcontributors
Advanced tools
Comparing version 2.0.0 to 2.1.0-next.1585267301.18467a5c39688e18b5333b87bdeef47ea65aa283
@@ -12,4 +12,18 @@ /* eslint camelcase:0 */ | ||
} | ||
// | ||
/** Fetch Contributors from a Repository's GitHub Contributor API */ | ||
/** Fetch the full profile information for a contributor */ | ||
export async function getContributorProfile(url) { | ||
const resp = await fetch(url, { | ||
headers: { | ||
Accept: 'application/vnd.github.v3+json', | ||
}, | ||
}) | ||
const responseData = await resp.json() | ||
// Check | ||
if (responseData.message) { | ||
return Promise.reject(new Error(responseData.message)) | ||
} | ||
// Return | ||
return responseData | ||
} | ||
/** Fetch contributors from a Repository's GitHub Contributor API */ | ||
export async function getContributorsFromCommits(slug) { | ||
@@ -31,16 +45,31 @@ // Fetch | ||
) | ||
} else if (responseData.length === 0) { | ||
return new Set() | ||
} | ||
// Process | ||
const added = new Set() | ||
for (const user of responseData) { | ||
const fellow = Fellow.ensure({ | ||
github: user, | ||
githubUsername: user.login, | ||
githubUrl: user.html_url, | ||
}) | ||
fellow.contributedRepositories.add(slug) | ||
added.add(fellow) | ||
} | ||
// Return | ||
return added | ||
return new Set( | ||
await Promise.all( | ||
responseData.map(async function (contributor) { | ||
const profile = await getContributorProfile(contributor.url) | ||
const fellow = Fellow.ensure({ | ||
githubProfile: profile, | ||
name: profile.name, | ||
email: profile.email, | ||
description: profile.bio, | ||
company: profile.company, | ||
location: profile.location, | ||
homepage: profile.blog, | ||
hireable: profile.hireable, | ||
githubUsername: profile.login, | ||
githubUrl: profile.html_url, | ||
}) | ||
fellow.contributions.set(slug, contributor.contributions) | ||
if (contributor.site_admin) { | ||
fellow.administeredRepositories.add(slug) | ||
} | ||
fellow.contributedRepositories.add(slug) | ||
return fellow | ||
}) | ||
) | ||
) | ||
} | ||
@@ -47,0 +76,0 @@ /** Fetch contributors from a repository's `package.json` file */ |
@@ -21,4 +21,19 @@ 'use strict' | ||
} | ||
// | ||
/** Fetch Contributors from a Repository's GitHub Contributor API */ | ||
/** Fetch the full profile information for a contributor */ | ||
async function getContributorProfile(url) { | ||
const resp = await cross_fetch_1.default(url, { | ||
headers: { | ||
Accept: 'application/vnd.github.v3+json', | ||
}, | ||
}) | ||
const responseData = await resp.json() | ||
// Check | ||
if (responseData.message) { | ||
return Promise.reject(new Error(responseData.message)) | ||
} | ||
// Return | ||
return responseData | ||
} | ||
exports.getContributorProfile = getContributorProfile | ||
/** Fetch contributors from a Repository's GitHub Contributor API */ | ||
async function getContributorsFromCommits(slug) { | ||
@@ -40,16 +55,31 @@ // Fetch | ||
) | ||
} else if (responseData.length === 0) { | ||
return new Set() | ||
} | ||
// Process | ||
const added = new Set() | ||
for (const user of responseData) { | ||
const fellow = fellow_1.default.ensure({ | ||
github: user, | ||
githubUsername: user.login, | ||
githubUrl: user.html_url, | ||
}) | ||
fellow.contributedRepositories.add(slug) | ||
added.add(fellow) | ||
} | ||
// Return | ||
return added | ||
return new Set( | ||
await Promise.all( | ||
responseData.map(async function (contributor) { | ||
const profile = await getContributorProfile(contributor.url) | ||
const fellow = fellow_1.default.ensure({ | ||
githubProfile: profile, | ||
name: profile.name, | ||
email: profile.email, | ||
description: profile.bio, | ||
company: profile.company, | ||
location: profile.location, | ||
homepage: profile.blog, | ||
hireable: profile.hireable, | ||
githubUsername: profile.login, | ||
githubUrl: profile.html_url, | ||
}) | ||
fellow.contributions.set(slug, contributor.contributions) | ||
if (contributor.site_admin) { | ||
fellow.administeredRepositories.add(slug) | ||
} | ||
fellow.contributedRepositories.add(slug) | ||
return fellow | ||
}) | ||
) | ||
) | ||
} | ||
@@ -56,0 +86,0 @@ exports.getContributorsFromCommits = getContributorsFromCommits |
# History | ||
## v2.1.0 2020 March 27 | ||
- Fetch the contributor's profile information (such that we have their names), instead of just their contributor data (their usernames) | ||
## v2.0.0 2020 March 27 | ||
@@ -4,0 +8,0 @@ |
{ | ||
"title": "Get Contributors", | ||
"name": "getcontributors", | ||
"version": "2.0.0", | ||
"version": "2.1.0-next.1585267301.18467a5c39688e18b5333b87bdeef47ea65aa283", | ||
"description": "Fetch all the contributors from a github repository, github organisation, or github search", | ||
@@ -118,3 +118,3 @@ "homepage": "https://github.com/bevry/getcontributors", | ||
"cross-fetch": "^3.0.4", | ||
"fellow": "^6.0.0", | ||
"fellow": "^6.1.0", | ||
"getrepos": "^4.0.3", | ||
@@ -121,0 +121,0 @@ "githubauthquerystring": "^4.0.0", |
@@ -55,3 +55,3 @@ <!-- TITLE/ --> | ||
<script type="module"> | ||
import * as pkg from '//cdn.pika.dev/getcontributors/^2.0.0' | ||
import * as pkg from '//cdn.pika.dev/getcontributors/^2.1.0' | ||
</script> | ||
@@ -64,3 +64,3 @@ ``` | ||
<script type="module"> | ||
import * as pkg from '//unpkg.com/getcontributors@^2.0.0' | ||
import * as pkg from '//unpkg.com/getcontributors@^2.1.0' | ||
</script> | ||
@@ -73,3 +73,3 @@ ``` | ||
<script type="module"> | ||
import * as pkg from '//dev.jspm.io/getcontributors@2.0.0' | ||
import * as pkg from '//dev.jspm.io/getcontributors@2.1.0' | ||
</script> | ||
@@ -76,0 +76,0 @@ ``` |
@@ -19,2 +19,7 @@ /* eslint camelcase:0 */ | ||
/** GitHub's response when an error occurs */ | ||
interface GitHubError { | ||
message: string | ||
} | ||
/** | ||
@@ -24,30 +29,87 @@ * GitHub's response to getting a repository | ||
*/ | ||
export type ContributorsResponse = StrictUnion< | ||
| Array<{ | ||
login: string | ||
id: number | ||
node_id: string | ||
avatar_url: string | ||
gravatar_id: string | ||
url: string | ||
html_url: string | ||
followers_url: string | ||
following_url: string | ||
gists_url: string | ||
starred_url: string | ||
subscriptions_url: string | ||
organizations_url: string | ||
repos_url: string | ||
events_url: string | ||
received_events_url: string | ||
type: string | ||
site_admin: false | ||
contributions: number | ||
}> | ||
| { message: string } | ||
export interface GitHubContributor { | ||
login: string | ||
id: number | ||
node_id: string | ||
avatar_url: string | ||
gravatar_id: string | ||
url: string | ||
html_url: string | ||
followers_url: string | ||
following_url: string | ||
gists_url: string | ||
starred_url: string | ||
subscriptions_url: string | ||
organizations_url: string | ||
repos_url: string | ||
events_url: string | ||
received_events_url: string | ||
type: string | ||
site_admin: boolean | ||
contributions: number | ||
} | ||
export type GitHubContributorsResponse = StrictUnion< | ||
GitHubError | Array<GitHubContributor> | ||
> | ||
// | ||
/** | ||
* GitHub's response to getting a user | ||
* https://developer.github.com/v3/users/#get-a-single-user | ||
*/ | ||
export interface GitHubProfile { | ||
login: string | ||
id: number | ||
node_id: string | ||
avatar_url: string | ||
gravatar_id: string | ||
url: string | ||
html_url: string | ||
followers_url: string | ||
following_url: string | ||
gists_url: string | ||
starred_url: string | ||
subscriptions_url: string | ||
organizations_url: string | ||
repos_url: string | ||
events_url: string | ||
received_events_url: string | ||
type: string | ||
site_admin: false | ||
name: string | ||
company: string | ||
blog: string | ||
location: string | ||
email: string | ||
hireable: boolean | ||
bio: string | ||
public_repos: number | ||
public_gists: number | ||
followers: number | ||
following: number | ||
created_at: string | ||
updated_at: string | ||
} | ||
export type GitHubProfileResponse = StrictUnion<GitHubError | GitHubProfile> | ||
/** Fetch Contributors from a Repository's GitHub Contributor API */ | ||
/** Fetch the full profile information for a contributor */ | ||
export async function getContributorProfile( | ||
url: string | ||
): Promise<GitHubProfile> { | ||
const resp = await fetch(url, { | ||
headers: { | ||
Accept: 'application/vnd.github.v3+json', | ||
}, | ||
}) | ||
const responseData = (await resp.json()) as GitHubProfileResponse | ||
// Check | ||
if (responseData.message) { | ||
return Promise.reject(new Error(responseData.message)) | ||
} | ||
// Return | ||
return responseData as GitHubProfile | ||
} | ||
/** Fetch contributors from a Repository's GitHub Contributor API */ | ||
export async function getContributorsFromCommits( | ||
@@ -63,3 +125,3 @@ slug: string | ||
}) | ||
const responseData = (await resp.json()) as ContributorsResponse | ||
const responseData = (await resp.json()) as GitHubContributorsResponse | ||
@@ -73,18 +135,32 @@ // Check | ||
) | ||
} else if (responseData.length === 0) { | ||
return new Set<Fellow>() | ||
} | ||
// Process | ||
const added = new Set<Fellow>() | ||
for (const user of responseData) { | ||
const fellow = Fellow.ensure({ | ||
github: user, | ||
githubUsername: user.login, | ||
githubUrl: user.html_url, | ||
}) | ||
fellow.contributedRepositories.add(slug) | ||
added.add(fellow) | ||
} | ||
// Return | ||
return added | ||
return new Set<Fellow>( | ||
await Promise.all( | ||
responseData.map(async function (contributor) { | ||
const profile = await getContributorProfile(contributor.url) | ||
const fellow = Fellow.ensure({ | ||
githubProfile: profile, | ||
name: profile.name, | ||
email: profile.email, | ||
description: profile.bio, | ||
company: profile.company, | ||
location: profile.location, | ||
homepage: profile.blog, | ||
hireable: profile.hireable, | ||
githubUsername: profile.login, | ||
githubUrl: profile.html_url, | ||
}) | ||
fellow.contributions.set(slug, contributor.contributions) | ||
if (contributor.site_admin) { | ||
fellow.administeredRepositories.add(slug) | ||
} | ||
fellow.contributedRepositories.add(slug) | ||
return fellow | ||
}) | ||
) | ||
) | ||
} | ||
@@ -91,0 +167,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
38383
535
1
3
Updatedfellow@^6.1.0