Version control with AutoGist

Original Gister by @acp http://twolivesleft.com/Codea/Talk/discussion/comment/21842#Comment_21842

UPDATED to version 2 Now get your Github token inside the app
http://twolivesleft.com/Codea/Talk/discussion/2744/autogist-v2-0-backup-your-projects-as-a-gist#Item_2

I had been using Gister by @acp. But I found that i rarely took the time to update my gists and when I did I would have to find the gist ID for my last gist. This resulted in creating multipal gists of my projects. I added on to @acp 's library to only update the gist when the version number changes. So just include this as a library and set the required info.@acp did all the work on this I just added version checking. So all credit is @acp 's :slight_smile:

You are required to set some project info. This can be done manually or with AutoGist.setProjectInfo(). There are two fields that are required. “Project” = “Your Exact Project Name” and “Version” = “current version number”

Then you call AutoGist.backup() with no params it will create a new Gist id for the project and save it as private. It can take 2 parameters. The first can be true to make it a Public Gist and the second can be a Gist ID of a currently existing gist.

You will need to create a github account and get an Authentication key. I Save this key as local data so itcan not be accidently gisted for the world to see.

Make sure to grab all 3 files
AutoGist on GitHub: https://gist.github.com/briarfox/5525674

GitHub token tutorial - https://help.github.com/articles/creating-an-oauth-token-for-command-line-use

main.lua

-- AutoGist
VERSION = 1.05 -- Use this to set Version Numbers

function setup()  
AutoGist.setProjectInfo("AutoGist","Briarfox","Auto Gists your Project",VERSION) --sets Project Info
AutoGist.backup() -- Add this to make backups 
end

This is what I used to get and set the GitHub Token

--   curl https://api.github.com/authorizations \\
--   --user "username" \\
--   --data '{"scopes":["gist"],"note":"Codea Gister"}'

saveGlobalData("Auth_Gist_Token", PLACE_TOKEN_HERE) -- run this one in any projectthen delete it. you do not want to give this token out.
-------------
Version Notes
-------------
Version 1.13
-Automatically Generate Gist Descriptions for Release and Build
-Release shows project name, version and the description found in projectInfo("Description")
-Build shows project name, Version number and build number

Version 1.12 
-You now have the ability to create a build gist and a release gist. 
-Option to create a new gist for build after the version number has been changed
-This is toggled in Gist.lua local newGistBuildWithVersion = true/false
-When you create a new gist, the gist will open in safari. I recommend naming the gist project Build/Release. I add the version number to the build gist so I can keep them separate
-Json library updated to 2.3

Version 1.07 
-Adds back in the ability to retrieve Gists by @acp simply create a blank project then open AutoGist and add the project name and the Gist ID from the url. Warning: This will write over the project you specify.

Version 1.06. 
-Had an issue with Public vs private gist ID's

looking forward to trying this

@Briarfox - sorry, but the process of getting a token isn’t at all clear. That link you provided doesn’t show how to do it, or how you actually use OAuth with github. It shows what looks like a console screen with lots of stuff on it, but no clue how to get to that.

I’d like to provide a step by step explanation so that anyone can use it (starting with me), so I need it in kindergarten language if possible. I understand most web stuff but I haven’t come across this before.

So - I have a github account. What exactly do I do, next?

@Ignatz unfortunatly I have a habbit of learning and figuring things out really fast, downside is that i do not retain the knowledgeonce i figure it out. If I recall correctly Github is for Git version control. So you need a console to get the git auth key. Mac uses terminal but I believe I used the terminal in Git Bash in windows. Its free and I believe thats what I used. I typed in what I posted in the first post and it returned a key. You can paste the ket into your project and call it directly but thats dangerous. If anyone else gets it they can access your gists. so store it in codeas global data. please let me know if you figure it out. I am new to this command line stuff. But I managed to hack it together using google. I’ll see if I can replicate it when I get on my windows or mac box. I’m hoping some of the guys on here that know how O Auth works can chime in.

btw feel free to re write any of this as you see fit. I just wrote this to make my life easier and I’m sure it can be done much better.

I’d like your feedback on an idea I have for this. I noticed that when working on this I would gist a lot to track my changed. however I don’t think this is a good idea if its being used in a project that other people are pulling from gist. I’m thinking of having Auto gist create two separate gists. One for builds that only the developer would see and a release version that the link would be shared to. What do you thing?

I’ll have another go

i think your idea of a release version gist is a good one

Updated it to allow for a release and build gist. Also @Ignatz If you haven’t already check out the Json Library. Its great for encoding and decoding tables.

@Ignatz Ok I just did it in Terminal

type curl https://api.github.com/authorizations \
Enter
type --user “Username Here” \
Enter
type --data ‘{“scopes”:[“gist”],“note”:"Name of Auth Here I used Codea AutoGist "}’
Enter
Password Prompt
Enter
Copy the Token

This can be used to access all of github including Gist.

I am following your discussion with great interest. When you’ll be all set i’ll give it a try. Please keep making things work better and simpler, thanks.

@jmv38 Thanks :slight_smile: I think I’m going to let it sit for a little bit. I’m happy with where it is at. Auto Gist now has the option to create a Release Gist according to Version numbers and a Builds gist to track smaller internal changes. There is an option to create a new Build gist with every Version push. I found that I liked the changes for all the builds in relation to a version to be separate. This can be toggled in Gist.lua.

I’m going to dive a little deeper and see what other information I can submit to gist. I’d like to automatically add the gist info. After that I’m going to see about making AutoGit to pull and push individual files onto github from within a project.

I’m primarily interested in quickly making a backup in case I do something really stupid. I use the “press on the project icon and Copy” feature and then paste into email to myself. This works even on my stupid days, when it’s most important!

But gisting does look like something that would be very helpful on other days. Thanks for the info.

@Ceres No problem :slight_smile: I use to backup with the method you stated but changing a version number made it so much quicker for me. I may actually backup more then needed. I really messed up another application I was working on, it was nice to just grab an old build instead of trying to figure out what I messed up.

I finally took the time to read through the github api so I do not need to rely on @acp 's code as much as I was.

New update will automatically name your gists and update the version and build numbers to keep them straight.

I’m going to spend some time cleaning the code up because its super sloppy. Then I’m going to work on AutoGit to use Github which should be better for larger projects.