This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
mrdawgza's profile picture

Downloading files off GitHub (and how to use a repo)

Started by mrdawgza, 16 December 2013 - 02:29 PM
mrdawgza #1
Posted 16 December 2013 - 03:29 PM
This tutorial will show you how to make a github repository and download the files into your computer.
it's my first tutorial so…

Step One
You shall be needing a GitHub repository - head to www.github.com and create an account.
Then you should create a new repository.
The name can be anything, Tungsten OS or such anything!
And the description is optional.
You don't need the .gitignore and license features yet since you haven't really made Tungsten OS proper yet. It is still under development.

Step Two
With a GitHub repository located at www.github.com/youname/theRepositoryName you can continue on here.
Now I have a nifty little program called (not mine) SourceTree which you can get here.

Setting up SourceTree
SpoilerNow once it's installed you need to set it up.

Step One
The first screen just needs you to put in your full name and email address (I used the one associated with GitHub)
Make sure you have all of the boxes ticked and agree to the license.

Step Two
The next screen is about SSH Client, click Use OpenSSH and click next.

Step Three
Now you must enter your GitHub user informations, such as your username and password.
Click finish.

Step Four
Now since SourceTree is setup - it's time to clone a repository.
Click the Clone/New button, you will have a window with 3 tabs, make sure you are on the Clone Repository tab.
You will the the field SourcePath/URL; look to the right of it and you'll see an icon of the world (a button), click it.
This will list all your repositories on the account.
Select the repository in that screen and click OK to go back to the window with three tabs.
The next field; Destination Path; is where the repository is managed on your computer.
So click the three dots next to the field and locate where you wish to save the repository. (For instance, I am using /c/users/me/documents/github/repo)
Do not make this your computer folder
Leave the folder to [Root].
Click the Clone button.

Step Five
Head into the folder you set as the destination path, and paste your programs or computer layout in there. (For instance, I'll put my OSes files in C:/users/me/documents/github/osros/)
Once you've done that head back into SourceTree and in the block 'Working Copy Changes' you will see all the files you've copied.
Click on one of the files in the block and hit CRTL+A to select all, then hit the Add button at the top. You will see those move to the Staged Changes.

Step Six
Click the Commit button next to the Clone/New button and write a nice little message to say why you're uploading the files.
Once you've done that click the Commit button.

Step Seven
Hit the Push button, in the same row as Add.
This will upload the files in your destination folder with the commit you wrote to your URL. Now if you go to www.github.com/yourUsername/repo and you should see all the files you put in the
destination folder.

That is SourceTree setup - When you wish to update the files just overwrite them in the destination folder and add them to the Staged Changes in SourceTree with a nice commit then Push them up.
They will change on GitHub.

The Installer

Note: You need the HTTP API enabled for this to work!
How to enable the HTTP API
SpoilerTo enable the HTTP API you need to head to the ComputerCraft Config in your Minecraft or modpack (computercraft.cfg). If you cannot find this, make sure you are in the right
directory, and if still not; search for computercraft.cfg. Now when you try and open that file, Windows will ask what do you want to do, click Search for Program to run with, and choose Notepad.
Once in; look for B:enableAPI_http=false and change the false to true.


Now, the file we shall be downloading is called 'startup', located at www.github.com/myName/repo/startup .
If you try to download that into ComputerCraft it'll show you all of the HTML details, which is useless - so we need the raw file which is found at
https://raw.github.com/me/repo/startup .
That is what we shall download.

So now to get, read and save 'startup' off GitHub, we shall use the code:

local download = http.get("https://raw.github.com/myName/repo/startup") --This will make 'download' hold the contents of the file.
local handle = download.readAll() --Reads everything in download
download.close() --remember to close download!

local file = fs.open("startup","w") --opens the file 'startup' with the permissions to write.
file.write(handle) --writes all the stuff in handle to the file 'startup'.
file.close() --remember to close download!
That is basically it!

Now putting that code in for each file is a mission, so you can put it into a local function: (in the installer)
This code will make sure it downloaded it, else if it didn't the installer will return false with an error message.

local function get(repoFile,saveTo)
local download = http.get("https://raw.github.com/myName/repo/repoFile") --This will make 'download' hold the contents of the file.
if download then --checks if download returned true or false
   local handle = download.readAll() --Reads everything in download
   download.close() --remember to close the download!
   local file = fs.open(saveTo,"w") --opens the file defined in 'saveTo' with the permissions to write.
   file.write(handle) --writes all the stuff in handle to the file defined in 'saveTo'
   file.close() --remember to close the file!
  else --if returned false
   print("Unable to download the file "..repoFile)
   print("Make sure you have the HTTP API enabled or")
   print("an internet connection!")
  end --end the if
end --close the function
Now call this function with:

get("startup","startup") --remember the quotation marks! (" ")

That is basically it for an advanced installer of GitHub. That is exactly what the pastebin get program does, it just doesn't run with a function and has the URL www.pastebin.com/raw?i= (or whatever)
and saves the raw.

If you need any questions just ask me. ALSO if the code I posted errors just tell me - I posted it without testing…
Edited on 07 July 2014 - 09:19 AM
Lyqyd #2
Posted 16 December 2013 - 05:05 PM
Why SourceTree and not git itself, or the git bash for Windows? Git is a pretty powerful tool, and you'd be better off knowing how to use it directly than tying yourself down to some GUI app.
theoriginalbit #3
Posted 16 December 2013 - 06:22 PM
I can definitely confirm what Lyqyd is saying… I started out with with the GUI app, and was apprehensive to switch to command line, but NeverCast managed to convince me and I love him for it. Its much more powerful, and you end up just having much better control over your repos.
distantcam #4
Posted 16 December 2013 - 06:48 PM
I'd also mention GitHub for Mac and Windows.

And as far as using the command line goes on Windows, installing SourceTree or GitHub for Windows is the easiest way to get the Git command line installed. Both provide access when you need to step outside the GUI.
theoriginalbit #5
Posted 16 December 2013 - 06:57 PM
I'd also mention GitHub for Mac and Windows.
SourceTree is better than the GitHub GUI.
mrdawgza #6
Posted 17 December 2013 - 08:11 AM
Why SourceTree and not git itself, or the git bash for Windows? Git is a pretty powerful tool, and you'd be better off knowing how to use it directly than tying yourself down to some GUI app.

I sorta made this tutorial for someone new to GitHub and Git - So using a GUI would make it easier for them to understand.
oeed #7
Posted 17 December 2013 - 04:55 PM
Why SourceTree and not git itself, or the git bash for Windows? Git is a pretty powerful tool, and you'd be better off knowing how to use it directly than tying yourself down to some GUI app.

I sorta made this tutorial for someone new to GitHub and Git - So using a GUI would make it easier for them to understand.

I completely agree. Someone starting off with GitHub won't want to spend ages learning how to use the command line, they may decide to use it later on, but initially for the tasks they're doing it's probably not worth learning until they have a basic grasp on the idea. You have to learn to walk before you can run.
awsmazinggenius #8
Posted 17 December 2013 - 08:39 PM
Why SourceTree and not git itself, or the git bash for Windows? Git is a pretty powerful tool, and you'd be better off knowing how to use it directly than tying yourself down to some GUI app.

I sorta made this tutorial for someone new to GitHub and Git - So using a GUI would make it easier for them to understand.

I completely agree. Someone starting off with GitHub won't want to spend ages learning how to use the command line, they may decide to use it later on, but initially for the tasks they're doing it's probably not worth learning until they have a basic grasp on the idea. You have to learn to walk before you can run.
Agreed. I always used the GitHub web editor (copy-pasting from my editor) until the first time I needed to get a .png into a repo. Then I switched to the command line. Also, for getting files from GitHub into CC, I have always used raw.github.com . I'm not entirely sure that's the best way, though.
Lemur #9
Posted 22 December 2013 - 11:45 PM
If you intend to get into the Software world at all, learning Git is a requirement for most places. It would be advantageous to learn it, and honestly the command line will be a lot faster for you on that one.

As one of the most nightmarish things is undoing whatever bork in a repo you just made, this is bookmark worthy: http://sethrobertson.github.io/GitFixUm/fixup.html

In terms of API it would be worthwhile to note that effectively all you're doing is grabbing the raw (text) version of the file from Github. As to how to get all the files in there from a repo, I'd have to think about it. That would definitely be a beneficial feature, some form of functioning Git API Facade in Lua.

http://developer.github.com/v3/repos/contents/

This looks promising as to a source for getting everything. If there's some form of JSON parser in Lua we could make it automatically fetch everything in a directory and effectively download everything you need in one go. Considering the API is HTTP Rest based, you just need to shoot it a get request to get the data you need to get the rest of the library.

Anyone up for trying to make a Git Facade for pulling down a whole repo? My Lua skills are less than par at this point, so I'm not sure what types of features it'd have for this. I'll do a bit of research and see what I can find out on it.

I suppose the question I'd need answered is can we parse JSON in CC? I'd rather not make a custom JSON parser unless absolutely necessary.
awsmazinggenius #10
Posted 23 December 2013 - 09:20 AM
I suppose the question I'd need answered is can we parse JSON in CC? I'd rather not make a custom JSON parser unless absolutely necessary.
I just downloaded JSON4Lua from LuaForge - I am translating it into CC Lua. If you'd like, I can PM you when done. (I don't plan on a release of it specifically (though it is MIT, I could if I wanted), but it's really useful to have in awsmazingOS.
Edited on 23 December 2013 - 08:21 AM
Lemur #11
Posted 24 December 2013 - 12:21 AM
Is there a definitive guide on the differences? I come from Ruby but I could easily pick up Lua in any capacity for things like this. Ping me out and around if you have any projects on getting something like this done.

Why not just OS is on Github?
distantcam #12
Posted 24 December 2013 - 01:34 AM
This JSON parser from ElvishJerricco worked well for me.

http://www.computercraft.info/forums2/index.php?/topic/5854-json-api-v201-for-computercraft/
SpencerBeige #13
Posted 24 June 2014 - 04:24 AM
thanks! this is great because now, i can make better installation files, this is great!
by the way, it says that my access is denied, how do i make it so i can access a website with https?
Edited on 24 June 2014 - 03:05 AM
skwerlman #14
Posted 25 June 2014 - 03:52 AM
by the way, it says that my access is denied, how do i make it so i can access a website with https?
In the computercraft config, there's a whitelist for the http api. If you set it to '*' (without quotes) it will allow access to all sites.
mrdawgza #15
Posted 25 June 2014 - 12:16 PM
thanks! this is great because now, i can make better installation files, this is great!
by the way, it says that my access is denied, how do i make it so i can access a website with https?

The answer;
by the way, it says that my access is denied, how do i make it so i can access a website with https?
In the computercraft config, there's a whitelist for the http api. If you set it to '*' (without quotes) it will allow access to all sites.

however if you are playing on a server and cannot access the Computercraft config file simply ask the server manager/owner if he could change it for you.
In modpacks (like direwolf20) I think it is enabled on default.
Edited on 25 June 2014 - 10:16 AM
Agoldfish #16
Posted 29 June 2014 - 12:58 AM
Now time to teach how to download branches. :P/>
skwerlman #17
Posted 29 June 2014 - 07:01 PM
Now time to teach how to download branches. :P/>
Or from release tags. (This'd be really useful actually, now that I think about it…)
Or from specific commits.
Agoldfish #18
Posted 29 June 2014 - 07:09 PM
Now time to teach how to download branches. :P/>
Or from release tags. (This'd be really useful actually, now that I think about it…)
Or from specific commits.
Now time to teach how to download branches. :P/>
Or from release tags. (This'd be really useful actually, now that I think about it…)
Or from specific commits.
Yeah, I'll have to look into that. :P/>