upend / IF_MS_BUYS_GITHUB_IMMA_OUT

GitHub has sold us out. Time to get out.
3.65k stars 54 forks source link

Anyway to import gists? #121

Closed sytranvn closed 5 years ago

sytranvn commented 6 years ago

How to import snippets like we do with project to gitlab or other platform?

tst2005 commented 6 years ago

For now I only have a workaround : "convert all gists to a repository". I created a repository and import each gist in one separated branch.

git clone all_my_gist_url gists
git clone one_gist_url one_gist
cd gists
git fetch ../one_gist
git checkout -b one_gist FETCH_HEAD
sytranvn commented 6 years ago
#!/usr/bin/env node

const exec = require('child_process').exec
const https = require('https')

console.log(`Fetching gists data of user ${process.argv[2]}`)

function execute(command) {

    exec(command, (err, stdout, stderr) => {
        process.stdout.write(stdout)
    })
}

function request(path) {
    const options = {
        hostname: 'api.github.com',
        path,
        method: 'GET',
        headers: { 'User-Agent': 'Mozilla/5.0' }
    }
    return new Promise((resolve, reject) => {
        let body = ''
        https.get(options, res => {
            res.on('data', data => body += data)
            res.on('end', () => resolve(body))
        })
    })
}

request(`/users/${process.argv[2]}/gists`)
    .then(data => {
        return JSON.parse(data)
    })
    .then(gists => {
        console.log(gists)
        gists.forEach(gist => {
            const file = Object.keys(gist.files)[0]
            console.log('Found gist ' + file)
            console.log(`Cloning ${gist.git_pull_url} into ${file}...`)

            exec(`git clone ${gist.git_pull_url} ${file}`)
        })
    })
    .then(() => console.log('Waiting for the magic.....'))

I ended up writing a script myself to do the job. But this script just works on public gists only. Just create clone.js file with script above, then run clone.js your_account. Next step is to auto push those gists to gitlab smh. BTW, I'm not sure if it works on Windows :confused:

tst2005 commented 6 years ago

you have a typo : s/gitst/gists/

sytranvn commented 6 years ago

Thanks mate. I also found gitlab api documents to create snippets here. https://docs.gitlab.com/ee/api/snippets.html#create-new-snippet I will try to write step 2 soon.