Skip to content

Commit

Permalink
Finished v3.0.0 - 100% code coverage, better docs, new features, bug …
Browse files Browse the repository at this point in the history
…fixes
  • Loading branch information
Justintime50 committed Oct 1, 2020
1 parent 39d14f9 commit e158712
Show file tree
Hide file tree
Showing 19 changed files with 866 additions and 491 deletions.
6 changes: 4 additions & 2 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
[report]
exclude_lines =
if __name__ == '__main__':
main()
GitHubArchiveCLI()
CLI()

[run]
omit = github_archive/cli.py
2 changes: 2 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[flake8]
max-line-length=120
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ install:

script:
- shellcheck legacy/github-archive.sh
- flake8 githubarchive/*.py
- flake8 github_archive/*.py
- flake8 test/*.py
- pytest --cov=githubarchive
- pytest --cov=github_archive

deploy:
provider: pypi
Expand Down
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# CHANGELOG

## 3.0.0 (2020-10-01)

* Refactored the entire codebase to be more pythonic, simpler, DRY, and documented (closes #15)
* Better error handling by raising errors where applicable and switching from a homegrown logger to the built-in Python logger (closes #12)
* Added unit tests and test coverage (closes #14)
* Added various additional configuration options
* Automated releasing on PyPi via Travis
* Various bug fixes throughout
* Better documentation on exactly what is possible with this tool
* Added a Makefile
* Adjusted most of the command and option names to be more uniform and explicit

## 2.1.2 (2020-8-14)

* Fixed the script's entrypoint (PyPi installs work again)
Expand Down
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,15 @@ clean:

## lint - Lint the project
lint:
venv/bin/flake8 githubarchive/*.py
venv/bin/flake8 github_archive/*.py
venv/bin/flake8 test/*.py

## test - Test the project
test:
venv/bin/pytest

.PHONY: help install clean lint test
## coverage - Test the project and generate an HTML coverage report
coverage:
venv/bin/pytest --cov=github_archive --cov-branch --cov-report=html

.PHONY: help install clean lint test coverage
96 changes: 53 additions & 43 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,45 @@ A powerful script to concurrently clone your entire GitHub instance or save it a
[![Build Status](https://travis-ci.com/Justintime50/github-archive.svg?branch=master)](https://travis-ci.com/Justintime50/github-archive)
[![Coverage Status](https://coveralls.io/repos/github/Justintime50/github-archive/badge.svg?branch=master)](https://coveralls.io/github/Justintime50/github-archive?branch=master)
[![PyPi](https://img.shields.io/pypi/v/github-archive)](https://pypi.org/project/github-archive)
[![Licence](https://img.shields.io/github/license/justintime50/GitHub-archive)](https://opensource.org/licenses/mit-license.php)
[![Licence](https://img.shields.io/github/license/justintime50/GitHub-archive)](LICENSE)

<img src="assets/showcase.gif" alt="Showcase">
<img src="assets/showcase.png" alt="Showcase">

</div>

GitHub Archive will clone any repo and gist that doesn't exist locally and pull those that do from your desired branch of each repo and latest revision of each gist that you have access to - including organizations (if configured).

## What Can it Do?

- Clone/pull personal repos (public and private)
- Clone/pull organization repos (public and private)
- Clone/pull personal gists (public and private)
- Iterate over infinite number of repos and gists concurrently
- Great use case: Run on a schedule to automate pulling changes or keep a local backup of all your repos
* Clone/pull personal repos (public and private)
* Clone/pull organization repos (public and private)
* Clone/pull personal gists (public and private)
* Iterate over infinite number of repos and gists concurrently
* Great use case: Run on a schedule to automate pulling changes or keep a local backup of all your repos

### Configurable Settings

The power of GitHub Archive comes in its configuration. Maybe you only want to clone/pull your personal public repos or maybe you want to go all out and include private repos from you and all organizations you belong to including your gists. Iterate over all your repos concurrently and sit back while GitHub Archive does the work.

- Personal repos (on/off)
- Organization repos (on/off)
- Personal Gists (on/off)
- Cloning (on/off)
- Pulling (on/off)
- What organizations you'd like included
- GitHub Archive location
- Which branch to clone/pull from
* Personal repos cloning/pulling
* Organization repos cloning/pulling
* Personal Gists cloning/pulling
* List of organizations to include
* Which branch to clone/pull from
* A host of environment variables to tweak GitHub Archive even further to meet your needs

## Install

```bash
# Install tool
pip3 install github-archive
```

**For Private Repos:** You must have an SSH key generated on your local machine and added to your GitHub account as this tool uses the `ssh_url` to clone/pull.
# Install locally
make install

# Get Makefile help
make help
```

### Automating SSH Passphrase Prompt (Recommended)

Expand All @@ -53,50 +58,55 @@ ssh-add

## Usage

GitHub Archive will clone any repo and gist that doesn't exist locally and pull those that do from the master branch of each repo and latest revision of each gist that you have access to - including organizations (if configured). **Merge Conflicts:** *Be aware that using GitHub Archive could lead to merge conflicts if you do not commit or stash your changes if using these repos as active development repos instead of simply an archive or one-time clone.*
**SSH Key:** You must have an SSH key generated on your local machine and added to your GitHub account as this tool uses the `ssh_url` to clone/pull.

By default, you only need to specify your GitHub token and GitHub Archive will clone/pull your personal repos for you. See below for customization options.
**Merge Conflicts:** *Be aware that using GitHub Archive could lead to merge conflicts if you do not commit or stash your changes if using these repos as active development repos instead of simply an archive or one-time clone.*

```
Basic Usage:
GITHUB_TOKEN=123... github_archive --user-clone --user-pull
GITHUB_TOKEN=123... github-archive --user-clone --user-pull
Advanced Usage:
GITHUB_TOKEN=123... GITHUB_ARCHIVE_ORGS="org1, org2" GITHUB_ARCHIVE_LOCATION="~/custom_location" \
github-archive -uc -up -gc -gp -oc -op -b develop
Options:
-uc, --user-clone Clone personal repos (default: on)
-up, --user-pull Pull personal repos (default: on)
-gc, --gists-clone Clone personal gists (default: off)
-gp, --gists-pull Pull personal gists (default: off)
-oc, --orgs-clone Clone organization repos (default: off)
-op, --orgs-pull Pull organization repos (defaulf: off)
-b, --branch The branch to clone/pull from (default "master")
-h, --help Show usage info on for this tool
Environment variables
GITHUB_ARCHIVE_TOKEN - expects a string
GITHUB_ARCHIVE_ORGS - expects a string of comma separated orgs. eg: "org1, org2"
GITHUB_ARCHIVE_LOCATION - expects a string of an explicit location on your machine. eg: "~/custom_location"
-h, --help show this help message and exit
-uc, --user_clone Clone personal repos.
-up, --user_pull Pull personal repos
-gc, --gists_clone Clone personal gists
-gp, --gists_pull Pull personal gists.
-oc, --orgs_clone Clone organization repos.
-op, --orgs_pull Pull organization repos.
-b BRANCH, --branch BRANCH
Which branch to pull from.
Environment Variables
GITHUB_TOKEN expects a string of your GitHub Token
GITHUB_ARCHIVE_ORGS expects a string of comma separated orgs. eg: "org1, org2"
GITHUB_ARCHIVE_LOCATION expects a string of an explicit location on your machine (eg: "~/custom_location"). Default: ~/github-archive
GITHUB_ARCHIVE_BUFFER expects a float for the buffer inbetween requests. Default: 0.1
GITHUB_ARCHIVE_TIMEOUT expects an int for the number of seconds before a git operation times out. Default: 180
GITHUB_ARCHIVE_LOG_MAX_BYTES expects an int of the max bytes that a log will grow to. Once the log exceeds this number, it will rollover to another log. Default: 200000
GITHUB_ARCHIVE_LOG_BACKUP_COUNT expects an int of the number of logs to rollover once a single log exceeds the max bytes size. Default: 5
```

## Development

Install project with dev depencencies:

```bash
pip3 install -e ."[dev]"
```
# Lint the project
make lint

Lint the project:
# Run tests
make test

```bash
pylint githubarchive/*.py
# Run test coverage
make coverage

# Run the tool locally
venv/bin/python github_archive/cli.py --help
```

## Legacy Script

GitHub Archive was initially built with Bash partly because I was into shell scripting at the time and partly because I wanted to keep the script as dependency free as possible. Even still, the Bash script depended on Python. As Python will soon be removed from macOS by default, I decided to rewrite the script in pure Python for two reasons - 1) Once Python is no longer built-in, users would need to install Python anyway making the pure Bash script broken out of the box and 2) Rewriting allowed me to take full advantage of the power of Python. One large benefit of doing this was adding concurrency which is great for users with dozens or hundreds of repos across various organizations. Additional logging and stability improvements were also made.

If you'd like to use or view the legacy script, check out the `src/legacy` folder.
This tool was initially built in Bash and later re-written in Python. If you'd like to use or view the legacy script, check out the separate [Legacy README](legacy/README.md).
Binary file removed assets/showcase.gif
Binary file not shown.
Binary file added assets/showcase.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions github_archive/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# flake8: noqa
from github_archive.archive import GithubArchive
from github_archive.logger import Logger

0 comments on commit e158712

Please sign in to comment.