Home

Using Octokit

Resource

  1. Octokit - GitHub
  2. Octokit - Documentation
  3. Creating a Personal Access Token

Adding a file to a repo

npm install @octokit/rest

Usage

const { Octokit } = require('@octokit/rest'); const octokit = new Octokit(); // Compare: https://developer.github.com/v3/repos/#list-organization-repositories octokit.repos .listForOrg({ org: 'octokit', type: 'public', }) .then(({ data }) => { // handle data });

Adding a file to a repo using Octokit

const { Octokit } = require('@octokit/rest'); const { Base64 } = require('js-base64'); const fs = require('fs'); if (process.env.MODE !== 'production') { require('dotenv').config(); } const octokit = new Octokit({ auth: process.env.GITHUB_ACCESS_TOKEN, }); const content = fs.readFileSync('file/to/path', 'utf-8'); const fileOutput = Base64.encode(content); const { data } = await octokit.repos.createOrUpdateFileContents({ owner: 'okeeffed', repo: 'octokit-create-file-example', path: 'OUTPUT.md', message: 'feat: Added OUTPUT.md programatically', content: contentEncoded, committer: { name: `Octokit Bot`, email: 'hello@dennisokeeffe.com', }, author: { name: 'Octokit Bot', email: 'hello@dennisokeeffe.com', }, });

Repository

https://github.com/okeeffed/developer-notes-nextjs/content/github/using-octokit

Sections


Related