@bevry/github-commit
Advanced tools
Comparing version 1.0.0 to 1.1.0-next.1628116714.455a684bd80cb24b059cc1cabb8c6712b1ea2415
@@ -1,12 +0,9 @@ | ||
import { GitHubCredentials } from 'githubauthreq' | ||
import { GitHubCredentials } from '@bevry/github-api'; | ||
/** | ||
* Get the latest commit for a github repository | ||
* @param slug the organisation/user name along with the repository name, e.g. `bevry/github-commit` | ||
* @param slug the organization/user name along with the repository name, e.g. `bevry/github-commit` | ||
* @param credentials the github credentials you wish to use, otherwise it uses those within the env vars | ||
* @returns the latest github commit | ||
*/ | ||
export default function getLatestCommit( | ||
slug: string, | ||
credentials?: GitHubCredentials | ||
): Promise<string> | ||
//# sourceMappingURL=index.d.ts.map | ||
export default function getLatestCommit(slug: string, credentials?: GitHubCredentials): Promise<string>; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -1,22 +0,10 @@ | ||
// external | ||
import fetch from 'cross-fetch' | ||
// github | ||
import { getHeaders } from 'githubauthreq' | ||
import { env } from 'process' | ||
const { GITHUB_API = 'https://api.github.com' } = env | ||
// github auth | ||
import { query } from '@bevry/github-api'; | ||
/** Have the request fail with the details as to why */ | ||
function fail(slug, details) { | ||
return Promise.reject( | ||
new Error( | ||
`failed to fetch the latest commit for ${slug}\n${JSON.stringify( | ||
details, | ||
null, | ||
' ' | ||
)}` | ||
) | ||
) | ||
return Promise.reject(new Error(`failed to fetch the latest commit for ${slug}\n${JSON.stringify(details, null, ' ')}`)); | ||
} | ||
/** | ||
* Get the latest commit for a github repository | ||
* @param slug the organisation/user name along with the repository name, e.g. `bevry/github-commit` | ||
* @param slug the organization/user name along with the repository name, e.g. `bevry/github-commit` | ||
* @param credentials the github credentials you wish to use, otherwise it uses those within the env vars | ||
@@ -26,49 +14,41 @@ * @returns the latest github commit | ||
export default async function getLatestCommit(slug, credentials) { | ||
// prepare the request metadata | ||
const url = `${GITHUB_API}/repos/${slug}/commits` | ||
const headers = getHeaders(credentials) | ||
const init = { | ||
headers: { | ||
...headers, | ||
'User-Agent': '@bevry/github-commit', | ||
}, | ||
} | ||
// fetch url | ||
let response | ||
try { | ||
response = await fetch(url, init) | ||
} catch (err) { | ||
return fail(slug, { | ||
url, | ||
message: err, | ||
}) | ||
} | ||
// failed with error message | ||
if (response.status < 200 || response.status >= 300) { | ||
return fail(slug, { | ||
url, | ||
status: response.status, | ||
message: await response.text(), | ||
}) | ||
} | ||
// parse result | ||
const result = await response.json() | ||
// failed with json error message | ||
if (result.message) { | ||
return fail(slug, { | ||
url, | ||
message: result.message, | ||
}) | ||
} | ||
// unexpected result | ||
const commit = result[0] && result[0].sha | ||
if (!commit) { | ||
return fail(slug, { | ||
url, | ||
message: 'result was unexpected', | ||
result, | ||
}) | ||
} | ||
// success | ||
return commit | ||
// fetch | ||
let response; | ||
try { | ||
response = await query({ | ||
pathname: `repos/${slug}/commits`, | ||
userAgent: '@bevry/github-commit', | ||
credentials, | ||
}); | ||
} | ||
catch (err) { | ||
return fail(slug, { | ||
message: err, | ||
}); | ||
} | ||
// failed with error message | ||
if (response.status < 200 || response.status >= 300) { | ||
return fail(slug, { | ||
status: response.status, | ||
message: await response.text(), | ||
}); | ||
} | ||
// parse result | ||
const result = await response.json(); | ||
// failed with json error message | ||
if (result.message) { | ||
return fail(slug, { | ||
message: result.message, | ||
}); | ||
} | ||
// unexpected result | ||
const commit = result[0] && result[0].sha; | ||
if (!commit) { | ||
return fail(slug, { | ||
message: 'result was unexpected', | ||
result, | ||
}); | ||
} | ||
// success | ||
return commit; | ||
} |
# History | ||
## v1.1.0 2021 August 5 | ||
- Updated for [`@bevry/github-api`](https://github.com/bevry/github-api) | ||
- Updated dependencies, [base files](https://github.com/bevry/base), and [editions](https://editions.bevry.me) using [boundation](https://github.com/bevry/boundation) | ||
## v1.0.0 2020 November 4 | ||
- Extracted from [boundation](https://github.com/bevry/boundation/blob/dc5cf829585b319a8f033c2be8700020a3c7c191/source/get-github-commit.js) |
@@ -18,3 +18,3 @@ <!-- LICENSEFILE/ --> | ||
The above copyright notice and this permission notice (including the next paragraph) shall be included in all copies or substantial portions of the Software. | ||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
@@ -21,0 +21,0 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
100
package.json
{ | ||
"name": "@bevry/github-commit", | ||
"version": "1.0.0", | ||
"version": "1.1.0-next.1628116714.455a684bd80cb24b059cc1cabb8c6712b1ea2415", | ||
"description": "Fetch the latest commit of a GitHub repository", | ||
@@ -10,3 +10,3 @@ "homepage": "https://github.com/bevry/github-commit", | ||
"commit", | ||
"esnext", | ||
"es2019", | ||
"export-default", | ||
@@ -25,3 +25,3 @@ "gh", | ||
"list": [ | ||
"travisci", | ||
"githubworkflow", | ||
"npmversion", | ||
@@ -43,2 +43,3 @@ "npmdownloads", | ||
"config": { | ||
"githubWorkflow": "bevry", | ||
"githubSponsorsUsername": "balupton", | ||
@@ -53,7 +54,6 @@ "buymeacoffeeUsername": "balupton", | ||
"wishlistURL": "https://bevry.me/wishlist", | ||
"travisTLD": "com", | ||
"githubUsername": "bevry", | ||
"githubRepository": "github-commit", | ||
"githubSlug": "bevry/github-commit", | ||
"npmPackageName": "github-commit" | ||
"npmPackageName": "@bevry/github-commit" | ||
} | ||
@@ -66,2 +66,5 @@ }, | ||
], | ||
"contributors": [ | ||
"Benjamin Lupton <b@lupton.cc> (https://github.com/balupton)" | ||
], | ||
"bugs": { | ||
@@ -90,3 +93,3 @@ "url": "https://github.com/bevry/github-commit/issues" | ||
{ | ||
"description": "TypeScript compiled against ES2019 for web browsers with Import for modules", | ||
"description": "TypeScript compiled against ES2020 for web browsers with Import for modules", | ||
"directory": "edition-browsers", | ||
@@ -105,4 +108,4 @@ "entry": "index.js", | ||
{ | ||
"description": "TypeScript compiled against ESNext for Node.js 10 || 12 || 14 || 15 with Require for modules", | ||
"directory": "edition-esnext", | ||
"description": "TypeScript compiled against ES2019 for Node.js 10 || 12 || 14 || 16 with Require for modules", | ||
"directory": "edition-es2019", | ||
"entry": "index.js", | ||
@@ -112,7 +115,7 @@ "tags": [ | ||
"javascript", | ||
"esnext", | ||
"es2019", | ||
"require" | ||
], | ||
"engines": { | ||
"node": "10 || 12 || 14 || 15", | ||
"node": "10 || 12 || 14 || 16", | ||
"browsers": false | ||
@@ -122,4 +125,4 @@ } | ||
{ | ||
"description": "TypeScript compiled against ESNext for Node.js 12 || 14 || 15 with Import for modules", | ||
"directory": "edition-esnext-esm", | ||
"description": "TypeScript compiled against ES2019 for Node.js 12 || 14 || 16 with Import for modules", | ||
"directory": "edition-es2019-esm", | ||
"entry": "index.js", | ||
@@ -129,7 +132,7 @@ "tags": [ | ||
"javascript", | ||
"esnext", | ||
"es2019", | ||
"import" | ||
], | ||
"engines": { | ||
"node": "12 || 14 || 15", | ||
"node": "12 || 14 || 16", | ||
"browsers": false | ||
@@ -141,7 +144,7 @@ } | ||
"type": "module", | ||
"main": "edition-esnext/index.js", | ||
"main": "edition-es2019/index.js", | ||
"exports": { | ||
"node": { | ||
"import": "./edition-esnext-esm/index.js", | ||
"require": "./edition-esnext/index.js" | ||
"import": "./edition-es2019-esm/index.js", | ||
"require": "./edition-es2019/index.js" | ||
}, | ||
@@ -154,28 +157,31 @@ "browser": { | ||
"module": "edition-browsers/index.js", | ||
"dependencies": { | ||
"@bevry/github-api": "^9.0.0" | ||
}, | ||
"devDependencies": { | ||
"@bevry/update-contributors": "^1.18.0", | ||
"@typescript-eslint/eslint-plugin": "^4.6.1", | ||
"@typescript-eslint/parser": "^4.6.1", | ||
"assert-helpers": "^8.1.0", | ||
"eslint": "^7.12.1", | ||
"eslint-config-bevry": "^3.23.0", | ||
"eslint-config-prettier": "^6.15.0", | ||
"eslint-plugin-prettier": "^3.1.4", | ||
"kava": "^5.13.0", | ||
"make-deno-edition": "^1.2.0", | ||
"prettier": "^2.1.2", | ||
"projectz": "^2.17.0", | ||
"surge": "^0.21.6", | ||
"typedoc": "^0.19.2", | ||
"typescript": "^4.0.5", | ||
"valid-directory": "^3.5.0", | ||
"valid-module": "^1.15.0" | ||
"@bevry/update-contributors": "^1.20.0", | ||
"@typescript-eslint/eslint-plugin": "^4.29.0", | ||
"@typescript-eslint/parser": "^4.29.0", | ||
"assert-helpers": "^8.4.0", | ||
"eslint": "^7.32.0", | ||
"eslint-config-bevry": "^3.27.0", | ||
"eslint-config-prettier": "^8.3.0", | ||
"eslint-plugin-prettier": "^3.4.0", | ||
"kava": "^5.15.0", | ||
"make-deno-edition": "^1.3.0", | ||
"prettier": "^2.3.2", | ||
"projectz": "^2.22.0", | ||
"surge": "^0.23.0", | ||
"typedoc": "^0.21.5", | ||
"typescript": "4.3.5", | ||
"valid-directory": "^3.9.0", | ||
"valid-module": "^1.17.0" | ||
}, | ||
"scripts": { | ||
"our:clean": "rm -Rf ./docs ./edition* ./es2015 ./es5 ./out ./.next", | ||
"our:compile": "npm run our:compile:deno && npm run our:compile:edition-browsers && npm run our:compile:edition-esnext && npm run our:compile:edition-esnext-esm && npm run our:compile:types", | ||
"our:compile": "npm run our:compile:deno && npm run our:compile:edition-browsers && npm run our:compile:edition-es2019 && npm run our:compile:edition-es2019-esm && npm run our:compile:types", | ||
"our:compile:deno": "make-deno-edition --attempt", | ||
"our:compile:edition-browsers": "tsc --module ESNext --target ES2019 --outDir ./edition-browsers --project tsconfig.json && ( test ! -d edition-browsers/source || ( mv edition-browsers/source edition-temp && rm -Rf edition-browsers && mv edition-temp edition-browsers ) )", | ||
"our:compile:edition-esnext": "tsc --module commonjs --target ESNext --outDir ./edition-esnext --project tsconfig.json && ( test ! -d edition-esnext/source || ( mv edition-esnext/source edition-temp && rm -Rf edition-esnext && mv edition-temp edition-esnext ) ) && echo '{\"type\": \"commonjs\"}' > edition-esnext/package.json", | ||
"our:compile:edition-esnext-esm": "tsc --module ESNext --target ESNext --outDir ./edition-esnext-esm --project tsconfig.json && ( test ! -d edition-esnext-esm/source || ( mv edition-esnext-esm/source edition-temp && rm -Rf edition-esnext-esm && mv edition-temp edition-esnext-esm ) ) && echo '{\"type\": \"module\"}' > edition-esnext-esm/package.json", | ||
"our:compile:edition-browsers": "tsc --module ESNext --target ES2020 --outDir ./edition-browsers --project tsconfig.json && ( test ! -d edition-browsers/source || ( mv edition-browsers/source edition-temp && rm -Rf edition-browsers && mv edition-temp edition-browsers ) )", | ||
"our:compile:edition-es2019": "tsc --module commonjs --target ES2019 --outDir ./edition-es2019 --project tsconfig.json && ( test ! -d edition-es2019/source || ( mv edition-es2019/source edition-temp && rm -Rf edition-es2019 && mv edition-temp edition-es2019 ) ) && echo '{\"type\": \"commonjs\"}' > edition-es2019/package.json", | ||
"our:compile:edition-es2019-esm": "tsc --module ESNext --target ES2019 --outDir ./edition-es2019-esm --project tsconfig.json && ( test ! -d edition-es2019-esm/source || ( mv edition-es2019-esm/source edition-temp && rm -Rf edition-es2019-esm && mv edition-temp edition-es2019-esm ) ) && echo '{\"type\": \"module\"}' > edition-es2019-esm/package.json", | ||
"our:compile:types": "tsc --project tsconfig.json --emitDeclarationOnly --declaration --declarationMap --declarationDir ./compiled-types && ( test ! -d compiled-types/source || ( mv compiled-types/source edition-temp && rm -Rf compiled-types && mv edition-temp compiled-types ) )", | ||
@@ -186,3 +192,3 @@ "our:deploy": "echo no need for this project", | ||
"our:meta:docs": "npm run our:meta:docs:typedoc", | ||
"our:meta:docs:typedoc": "rm -Rf ./docs && typedoc --mode file --exclude '**/+(*test*|node_modules)' --excludeExternals --name \"$npm_package_name\" --readme ./README.md --out ./docs ./source", | ||
"our:meta:docs:typedoc": "rm -Rf ./docs && typedoc --exclude '**/+(*test*|node_modules)' --excludeExternals --out ./docs ./source", | ||
"our:meta:projectz": "projectz compile", | ||
@@ -193,3 +199,3 @@ "our:release": "npm run our:release:prepare && npm run our:release:check-changelog && npm run our:release:check-dirty && npm run our:release:tag && npm run our:release:push", | ||
"our:release:prepare": "npm run our:clean && npm run our:compile && npm run our:test && npm run our:meta", | ||
"our:release:push": "git push origin master && git push origin --tags", | ||
"our:release:push": "git push origin && git push origin --tags", | ||
"our:release:tag": "export MESSAGE=$(cat ./HISTORY.md | sed -n \"/## v$npm_package_version/,/##/p\" | sed 's/## //' | awk 'NR>1{print buf}{buf = $0}') && test \"$MESSAGE\" || (echo 'proper changelog entry not found' && exit -1) && git tag v$npm_package_version -am \"$MESSAGE\"", | ||
@@ -204,3 +210,3 @@ "our:setup": "npm run our:setup:install", | ||
"our:verify:prettier": "prettier --write .", | ||
"test": "node ./edition-esnext/test.js" | ||
"test": "node ./edition-es2019/test.js" | ||
}, | ||
@@ -216,9 +222,7 @@ "eslintConfig": { | ||
}, | ||
"dependencies": { | ||
"cross-fetch": "^3.0.6", | ||
"githubauthreq": "^5.19.0" | ||
}, | ||
"contributors": [ | ||
"Benjamin Lupton <b@lupton.cc> (https://github.com/balupton)" | ||
] | ||
"boundation": { | ||
"githubActionTestEnv": { | ||
"GITHUB_TOKEN": "${{ secrets.GITHUB_TOKEN }}" | ||
} | ||
} | ||
} |
@@ -10,5 +10,5 @@ <!-- TITLE/ --> | ||
<span class="badge-travisci"><a href="http://travis-ci.com/bevry/github-commit" title="Check this project's build status on TravisCI"><img src="https://img.shields.io/travis/com/bevry/github-commit/master.svg" alt="Travis CI Build Status" /></a></span> | ||
<span class="badge-npmversion"><a href="https://npmjs.org/package/github-commit" title="View this project on NPM"><img src="https://img.shields.io/npm/v/github-commit.svg" alt="NPM version" /></a></span> | ||
<span class="badge-npmdownloads"><a href="https://npmjs.org/package/github-commit" title="View this project on NPM"><img src="https://img.shields.io/npm/dm/github-commit.svg" alt="NPM downloads" /></a></span> | ||
<span class="badge-githubworkflow"><a href="https://github.com/bevry/github-commit/actions?query=workflow%3Abevry" title="View the status of this project's GitHub Workflow: bevry"><img src="https://github.com/bevry/github-commit/workflows/bevry/badge.svg" alt="Status of the GitHub Workflow: bevry" /></a></span> | ||
<span class="badge-npmversion"><a href="https://npmjs.org/package/@bevry/github-commit" title="View this project on NPM"><img src="https://img.shields.io/npm/v/@bevry/github-commit.svg" alt="NPM version" /></a></span> | ||
<span class="badge-npmdownloads"><a href="https://npmjs.org/package/@bevry/github-commit" title="View this project on NPM"><img src="https://img.shields.io/npm/dm/@bevry/github-commit.svg" alt="NPM downloads" /></a></span> | ||
<span class="badge-daviddm"><a href="https://david-dm.org/bevry/github-commit" title="View the status of this project's dependencies on DavidDM"><img src="https://img.shields.io/david/bevry/github-commit.svg" alt="Dependency Status" /></a></span> | ||
@@ -39,3 +39,3 @@ <span class="badge-daviddmdev"><a href="https://david-dm.org/bevry/github-commit#info=devDependencies" title="View the status of this project's development dependencies on DavidDM"><img src="https://img.shields.io/david/dev/bevry/github-commit.svg" alt="Dev Dependency Status" /></a></span> | ||
[Complete API Documentation.](http://master.github-commit.bevry.surge.sh/docs/globals.html) | ||
[Complete API Documentation.](http://master.github-commit.bevry.surge.sh/docs/) | ||
@@ -45,10 +45,13 @@ ```typescript | ||
import getCommit from '@bevry/github-commit` | ||
// fetch the commit | ||
const commit = await getCommit('bevry/github-commit').catch((err) => { | ||
// if something went wrong, such as unauthorised, empty repository, no internet connection | ||
// if something went wrong, such as unauthorized, empty repository, no internet connection | ||
// then log the error as a warning | ||
console.warn(err) | ||
// and fallback to master | ||
return 'master' | ||
}) | ||
// log the eventual result | ||
@@ -73,3 +76,3 @@ console.log(commit) | ||
<script type="module"> | ||
import pkg from '//cdn.skypack.dev/@bevry/github-commit@^1.0.0' | ||
import pkg from '//cdn.skypack.dev/@bevry/github-commit@^1.1.0' | ||
</script> | ||
@@ -82,3 +85,3 @@ ``` | ||
<script type="module"> | ||
import pkg from '//unpkg.com/@bevry/github-commit@^1.0.0' | ||
import pkg from '//unpkg.com/@bevry/github-commit@^1.1.0' | ||
</script> | ||
@@ -91,3 +94,3 @@ ``` | ||
<script type="module"> | ||
import pkg from '//dev.jspm.io/@bevry/github-commit@1.0.0' | ||
import pkg from '//dev.jspm.io/@bevry/github-commit@1.1.0' | ||
</script> | ||
@@ -101,6 +104,6 @@ ``` | ||
<ul><li><code>@bevry/github-commit/source/index.ts</code> is <a href="https://www.typescriptlang.org/" title="TypeScript is a typed superset of JavaScript that compiles to plain JavaScript. ">TypeScript</a> source code with <a href="https://babeljs.io/docs/learn-es2015/#modules" title="ECMAScript Modules">Import</a> for modules</li> | ||
<li><code>@bevry/github-commit/edition-browsers/index.js</code> is <a href="https://www.typescriptlang.org/" title="TypeScript is a typed superset of JavaScript that compiles to plain JavaScript. ">TypeScript</a> compiled against <a href="https://en.wikipedia.org/wiki/ECMAScript#10th_Edition_-_ECMAScript_2019" title="ECMAScript ES2019">ES2019</a> for web browsers with <a href="https://babeljs.io/docs/learn-es2015/#modules" title="ECMAScript Modules">Import</a> for modules</li> | ||
<li><code>@bevry/github-commit</code> aliases <code>@bevry/github-commit/edition-esnext/index.js</code></li> | ||
<li><code>@bevry/github-commit/edition-esnext/index.js</code> is <a href="https://www.typescriptlang.org/" title="TypeScript is a typed superset of JavaScript that compiles to plain JavaScript. ">TypeScript</a> compiled against <a href="https://en.wikipedia.org/wiki/ECMAScript#ES.Next" title="ECMAScript Next">ESNext</a> for <a href="https://nodejs.org" title="Node.js is a JavaScript runtime built on Chrome's V8 JavaScript engine">Node.js</a> 10 || 12 || 14 || 15 with <a href="https://nodejs.org/dist/latest-v5.x/docs/api/modules.html" title="Node/CJS Modules">Require</a> for modules</li> | ||
<li><code>@bevry/github-commit/edition-esnext-esm/index.js</code> is <a href="https://www.typescriptlang.org/" title="TypeScript is a typed superset of JavaScript that compiles to plain JavaScript. ">TypeScript</a> compiled against <a href="https://en.wikipedia.org/wiki/ECMAScript#ES.Next" title="ECMAScript Next">ESNext</a> for <a href="https://nodejs.org" title="Node.js is a JavaScript runtime built on Chrome's V8 JavaScript engine">Node.js</a> 12 || 14 || 15 with <a href="https://babeljs.io/docs/learn-es2015/#modules" title="ECMAScript Modules">Import</a> for modules</li></ul> | ||
<li><code>@bevry/github-commit/edition-browsers/index.js</code> is <a href="https://www.typescriptlang.org/" title="TypeScript is a typed superset of JavaScript that compiles to plain JavaScript. ">TypeScript</a> compiled against <a href="https://en.wikipedia.org/wiki/ECMAScript#11th_Edition_–_ECMAScript_2020" title="ECMAScript ES2020">ES2020</a> for web browsers with <a href="https://babeljs.io/docs/learn-es2015/#modules" title="ECMAScript Modules">Import</a> for modules</li> | ||
<li><code>@bevry/github-commit</code> aliases <code>@bevry/github-commit/edition-es2019/index.js</code></li> | ||
<li><code>@bevry/github-commit/edition-es2019/index.js</code> is <a href="https://www.typescriptlang.org/" title="TypeScript is a typed superset of JavaScript that compiles to plain JavaScript. ">TypeScript</a> compiled against <a href="https://en.wikipedia.org/wiki/ECMAScript#10th_Edition_-_ECMAScript_2019" title="ECMAScript ES2019">ES2019</a> for <a href="https://nodejs.org" title="Node.js is a JavaScript runtime built on Chrome's V8 JavaScript engine">Node.js</a> 10 || 12 || 14 || 16 with <a href="https://nodejs.org/dist/latest-v5.x/docs/api/modules.html" title="Node/CJS Modules">Require</a> for modules</li> | ||
<li><code>@bevry/github-commit/edition-es2019-esm/index.js</code> is <a href="https://www.typescriptlang.org/" title="TypeScript is a typed superset of JavaScript that compiles to plain JavaScript. ">TypeScript</a> compiled against <a href="https://en.wikipedia.org/wiki/ECMAScript#10th_Edition_-_ECMAScript_2019" title="ECMAScript ES2019">ES2019</a> for <a href="https://nodejs.org" title="Node.js is a JavaScript runtime built on Chrome's V8 JavaScript engine">Node.js</a> 12 || 14 || 16 with <a href="https://babeljs.io/docs/learn-es2015/#modules" title="ECMAScript Modules">Import</a> for modules</li></ul> | ||
@@ -107,0 +110,0 @@ <!-- /INSTALL --> |
@@ -1,9 +0,4 @@ | ||
// external | ||
import fetch from 'cross-fetch' | ||
// github auth | ||
import { query, GitHubCredentials } from '@bevry/github-api' | ||
// github | ||
import { getHeaders, GitHubCredentials } from 'githubauthreq' | ||
import { env } from 'process' | ||
const { GITHUB_API = 'https://api.github.com' } = env | ||
/** Have the request fail with the details as to why */ | ||
@@ -24,3 +19,3 @@ function fail(slug: string, details: object) { | ||
* Get the latest commit for a github repository | ||
* @param slug the organisation/user name along with the repository name, e.g. `bevry/github-commit` | ||
* @param slug the organization/user name along with the repository name, e.g. `bevry/github-commit` | ||
* @param credentials the github credentials you wish to use, otherwise it uses those within the env vars | ||
@@ -33,25 +28,19 @@ * @returns the latest github commit | ||
): Promise<string> { | ||
// prepare the request metadata | ||
const url = `${GITHUB_API}/repos/${slug}/commits` | ||
const headers = getHeaders(credentials) | ||
const init = { | ||
headers: { | ||
...headers, | ||
'User-Agent': '@bevry/github-commit', | ||
}, | ||
} | ||
// fetch url | ||
// fetch | ||
let response: Response | ||
try { | ||
response = await fetch(url, init) | ||
response = await query({ | ||
pathname: `repos/${slug}/commits`, | ||
userAgent: '@bevry/github-commit', | ||
credentials, | ||
}) | ||
} catch (err) { | ||
return fail(slug, { | ||
url, | ||
message: err, | ||
}) | ||
} | ||
// failed with error message | ||
if (response.status < 200 || response.status >= 300) { | ||
return fail(slug, { | ||
url, | ||
status: response.status, | ||
@@ -61,11 +50,13 @@ message: await response.text(), | ||
} | ||
// parse result | ||
const result = await response.json() | ||
// failed with json error message | ||
if (result.message) { | ||
return fail(slug, { | ||
url, | ||
message: result.message, | ||
}) | ||
} | ||
// unexpected result | ||
@@ -75,3 +66,2 @@ const commit = result[0] && result[0].sha | ||
return fail(slug, { | ||
url, | ||
message: 'result was unexpected', | ||
@@ -81,4 +71,5 @@ result, | ||
} | ||
// success | ||
return commit | ||
} |
@@ -9,4 +9,3 @@ { | ||
"strict": true, | ||
"target": "ESNext", | ||
"lib": ["ESNext"], | ||
"target": "ES2019", | ||
"module": "ESNext" | ||
@@ -13,0 +12,0 @@ }, |
Sorry, the diff of this file is not supported yet
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
1
172
1
28762
13
246
1
+ Added@bevry/github-api@^9.0.0
+ Added@bevry/github-api@9.0.0(transitive)
+ Added@bevry/wait@1.1.0(transitive)
- Removedcross-fetch@^3.0.6
- Removedgithubauthreq@^5.19.0
- Removedcross-fetch@3.2.0(transitive)
- Removededitions@6.21.0(transitive)
- Removedgithubauthreq@5.19.0(transitive)
- Removedversion-range@4.14.0(transitive)