Skip to content

Instantly share code, notes, and snippets.

@jyydev
Last active June 29, 2021 06:27
Show Gist options
  • Save jyydev/7ca9cdf17f1c7bc42f41da1977909463 to your computer and use it in GitHub Desktop.
Save jyydev/7ca9cdf17f1c7bc42f41da1977909463 to your computer and use it in GitHub Desktop.
demo gist api

Demo Gist API

  • Type: full code example
  • Language: javascript, node.js
  • Demo: update an existing gist:
    • create a new file in a gist
    • edit the content of a gist file

Requirements

  • Github personal access token
  • Run: npm i @octokit/core in terminal

1 file

References

const { Octokit } = require('@octokit/core');
// process.env.GITHUB_TOKEN = personal access token from your Github account
const token = process.env.GITHUB_TOKEN
// gistId = the specific id of a gist (found in url)
let gistId = '{INPUT_GIST_ID}'
const octokit = new Octokit({
auth: token,
})
octokit
.request(`PATCH /gists/${gistId}`, {
gist_id: gistId,
description: 'description test1',
files: { 'test1.md': { content: 'content test1' } },
})
.then((rs) => console.log(rs));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment