Skip to content

Instantly share code, notes, and snippets.

@endepointe
Last active October 9, 2022 13:58
Show Gist options
  • Save endepointe/241bfadd5efd24cf43a2c297c09e2610 to your computer and use it in GitHub Desktop.
Save endepointe/241bfadd5efd24cf43a2c297c09e2610 to your computer and use it in GitHub Desktop.
Description
  1. ensure you can install the request module either globally or locally.

    globally: npm i -g request

    locally: first, make a directory and change to that directory.

     run the commands: 
     	npm init
     	npm	i request
    

Run the script:

node delete_your_gists.js <your_token>
const request = require('request');
// supply your token as the first command line argument.
// e.g.
// node delete_your_gists.js <your_token>
const token = process.argv[2];
request({
url: "https://api.github.com/gists",
method: "GET",
headers: {
"Accept": "application/vnd.github+json",
"Authorization": "Bearer " + token,
"User-Agent": "request"
}
},
function(err,res,body) {
if (err) {
return console.error(err);
}
let gists = JSON.parse(body);
gists.forEach((gist) => {
deleteGist(gist.id);
});
}
);
function deleteGist(id) {
console.log("deleting gist ", id);
request({
url: "https://api.github.com/gists/" + id,
method: "DELETE",
headers: {
"Accept": "application/vnd.github+json",
"Authorization": "Bearer " + token,
"User-Agent": "request"
}
},
function(err,res,body) {
if (err) {
return console.error(err);
}
console.log("successfully deleted gist ", id);
}
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment