Package: simplygithub
A simple tool for working with Github remotely. The basic interface is minimal.
WithSimply Github, you can:Create and delete branches.Add or remove files from a branch.Merge branches.ProfilesPretty much everySimply Githubfunction needs a profile as its first
argument. A profile providesSimply Githubwith two pieces of information.
It tellsSimply Github:Therepoit should connect to.Thetokenit should connect with.Therepois the name of a repo in the standard git form of:owner/:repo– for instance,jtpaasch/simplygithub.Thetokenis a valid personal access token, which you can create from
your Github account, under account settings. Seehttps://help.github.com/articles/creating-an-access-token-for-command-line-useTo generate a profile to use just during a coding session, import thesimplygithub.authentication.profilepackage and use theephemeral_profile()function. For example:from simplygithub.authentication import profile

my_profile = profile.ephemeral_profile(repo="jtpaasch/simplygithub",
                                       token="a3ef21ac0f...")You can then usemy_profilefor any of theSimply Githubfunctions
that need a profile.An ephemeral profile only lasts for the coding session though. It disappears
when themy_profilevariable disappears. If you want to store a profile
in a config file, use thewrite_profile()function.That function takes the aforementionedrepoandtokenarguments, but
you also need to give the profile a name so you can retrieve it later.This creates the same profile as above, but names itdefault:from simplygithub.authentication import profile

my_profile = profile.write_profile(name="default",
                                   repo="jtpaasch/simplygithub",
                                   token="a3ef21ac0f...")That will save the profile in a file at~/.profile/simplygithub/github.
(You can also create/modify this file yourself, by hand.)You can load the profile anytime later with theread_profile()function:from simplygithub.authentication import profile

my_profile = profile.read_profile("default")Once you have a profile loaded into a variable (likemy_profile), you can
use it for any of theSimply Githubfunctions that requires a profile as
their first argument.Creating branchesUse thesimplygithub.branchespackage to work with branches:from simplygithub import branchesTo see a list of all your branches (usingmy_profilefrom above):branches.list_branches(my_profile)To create a branch off of master:branches.create_branch(my_profile, "feature-branch", branch_off="master")To merge a feature branch into master:branches.merge(my_profile, "feature-branch", merge_into="master")To delete a branch:branches.delete_branch(my_profile, "feature-branch")Adding and removing files from a branchUse thesimplygithub.filespackage to work with files:from simplygithub import filesTo list all file objects in a branch (usingmy_profilefrom above):files.list_files(my_profile, "feature-branch")To get the (UTF-8 encoded) contents of a file on a branch:files.get_file(my_profile,
               branch="feature-branch",
               file_path="folder/path/foo.py")To add a file to a branch:files.add_file(my_profile,
               branch="feature-branch",
               file_path="folder/path/foo.py",
               file_contents="This is a silly file.")That will add a file atfolder/path/foo.py, and give it the contentsThis is a silly file.. It will commit that into thefeature-branch.If the file is an executable, addis_executable=Trueas a parameter. If
you want to provide a commit message, you do that with thecommit_messageparameter:files.add_file(my_profile,
               branch="feature-branch",
               file_path="folder/path/foo.py",
               file_contents="This is a silly file.",
               is_executable=True,
               commit_message="Added a silly file.")To delete a file from a branch:files.remove_file(my_profile,
                  branch="feature-branch",
                  file_path="folder/path/foo.py")That will remove the file from the branch and commit the change. You can add
an optionalcommit_messageparameter if you like:files.remove_file(my_profile,
                  branch="feature-branch",
                  file_path="folder/path/foo.py",
                  commit_message="Removed a silly file.")