readme-inspector
+ Inspect GitHub (and GitHub Enterprise) repositories for the presence and quality of READMEs.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Table of contents
+
+1. Installation
readme-inspector
is written in JavaScript (CommonJS) for Node.js versions 7.6.0 or higher (for async/await
support).
+$ npm install --save readme-inspector
2. Configuration
The commonality/readme-inspector
module combines the mediator, proxy, and factory design patterns to simplify:
+
+- README detection with the
readmeInfo
object, and
+- Quality assessment with the
readmeInfo.appraisal
object.
+
+
+ **Avoid rate-limiting, you should create a personal access token and save your personal access token in an environment variable called GH_TOKEN
.
+
+
+Click here for detailed .env variable initialization instructions
+
+
+
+properties
+# .env.schema, committed to repo
+
+## See https://github.com/keithmorris/node-dotenv-extended/#readme
+## ⛔️
+## 🚫 DO NOT COMMIT YOUR ACTUAL .env file to version control.
+## 🚫 It should only include environment-specific values such
+## 🚫 as database passwords or API keys.
+## 🚫 Your production database should have a different password
+## 🚫 than your development database.
+
+# ENV VARS required for readme-inspector
+## Add values to these ENV VARs and save to
+## {your-project-root-directory}/.env
+
+# 🔹 OPTIONAL env vars:
+API_ENDPOINT_README_SCORE=
+GA_README_INSPECTOR=
+
+# 🔸 RECOMMENDED vars (to extend GitHub API rate limits)
+GH_TOKEN=
+GITHUB_ACCESS_TOKEN=
+
+
+
+
+properties
+# .env.defaults, committed to repo
+
+## See https://github.com/keithmorris/node-dotenv-extended/#readme
+## ⛔️
+## 🚫 DO NOT COMMIT YOUR ACTUAL .env file to version control.
+## 🚫 It should only include environment-specific values such
+## 🚫 as database passwords or API keys.
+## 🚫 Your production database should have a different password
+## 🚫 than your development database.
+
+# ENV VARS defaults for readme-inspector:
+
+## Google Analytics trackingCode
+GA_README_INSPECTOR="UA-117338111-1"
+
+# ReadmeAppraisal
+API_ENDPOINT_README_SCORE="http://readme-score-api.herokuapp.com/score.json?url=&human_breakdown=false&force=false"
+
+
+
+
+
+2. Usage
+
+// Load all .env variables before anything else.
+
+const dotenvExtended = require('dotenv-extended')
+const envConfig = dotenvExtended.config()
+
+// Import readme-inspector.
+
+const readmeInspector = require('readme-inspector')
+
+// Recommended: authenticate to avoid rate limts.
+
+readmeInspector.authenticate({
+ token: envConfig.GH_TOKEN,
+ type: 'oauth'
+})
+
+// Verify that the repository with the slug
+// gregswindle/github-resource-converter
+// 1. Has a README, and
+// 2. Score the README for quality.
+
+const info = await readmeInspector.check(
+ 'gregswindle',
+ 'github-resource-converter'
+)
+
+// Display the resulting readmeInfo as a
+// JSON string.
+
+const WHITESPACE = 2
+console.log(JSON.stringify(results, null, WHITESPACE))
+// =>
+/*
+{
+ "appraisal": {
+ "breakdown": {
+ "cumulativeCodeBlockLength": 0,
+ "hasLists": 0,
+ "lowCodeBlockPenalty": 0,
+ "numberOfCodeBlocks": 0,
+ "numberOfGifs": 0,
+ "numberOfImages": 0,
+ "numberOfNonCodeSections": 0
+ },
+ "error": null,
+ "score": 0,
+ "url": null
+ },
+ "error": null,
+ "isPresent": true,
+ "value": {
+ "name": "README.md",
+ "path": "README.md",
+ "sha": "4769744aad57ff3e9aac2df603795c4d10fcdc31",
+ "size": 36877,
+ "url": "https://api.github.com/repos/commonality/readme-inspector/contents/README.md?ref=master",
+ "html_url": "https://github.com/commonality/readme-inspector/blob/master/README.md",
+ "git_url": "https://api.github.com/repos/commonality/readme-inspector/git/blobs/4769744aad57ff3e9aac2df603795c4d10fcdc31",
+ "download_url": "https://raw.githubusercontent.com/commonality/readme-inspector/master/README.md",
+ "type": "file",
+ "content": "{base64-encoding-of-readme-markdown}",
+ "encoding": "base64",
+ "_links": {
+ "self": "https://api.github.com/repos/commonality/readme-inspector/contents/README.md?ref=master",
+ "git": "https://api.github.com/repos/commonality/readme-inspector/git/blobs/4769744aad57ff3e9aac2df603795c4d10fcdc31",
+ "html": "https://github.com/commonality/readme-inspector/blob/master/README.md"
+ }
+ }
+}
+*/
+3. API
+ Test readme-inspector
in your Web browser .
+ View the full API docs for details.
+
+The readmeInspector
module detects whether or not a README document exists at the root of a GitHub or GitHub Enterprise repository. If a README exists, it can evaluate the README's quality and provide a numerical score from 0 to 100, where 0 is the lowest quality and 100 is the highest.
+3.1. authenticate({token, type, key})
+ Most GitHub API calls don't require authentication. Rules of thumb:
+
+- If you can see the information by visiting the site without being logged in, you don't have to be authenticated to retrieve the same information through the API.
+- If you want to change data, you have to be authenticated.
+
+octokit/rest.js. (2018). GitHub. Retrieved 21 March 2018, from https://github.com/octokit/rest.js#authentication
+
+3.1.1. Parameters
+
+
+Name |
+Type |
+Description |
+Notes |
+
+
+
+
+key |
+String |
+ |
+ |
+
+
+token |
+String |
+ |
+ |
+
+
+type |
+Enum |
+basic , oauth , oauth-key-secret , token , and integration |
+
+
+
+3.1.2. Returns void
authenticate
does not return a value.
+3.1.3. Example
+// Token (https://github.com/settings/tokens)
+// Load your GH_TOKEN or GITHUB_ACCESS_TOKEN from
+// environment variables:
+const dotenvExtended = require('dotenv-extended')
+const envConfig = dotenvExtended.config()
+
+const readmeInspector = require('readme-inspector')
+
+readmeInspector.authenticate({
+ token: envConfig.GH_TOKEN,
+ type: 'token'
+})
+3.2. check({ower, repo, ref})
A convenience method that
+
+- Attempts to GET a repository's root-level README, and, if found,
+- Scores the README.
+
+
+/repos/:owner/:repo/readme
3.2.1. Parameters
+
+
+ Field |
+ Type |
+ Description |
+
+
+
+
+ owner |
+
+ String
+ |
+ |
+
+
+ repo |
+
+ String
+ |
+ |
+
+
+ ref |
+
+ String
+ |
+ The name of the commit/branch/tag. Default: the repository’s default branch (usually master). |
+
+
+
+
+3.2.2. Returns Promise<ReadmeInfo>
ReadmeInfo's
interface (as a NullObject
):
+{
+ 'err': null,
+ 'isPresent': null,
+ 'appraisal': {
+ 'breakdown': {
+ 'cumulativeCodeBlockLength': 0,
+ 'hasLists': 0,
+ 'lowCodeBlockPenalty': 0,
+ 'numberOfCodeBlocks': 0,
+ 'numberOfGifs': 0,
+ 'numberOfImages': 0,
+ 'numberOfNonCodeSections': 0
+ },
+ 'err': null,
+ 'score': 0,
+ 'url': null
+ },
+ 'value': null
+}
3.2.3. Examples
+async/await:
+
+const readmeInfo = await readmeInspector.check({
+ owner: 'commonality',
+ ref: 'GH-1-feat-inspect-readmes',
+ repo: 'readme-inspector'
+})
+
+Promise:
+
+readmeInspector
+ .check({
+ owner: 'commonality',
+ ref: 'GH-1-feat-inspect-readmes',
+ repo: 'readme-inspector'
+ })
+ .then(readmeInfo => {})
+ .catch(err => {})
+
+
+3.3. getInfo({owner, repo, ref})
Retrieves README information without any AppraisalData
.
+
+/repos/:owner/:repo/readme
3.3.1. Parameters
+
+
+ Field |
+ Type |
+ Description |
+
+
+
+
+ owner |
+
+ String
+ |
+ |
+
+
+ repo |
+
+ String
+ |
+ |
+
+
+ ref |
+
+ String
+ |
+ The name of the commit/branch/tag. Default: the repository’s default branch (usually master). |
+
+
+
+
+3.3.2. Returns Promise<ReadmeInfo>
ReadmeInfo's
interface (as a NullObject
):
+{
+ 'err': null,
+ 'isPresent': null,
+ 'appraisal': {
+ 'breakdown': {
+ 'cumulativeCodeBlockLength': 0,
+ 'hasLists': 0,
+ 'lowCodeBlockPenalty': 0,
+ 'numberOfCodeBlocks': 0,
+ 'numberOfGifs': 0,
+ 'numberOfImages': 0,
+ 'numberOfNonCodeSections': 0
+ },
+ 'err': null,
+ 'score': 0,
+ 'url': null
+ },
+ 'value': null
+}
3.3.3. Examples
+async/await:
+
+const readmeInfo = await readmeInspector.getInfo({
+ owner: 'commonality',
+ ref: 'GH-1-feat-inspect-readmes',
+ repo: 'readme-inspector'
+})
+
+Promise:
+
+readmeInspector
+ .getInfo({
+ owner: 'commonality',
+ ref: 'GH-1-feat-inspect-readmes',
+ repo: 'readme-inspector'
+ })
+ .then(readmeInfo => {})
+ .catch(err => {})
+
+
+3.4. getAppraisal(url)
A convenience wrapper that calls the ReadmeAppraisal.prototype.for
method.
+3.5. ReadmeAppraisal
ReadmeAppraisal
is an API proxy for @clayallsopp 's readme-score-api
.
+
+ ScoreMe gives you a numerical score from 0 to 100 for your Github-style README. The intention is to measure complexity, which is a generally correlated with quality.
+It won't measure if one README is absolutely better than another, but it will give you a good idea if the README is high-quality, needs more work, or somewhere inbetween.
+ScoreMe. (2018). Clayallsopp.github.io. Retrieved 10 April 2018, from http://clayallsopp.github.io/readme-score/
+
+3.5.1. for(url): Promise<AppraisalData>
Evaluate the README at the root of a GitHub repository.
+3.5.1.1. Parameters
+
+
+Name |
+Type |
+Description |
+
+
+
+
+url |
+String |
+The URL, or slug of the repository to be evaluated for a README. |
+
+
+
+3.5.1.2. Returns Promise<AppraisalData>
+3.5.1.3. Examples
+URL:
+
+const { ReadmeAppraisal } = require('readme-inspector')
+const readmeAppraisal = new ReadmeAppraisal()
+const url = 'https://github.com/gregswindle/github-resource-converter'
+
+const appraisal = readmeAppraisal.for(url)
+/** =>
+ * {
+ * breakdown: {
+ * cumulativeCodeBlockLength: 10
+ * hasLists: 10
+ * lowCodeBlockPenalty: 0
+ * numberOfCodeBlocks: 40
+ * numberOfGifs: 0
+ * numberOfImages: 15
+ * numberOfNonCodeSections: 30
+ * },
+ * err: null,
+ * score: 100
+ * url: 'https://github.com/gregswindle/github-resource-converter'
+ * }
+ */
+
+Repository slug:
+
+const { ReadmeAppraisal } = require('readme-inspector')
+const readmeAppraisal = new ReadmeAppraisal()
+const url = 'gregswindle/github-resource-converter'
+
+const appraisal = readmeAppraisal.for(url)
+
+
+4. Version
+View the Change Log and Releases for details.
+5. Contributing
We welcome contributions with GitHub issues and pull requests.
+
+
+
+
+
+Before embarking on a significant change, please follow these guidelines:
+
+Create an issue—e.g., a defect ("bug") report or a feature request—to propose changes.
+Exceptions:
+
+If you're working on documentation and fixing something simple like a typo or an easy bug, go ahead and make a pull request.
+
+
+Follow the CONTRIBUTING guidelines.
+Why:
+
+Standards and guidelines make communication easier. If you're willing and able to program—or want to learn how— following the guidelines will increase the likelihood of having your changes added to readme-inspector
.
+
+
+Read the Code of Conduct.
+
+Make a pull request when you're ready for other to review your changes (or you get stuck somewhere).
+Never created a pull request?
+
+No problem: this free online training covers most of the conventions in the CONTRIBUTING guidelines.)
+
+
+
+6. License
MIT © commonality
+
+
+
+
+
+
+
+
+
+