├── tests ├── __init__.py └── test_trytravis.py ├── setup.cfg ├── README.md ├── MANIFEST.in ├── .travis ├── script.sh └── install.sh ├── .coveragerc ├── BACKERS.md ├── CONTRIBUTING.md ├── tox.ini ├── .appveyor.yml ├── .travis.yml ├── .gitignore ├── CHANGELOG.md ├── setup.py ├── CODE_OF_CONDUCT.md ├── LICENSE └── trytravis.py /tests/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [bdist_wheel] 2 | universal = 1 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # DO NOT USE 2 | 3 | This package is no longer maintained. Do not use it. 4 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include *.md 2 | include *.txt 3 | include *.ini 4 | include LICENSE 5 | include .coveragerc 6 | recursive-include tests *.py 7 | -------------------------------------------------------------------------------- /.travis/script.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | set -x 5 | 6 | if [[ "$(uname -s)" == "Darwin" ]]; then 7 | PYENV_ROOT="$HOME/.pyenv" 8 | PATH="$PYENV_ROOT/bin:$PATH" 9 | eval "$(pyenv init -)" 10 | fi 11 | 12 | tox 13 | -------------------------------------------------------------------------------- /.coveragerc: -------------------------------------------------------------------------------- 1 | [run] 2 | include = 3 | trytravis.py 4 | 5 | [report] 6 | exclude_lines = 7 | except ImportError: 8 | pass 9 | return NotImplemented 10 | def __repr__(self): 11 | def __str__(self): 12 | pragma: no coverage 13 | -------------------------------------------------------------------------------- /BACKERS.md: -------------------------------------------------------------------------------- 1 | # Backers on BountySource 2 | 3 | All users contributing at least $5.00 or more on [BountySource Salt](https://salt.bountysource.com/teams/trytravis) 4 | will be listed here. You can donate as much or as little as you like, we're very greatful for the opportunity to 5 | create software to help everyone. 6 | 7 | - [@eeeebbbbrrrr](https://github.com/eeeebbbbrrrr) 8 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing Guidelines 2 | 3 | Simple steps to make contributing to this project as smooth as possible: 4 | 5 | - Read, understand, and abide by our [`CODE_OF_CONDUCT.md`](https://github.com/SethMichaelLarson/trytravis/blob/master/CODE_OF_CONDUCT.md). 6 | - Make sure to add all changes you make to [`CHANGELOG.md`](https://github.com/SethMichaelLarson/trytravis/blob/master/CHANGELOG.md) under the correct heading. 7 | - Test your changes before submitting a Pull Request by running `tox` in the project root. 8 | Or alternatively use `trytravis` for what it was made to do! ;) 9 | - Be patient with maintainers, we have jobs and lives outside of Open Source. 10 | We'll get to your issues and Pull Requests when we can. :) 11 | -------------------------------------------------------------------------------- /tox.ini: -------------------------------------------------------------------------------- 1 | [tox] 2 | envlist = lint, packaging, py27, py34, py35, py36, py37 3 | sitepackages=True 4 | 5 | [testenv] 6 | commands = 7 | python -m pip install -U pytest pytest-cov coverage mock 8 | python setup.py install 9 | pytest --cov trytravis tests/ 10 | coverage report -m 11 | coverage html 12 | 13 | [testenv:lint] 14 | commands = 15 | python -m pip install -U flake8 16 | flake8 trytravis.py setup.py 17 | 18 | [testenv:packaging] 19 | commands = 20 | python -m pip install -U check-manifest readme_renderer 21 | check-manifest --ignore *.yml,.appveyor*,.travis*,.github* 22 | python setup.py check --metadata --restructuredtext --strict 23 | 24 | [testenv:release] 25 | commands = 26 | python -m pip install -U twine 27 | python setup.py sdist bdist_wheel 28 | twine upload dist/* 29 | -------------------------------------------------------------------------------- /.appveyor.yml: -------------------------------------------------------------------------------- 1 | build: off 2 | 3 | environment: 4 | matrix: 5 | - PYTHON: "C:\\Python27-x64" 6 | PYTHON_VERSION: "2.7.x" 7 | PYTHON_ARCH: "64" 8 | TOXENV: "py27" 9 | 10 | - PYTHON: "C:\\Python34-x64" 11 | PYTHON_VERSION: "3.4.x" 12 | PYTHON_ARCH: "64" 13 | TOXENV: "py34" 14 | 15 | - PYTHON: "C:\\Python35-x64" 16 | PYTHON_VERSION: "3.5.x" 17 | PYTHON_ARCH: "64" 18 | TOXENV: "py35" 19 | 20 | - PYTHON: "C:\\Python36-x64" 21 | PYTHON_VERSION: "3.6.x" 22 | PYTHON_ARCH: "64" 23 | TOXENV: "py36" 24 | 25 | install: 26 | - "SET PATH=%PYTHON%;%PYTHON%\\Scripts;%PATH%" 27 | - "python --version" 28 | - "python -c \"import struct; print(struct.calcsize('P') * 8)\"" 29 | - "python -m pip install --disable-pip-version-check --user --upgrade pip" 30 | - "python -m pip install tox" 31 | 32 | test_script: 33 | - "tox" 34 | 35 | on_success: 36 | - ".tox\\%TOXENV%\\Scripts\\activate" 37 | - "python -m pip install codecov" 38 | - "codecov --env PLATFORM,TOXENV" 39 | -------------------------------------------------------------------------------- /.travis/install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | set -x 5 | 6 | if [[ "$(uname -s)" == 'Darwin' ]]; then 7 | # install pyenv 8 | git clone --depth 1 https://github.com/yyuu/pyenv.git ~/.pyenv 9 | PYENV_ROOT="$HOME/.pyenv" 10 | PATH="$PYENV_ROOT/bin:$PATH" 11 | eval "$(pyenv init -)" 12 | 13 | case "${TOXENV}" in 14 | py26) 15 | pyenv install 2.6.9 16 | pyenv global 2.6.9 17 | ;; 18 | py27) 19 | curl -O https://bootstrap.pypa.io/get-pip.py 20 | python get-pip.py --user 21 | ;; 22 | py33) 23 | pyenv install 3.3.6 24 | pyenv global 3.3.6 25 | ;; 26 | py34) 27 | pyenv install 3.4.5 28 | pyenv global 3.4.5 29 | ;; 30 | py35) 31 | pyenv install 3.5.2 32 | pyenv global 3.5.2 33 | ;; 34 | py36) 35 | pyenv install 3.6.0 36 | pyenv global 3.6.0 37 | ;; 38 | esac 39 | pyenv rehash 40 | pip install -U setuptools 41 | pip install --user virtualenv 42 | else 43 | pip install virtualenv 44 | fi 45 | 46 | pip install tox 47 | 48 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: python 2 | sudo: false 3 | 4 | matrix: 5 | include: 6 | # Linting 7 | - python: 2.7 8 | env: TOXENV=lint 9 | 10 | - python: 3.6 11 | env: TOXENV=lint 12 | 13 | # Packaging 14 | - python: 3.6 15 | env: TOXENV=packaging 16 | 17 | # Linux Builds 18 | - python: 2.7 19 | env: TOXENV=py27 20 | 21 | - python: 3.4 22 | env: TOXENV=py34 23 | 24 | - python: 3.5 25 | env: TOXENV=py35 26 | 27 | - python: 3.6 28 | env: TOXENV=py36 29 | 30 | - python: nightly 31 | env: TOXENV=py37 32 | 33 | # Mac OS Builds 34 | - os: osx 35 | language: generic 36 | env: TOXENV=py27 37 | 38 | - os: osx 39 | language: generic 40 | env: TOXENV=py34 41 | 42 | - os: osx 43 | language: generic 44 | env: TOXENV=py35 45 | 46 | - os: osx 47 | language: generic 48 | env: TOXENV=py36 49 | 50 | - os: osx 51 | language: generic 52 | env: TOXENV=py37 53 | 54 | allow_failure: 55 | - python: nightly 56 | 57 | cache: 58 | - pip 59 | - directories: 60 | - ${HOME}/.cache 61 | 62 | install: 63 | - chmod a+x .travis/install.sh .travis/script.sh 64 | - ./.travis/install.sh 65 | 66 | script: 67 | - ./.travis/script.sh 68 | 69 | after_success: 70 | - source .tox/${TOXENV}/bin/activate 71 | - python -m pip install codecov 72 | - codecov --env TRAVIS_OS_NAME,TOXENV 73 | 74 | notifications: 75 | email: false 76 | 77 | branches: 78 | only: 79 | - master 80 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | env/ 12 | build/ 13 | develop-eggs/ 14 | dist/ 15 | downloads/ 16 | eggs/ 17 | .eggs/ 18 | lib/ 19 | lib64/ 20 | parts/ 21 | sdist/ 22 | var/ 23 | wheels/ 24 | *.egg-info/ 25 | .installed.cfg 26 | *.egg 27 | 28 | # PyInstaller 29 | # Usually these files are written by a python script from a template 30 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 31 | *.manifest 32 | *.spec 33 | 34 | # Installer logs 35 | pip-log.txt 36 | pip-delete-this-directory.txt 37 | 38 | # Unit test / coverage reports 39 | htmlcov/ 40 | .tox/ 41 | .coverage 42 | .coverage.* 43 | .cache 44 | nosetests.xml 45 | coverage.xml 46 | *.cover 47 | .hypothesis/ 48 | 49 | # Translations 50 | *.mo 51 | *.pot 52 | 53 | # Django stuff: 54 | *.log 55 | local_settings.py 56 | 57 | # Flask stuff: 58 | instance/ 59 | .webassets-cache 60 | 61 | # Scrapy stuff: 62 | .scrapy 63 | 64 | # Sphinx documentation 65 | docs/_build/ 66 | 67 | # PyBuilder 68 | target/ 69 | 70 | # Jupyter Notebook 71 | .ipynb_checkpoints 72 | 73 | # pyenv 74 | .python-version 75 | 76 | # celery beat schedule file 77 | celerybeat-schedule 78 | 79 | # SageMath parsed files 80 | *.sage.py 81 | 82 | # dotenv 83 | .env 84 | 85 | # virtualenv 86 | .venv 87 | venv/ 88 | ENV/ 89 | 90 | # Spyder project settings 91 | .spyderproject 92 | .spyproject 93 | 94 | # Rope project settings 95 | .ropeproject 96 | 97 | # mkdocs documentation 98 | /site 99 | 100 | # mypy 101 | .mypy_cache/ 102 | 103 | # PyCharm 104 | .idea/ 105 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | 7 | 8 | # Changelog 9 | 10 | All notable changes to trytravis will be documented in this file. 11 | 12 | The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) 13 | and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). 14 | 15 | ## Unreleased 16 | 17 | ### Added 18 | 19 | - Output Travis URL and stop. #17 Reported by @miguelbalparda 20 | 21 | ## 1.0.4 22 | 23 | ### Fixed 24 | 25 | - Issue where `committed_at` would not be normalized to UTC. #18 Reported by @einball 26 | 27 | ## 1.0.3 28 | 29 | ### Changed 30 | 31 | - Can no longer use a repository without containing the name `trytravis`. 32 | This is to prevent accidentally using a repository the user didn't intend 33 | to call with `git push -f`. 34 | 35 | ## 1.0.2 36 | 37 | ### Fixed 38 | 39 | - Issue where if `env` isn't defined in `.travis.yml` then the 40 | script will error out with `KeyError`. #12 Reported by @eeeebbbbrrrr. 41 | 42 | ## 1.0.1 43 | 44 | ### Added 45 | 46 | - Better message when running from a non-git repository. 47 | 48 | ### Fixed 49 | 50 | - When running multiple times with the same commit hash `trytravis` would sometimes 51 | find and watch the incorrect build. 52 | - `trytravis` would display an HTTPS URL even if an SSH URL was used in the output. 53 | 54 | ## 1.0.0 55 | 56 | ### Added 57 | 58 | - Added the ability to read your repository slug from the local config. 59 | - Added ability to add repository directly via command line with --repo option. 60 | - Added the main functionality to trigger and watch Travis builds. 61 | - Added ability to use `ssh://git@github.com/[USERNAME]/[REPOSITORY]` formatted remote urls. 62 | 63 | ### Changed 64 | 65 | - Flattened the structure of all functions. Adhered to PEP8. 66 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | import os 2 | from setuptools import setup 3 | 4 | # Get the directory that the setup.py script is in. 5 | base_dir = os.path.dirname(os.path.abspath(__file__)) 6 | 7 | # Gathering metadata for the package. 8 | about = {} 9 | with open(os.path.join(base_dir, 'trytravis.py')) as f: 10 | for line in f: 11 | if line.startswith('__'): 12 | exec(line, about) 13 | 14 | # Gather all install_requires values. 15 | install_requires = ['requests>=2.14.0', 16 | 'colorama>=0.3.9', 17 | 'GitPython>=2.1.5'] 18 | 19 | # Find all available classifiers at: 20 | # https://pypi.python.org/pypi?%3Aaction=list_classifiers 21 | classifiers = ['Development Status :: 3 - Alpha', 22 | 'Intended Audience :: Developers', 23 | 'License :: OSI Approved :: Apache Software License', 24 | 'Natural Language :: English', 25 | 'Operating System :: MacOS', 26 | 'Operating System :: Microsoft :: Windows', 27 | 'Operating System :: POSIX', 28 | 'Programming Language :: Python', 29 | 'Programming Language :: Python :: 2.7', 30 | 'Programming Language :: Python :: 3.4', 31 | 'Programming Language :: Python :: 3.5', 32 | 'Programming Language :: Python :: 3.6', 33 | 'Programming Language :: Python :: Implementation :: CPython', 34 | 'Topic :: Software Development :: Quality Assurance', 35 | 'Topic :: Software Development :: Testing'] 36 | 37 | # Run the setup() command to build the package. 38 | setup(name=about['__title__'], 39 | author=about['__author__'], 40 | author_email=about['__email__'], 41 | license=about['__license__'], 42 | version=about['__version__'], 43 | description=('Send local git changes to Travis CI ' 44 | 'without commits or pushes.'), 45 | url=about['__url__'], 46 | py_modules=['trytravis'], 47 | install_requires=install_requires, 48 | zip_safe=False, 49 | classifiers=classifiers, 50 | entry_points={'console_scripts': ['trytravis=trytravis:main']}, 51 | extras_require={':sys_platform=="win32"': ['pypiwin32>=214']}) 52 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. 6 | 7 | ## Our Standards 8 | 9 | Examples of behavior that contributes to creating a positive environment include: 10 | 11 | * Using welcoming and inclusive language 12 | * Being respectful of differing viewpoints and experiences 13 | * Gracefully accepting constructive criticism 14 | * Focusing on what is best for the community 15 | * Showing empathy towards other community members 16 | 17 | Examples of unacceptable behavior by participants include: 18 | 19 | * The use of sexualized language or imagery and unwelcome sexual attention or advances 20 | * Trolling, insulting/derogatory comments, and personal or political attacks 21 | * Public or private harassment 22 | * Publishing others' private information, such as a physical or electronic address, without explicit permission 23 | * Other conduct which could reasonably be considered inappropriate in a professional setting 24 | 25 | ## Our Responsibilities 26 | 27 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. 28 | 29 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. 30 | 31 | ## Scope 32 | 33 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. 34 | 35 | ## Enforcement 36 | 37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at sethmichaellarson@protonmail.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. 38 | 39 | Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. 40 | 41 | ## Attribution 42 | 43 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] 44 | 45 | [homepage]: http://contributor-covenant.org 46 | [version]: http://contributor-covenant.org/version/1/4/ 47 | -------------------------------------------------------------------------------- /tests/test_trytravis.py: -------------------------------------------------------------------------------- 1 | import os 2 | import trytravis 3 | import pytest 4 | import mock 5 | 6 | 7 | def test_help(): 8 | trytravis._main(['--help']) 9 | 10 | 11 | def test_too_many_parameters(): 12 | trytravis._main(['a', 'b', 'c']) 13 | 14 | 15 | def test_version(): 16 | assert trytravis.__version__ in trytravis._version_string() 17 | 18 | 19 | def test_repo_input(): 20 | with mock.patch('trytravis.user_input') as mock_input: 21 | mock_input.side_effect = ['https://www.github.com/testauthor/testname-trytravis', 'yes'] 22 | trytravis.config_dir = os.path.dirname(os.path.abspath(__file__)) 23 | 24 | trytravis._main(['--repo']) 25 | 26 | assert os.path.isfile(os.path.join(trytravis.config_dir, 'repo')) 27 | 28 | with open(os.path.join(trytravis.config_dir, 'repo'), 'r') as f: 29 | assert f.read() == 'https://www.github.com/testauthor/testname-trytravis' 30 | 31 | os.remove(os.path.join(trytravis.config_dir, 'repo')) 32 | 33 | 34 | def test_repo_command_line(): 35 | with mock.patch('trytravis.user_input') as mock_input: 36 | mock_input.side_effect = ['y'] 37 | trytravis.config_dir = os.path.dirname(os.path.abspath(__file__)) 38 | 39 | trytravis._main(['--repo', 'https://github.com/testauthor/testname-trytravis']) 40 | 41 | assert os.path.isfile(os.path.join(trytravis.config_dir, 'repo')) 42 | 43 | with open(os.path.join(trytravis.config_dir, 'repo'), 'r') as f: 44 | assert f.read() == 'https://github.com/testauthor/testname-trytravis' 45 | 46 | os.remove(os.path.join(trytravis.config_dir, 'repo')) 47 | 48 | 49 | def test_repo_ssh(): 50 | with mock.patch('trytravis.user_input') as mock_input: 51 | mock_input.side_effect = ['y'] 52 | trytravis.config_dir = os.path.dirname(os.path.abspath(__file__)) 53 | 54 | trytravis._main(['--repo', 'ssh://git@github.com/testauthor/testname-trytravis']) 55 | 56 | assert os.path.isfile(os.path.join(trytravis.config_dir, 'repo')) 57 | 58 | with open(os.path.join(trytravis.config_dir, 'repo'), 'r') as f: 59 | assert f.read() == 'ssh://git@github.com/testauthor/testname-trytravis' 60 | 61 | os.remove(os.path.join(trytravis.config_dir, 'repo')) 62 | 63 | 64 | def test_repo_cancel(): 65 | with pytest.raises(RuntimeError): 66 | with mock.patch('trytravis.user_input') as mock_input: 67 | mock_input.side_effect = ['https://www.github.com/testauthor/testname-trytravis', 'e'] 68 | trytravis.config_dir = os.path.dirname(os.path.abspath(__file__)) 69 | 70 | trytravis._main(['--repo']) 71 | 72 | assert not os.path.isfile(os.path.join(trytravis.config_dir, 'repo')) 73 | 74 | 75 | def test_repo_invalid_url(): 76 | with pytest.raises(RuntimeError): 77 | with mock.patch('trytravis.user_input') as mock_input: 78 | mock_input.side_effect = ['https://www.github.com/testauthor-trytravis', 'y'] 79 | trytravis.config_dir = os.path.dirname(os.path.abspath(__file__)) 80 | 81 | trytravis._main(['--repo']) 82 | 83 | assert not os.path.isfile(os.path.join(trytravis.config_dir, 'repo')) 84 | 85 | 86 | def test_repo_doesnt_contain_trytravis(): 87 | with pytest.raises(RuntimeError): 88 | with mock.patch('trytravis.user_input') as mock_input: 89 | mock_input.side_effect = ['https://github.com/trytravis-target'] 90 | trytravis.config_dir = os.path.dirname(os.path.abspath(__file__)) 91 | 92 | trytravis._main(['--repo']) 93 | assert not os.path.isfile(os.path.join(trytravis.config_dir, 'repo')) 94 | 95 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /trytravis.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2017 Seth Michael Larson 2 | # 3 | # This program is free software: you can redistribute it and/or modify 4 | # it under the terms of the GNU General Public License as published by 5 | # the Free Software Foundation, either version 3 of the License, or 6 | # (at your option) any later version. 7 | # 8 | # This program is distributed in the hope that it will be useful, 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | # GNU General Public License for more details. 12 | # 13 | # You should have received a copy of the GNU General Public License 14 | # along with this program. If not, see . 15 | 16 | """ Send local git changes to Travis CI without commits or pushes. """ 17 | 18 | import time 19 | import datetime 20 | import getpass 21 | import platform 22 | import sys 23 | import os 24 | import re 25 | import colorama 26 | import git 27 | from git.objects.util import utc 28 | 29 | 30 | __title__ = 'trytravis' 31 | __author__ = 'Seth Michael Larson' 32 | __email__ = 'sethmichaellarson@protonmail.com' 33 | __license__ = 'Apache-2.0' 34 | __url__ = 'https://github.com/SethMichaelLarson/trytravis' 35 | __version__ = '1.0.4' 36 | 37 | __all__ = ['main'] 38 | 39 | # Try to find the home directory for different platforms. 40 | _home_dir = os.path.expanduser('~') 41 | if _home_dir == '~' or not os.path.isdir(_home_dir): 42 | try: # Windows 43 | import win32file # noqa: F401 44 | from win32com.shell import shell, shellcon 45 | home = shell.SHGetFolderPath(0, shellcon.CSIDL_PROFILE, None, 0) 46 | except ImportError: # Try common directories? 47 | for _home_dir in [os.environ.get('HOME', ''), 48 | '/home/%s' % getpass.getuser(), 49 | 'C:\\Users\\%s' % getpass.getuser()]: 50 | if os.path.isdir(_home_dir): 51 | break 52 | 53 | # Determine config directory. 54 | if platform.system() == 'Windows': 55 | config_dir = os.path.join(_home_dir, 'trytravis') 56 | else: 57 | config_dir = os.path.join(_home_dir, '.config', 'trytravis') 58 | del _home_dir 59 | 60 | try: 61 | user_input = raw_input 62 | except NameError: 63 | user_input = input 64 | 65 | # Usage output 66 | _USAGE = ('usage: trytravis [command]?\n' 67 | '\n' 68 | ' [empty] Running with no command submits ' 69 | 'your git repo to Travis.\n' 70 | ' --help, -h Prints this help string.\n' 71 | ' --version, -v Prints out the version, useful when ' 72 | 'submitting an issue.\n' 73 | ' --repo, -r [repo]? Tells the program you wish to setup ' 74 | 'your building repository.\n' 75 | ' --no-wait, -nw Don\'t wait for the builds to end.\n' 76 | 77 | '\n' 78 | 'If you\'re still having troubles feel free to open an ' 79 | 'issue at our\nissue tracker: https://github.com/SethMichaelLarson' 80 | '/trytravis/issues') 81 | 82 | _HTTPS_REGEX = re.compile(r'^https://(?:www\.)?github\.com/([^/]+)/([^/]+)$') 83 | _SSH_REGEX = re.compile(r'^ssh://git@github\.com/([^/]+)/([^/]+)$') 84 | 85 | 86 | def _input_github_repo(url=None): 87 | """ Grabs input from the user and saves 88 | it as their trytravis target repo """ 89 | if url is None: 90 | url = user_input('Input the URL of the GitHub repository ' 91 | 'to use as a `trytravis` repository: ') 92 | url = url.strip() 93 | http_match = _HTTPS_REGEX.match(url) 94 | ssh_match = _SSH_REGEX.match(url) 95 | if not http_match and not ssh_match: 96 | raise RuntimeError('That URL doesn\'t look like a valid ' 97 | 'GitHub URL. We expect something ' 98 | 'of the form: `https://github.com/[USERNAME]/' 99 | '[REPOSITORY]` or `ssh://git@github.com/' 100 | '[USERNAME]/[REPOSITORY]') 101 | 102 | # Make sure that the user actually made a new repository on GitHub. 103 | if http_match: 104 | _, name = http_match.groups() 105 | else: 106 | _, name = ssh_match.groups() 107 | if 'trytravis' not in name: 108 | raise RuntimeError('You must have `trytravis` in the name of your ' 109 | 'repository. This is a security feature to reduce ' 110 | 'chances of running git push -f on a repository ' 111 | 'you don\'t mean to.') 112 | 113 | # Make sure that the user actually wants to use this repository. 114 | accept = user_input('Remember that `trytravis` will make commits on your ' 115 | 'behalf to `%s`. Are you sure you wish to use this ' 116 | 'repository? Type `y` or `yes` to accept: ' % url) 117 | if accept.lower() not in ['y', 'yes']: 118 | raise RuntimeError('Operation aborted by user.') 119 | 120 | if not os.path.isdir(config_dir): 121 | os.makedirs(config_dir) 122 | with open(os.path.join(config_dir, 'repo'), 'w+') as f: 123 | f.truncate() 124 | f.write(url) 125 | print('Repository saved successfully.') 126 | 127 | 128 | def _load_github_repo(): 129 | """ Loads the GitHub repository from the users config. """ 130 | if 'TRAVIS' in os.environ: 131 | raise RuntimeError('Detected that we are running in Travis. ' 132 | 'Stopping to prevent infinite loops.') 133 | try: 134 | with open(os.path.join(config_dir, 'repo'), 'r') as f: 135 | return f.read() 136 | except (OSError, IOError): 137 | raise RuntimeError('Could not find your repository. ' 138 | 'Have you ran `trytravis --repo`?') 139 | 140 | 141 | def _submit_changes_to_github_repo(path, url): 142 | """ Temporarily commits local changes and submits them to 143 | the GitHub repository that the user has specified. Then 144 | reverts the changes to the git repository if a commit was 145 | necessary. """ 146 | try: 147 | repo = git.Repo(path) 148 | except Exception: 149 | raise RuntimeError('Couldn\'t locate a repository at `%s`.' % path) 150 | commited = False 151 | try: 152 | try: 153 | repo.delete_remote('trytravis') 154 | except Exception: 155 | pass 156 | print('Adding a temporary remote to ' 157 | '`%s`...' % url) 158 | remote = repo.create_remote('trytravis', url) 159 | 160 | print('Adding all local changes...') 161 | repo.git.add('--all') 162 | try: 163 | print('Committing local changes...') 164 | timestamp = datetime.datetime.now().isoformat() 165 | repo.git.commit(m='trytravis-' + timestamp) 166 | commited = True 167 | except git.exc.GitCommandError as e: 168 | if 'nothing to commit' in str(e): 169 | commited = False 170 | else: 171 | raise 172 | commit = repo.head.commit.hexsha 173 | committed_at = repo.head.commit.committed_datetime 174 | 175 | print('Pushing to `trytravis` remote...') 176 | remote.push(force=True) 177 | finally: 178 | if commited: 179 | print('Reverting to old state...') 180 | repo.git.reset('HEAD^') 181 | try: 182 | repo.delete_remote('trytravis') 183 | except Exception: 184 | pass 185 | return commit, committed_at 186 | 187 | 188 | def _wait_for_travis_build(url, commit, committed_at): 189 | """ Waits for a Travis build to appear with the given commit SHA """ 190 | print('Waiting for a Travis build to appear ' 191 | 'for `%s` after `%s`...' % (commit, committed_at)) 192 | import requests 193 | 194 | slug = _slug_from_url(url) 195 | start_time = time.time() 196 | build_id = None 197 | 198 | while time.time() - start_time < 60: 199 | with requests.get('https://api.travis-ci.org/repos/%s/builds' % slug, 200 | headers=_travis_headers()) as r: 201 | if not r.ok: 202 | raise RuntimeError('Could not reach the Travis API ' 203 | 'endpoint. Additional information: ' 204 | '%s' % str(r.content)) 205 | 206 | # Search through all commits and builds to find our build. 207 | commit_to_sha = {} 208 | json = r.json() 209 | for travis_commit in sorted(json['commits'], 210 | key=lambda x: x['committed_at']): 211 | travis_committed_at = datetime.datetime.strptime( 212 | travis_commit['committed_at'], '%Y-%m-%dT%H:%M:%SZ' 213 | ).replace(tzinfo=utc) 214 | if travis_committed_at < committed_at: 215 | continue 216 | commit_to_sha[travis_commit['id']] = travis_commit['sha'] 217 | 218 | for build in json['builds']: 219 | if (build['commit_id'] in commit_to_sha and 220 | commit_to_sha[build['commit_id']] == commit): 221 | 222 | build_id = build['id'] 223 | print('Travis build id: `%d`' % build_id) 224 | print('Travis build URL: `https://travis-ci.org/' 225 | '%s/builds/%d`' % (slug, build_id)) 226 | 227 | if build_id is not None: 228 | break 229 | 230 | time.sleep(3.0) 231 | else: 232 | raise RuntimeError('Timed out while waiting for a Travis build ' 233 | 'to start. Is Travis configured for `%s`?' % url) 234 | return build_id 235 | 236 | 237 | def _watch_travis_build(build_id): 238 | """ Watches and progressively outputs information 239 | about a given Travis build """ 240 | import requests 241 | try: 242 | build_size = None # type: int 243 | running = True 244 | while running: 245 | with requests.get('https://api.travis-ci.org/builds/%d' % build_id, 246 | headers=_travis_headers()) as r: 247 | json = r.json() 248 | 249 | if build_size is not None: 250 | if build_size > 1: 251 | sys.stdout.write('\r\x1b[%dA' % build_size) 252 | else: 253 | sys.stdout.write('\r') 254 | 255 | build_size = len(json['jobs']) 256 | running = False 257 | current_number = 1 258 | for job in json['jobs']: # pragma: no coverage 259 | color, state, is_running = _travis_job_state(job['state']) 260 | if is_running: 261 | running = True 262 | 263 | platform = job['config']['os'] 264 | if platform == 'osx': 265 | platform = ' osx ' 266 | 267 | env = job['config'].get('env', '') 268 | sudo = 's' if job['config'].get('sudo', True) else 'c' 269 | lang = job['config'].get('language', 'generic') 270 | 271 | padding = ' ' * (len(str(build_size)) - 272 | len(str(current_number))) 273 | number = str(current_number) + padding 274 | current_number += 1 275 | job_display = '#' + ' '.join([number, 276 | state, 277 | platform, 278 | sudo, 279 | lang, 280 | env]) 281 | 282 | print(color + job_display + colorama.Style.RESET_ALL) 283 | 284 | time.sleep(3.0) 285 | except KeyboardInterrupt: 286 | pass 287 | 288 | 289 | def _travis_job_state(state): 290 | """ Converts a Travis state into a state character, color, 291 | and whether it's still running or a stopped state. """ 292 | if state in [None, 'queued', 'created', 'received']: 293 | return colorama.Fore.YELLOW, '*', True 294 | elif state in ['started', 'running']: 295 | return colorama.Fore.LIGHTYELLOW_EX, '*', True 296 | elif state == 'passed': 297 | return colorama.Fore.LIGHTGREEN_EX, 'P', False 298 | elif state == 'failed': 299 | return colorama.Fore.LIGHTRED_EX, 'X', False 300 | elif state == 'errored': 301 | return colorama.Fore.LIGHTRED_EX, '!', False 302 | elif state == 'canceled': 303 | return colorama.Fore.LIGHTBLACK_EX, 'X', False 304 | else: 305 | raise RuntimeError('unknown state: %s' % str(state)) 306 | 307 | 308 | def _slug_from_url(url): 309 | """ Parses a project slug out of either an HTTPS or SSH URL. """ 310 | http_match = _HTTPS_REGEX.match(url) 311 | ssh_match = _SSH_REGEX.match(url) 312 | if not http_match and not ssh_match: 313 | raise RuntimeError('Could not parse the URL (`%s`) ' 314 | 'for your repository.' % url) 315 | if http_match: 316 | return '/'.join(http_match.groups()) 317 | else: 318 | return '/'.join(ssh_match.groups()) 319 | 320 | 321 | def _version_string(): 322 | """ Gets the output for `trytravis --version`. """ 323 | platform_system = platform.system() 324 | if platform_system == 'Linux': 325 | os_name, os_version, _ = platform.dist() 326 | else: 327 | os_name = platform_system 328 | os_version = platform.version() 329 | python_version = platform.python_version() 330 | return 'trytravis %s (%s %s, python %s)' % (__version__, 331 | os_name.lower(), 332 | os_version, 333 | python_version) 334 | 335 | 336 | def _travis_headers(): 337 | """ Returns the headers that the Travis API expects from clients. """ 338 | return {'User-Agent': ('trytravis/%s (https://github.com/' 339 | 'SethMichaelLarson/trytravis)') % __version__, 340 | 'Accept': 'application/vnd.travis-ci.2+json'} 341 | 342 | 343 | def _main(argv): 344 | """ Function that acts just like main() except 345 | doesn't catch exceptions. """ 346 | repo_input_argv = len(argv) == 2 and argv[0] in ['--repo', '-r', '-R'] 347 | 348 | # We only support a single argv parameter. 349 | if len(argv) > 1 and not repo_input_argv: 350 | _main(['--help']) 351 | 352 | # Parse the command and do the right thing. 353 | if len(argv) == 1 or repo_input_argv: 354 | arg = argv[0] 355 | 356 | # Help/usage 357 | if arg in ['-h', '--help', '-H']: 358 | print(_USAGE) 359 | 360 | # Version 361 | elif arg in ['-v', '--version', '-V']: 362 | print(_version_string()) 363 | 364 | # Token 365 | elif arg in ['-r', '--repo', '-R']: 366 | if len(argv) == 2: 367 | url = argv[1] 368 | else: 369 | url = None 370 | _input_github_repo(url) 371 | 372 | # No wait 373 | elif arg in ['--no-wait', '-nw']: 374 | url = _load_github_repo() 375 | commit, committed = _submit_changes_to_github_repo(os.getcwd(), 376 | url) 377 | build_id = _wait_for_travis_build(url, commit, committed) 378 | 379 | # Help string 380 | else: 381 | _main(['--help']) 382 | 383 | # No arguments means we're trying to submit to Travis. 384 | elif len(argv) == 0: 385 | url = _load_github_repo() 386 | commit, committed = _submit_changes_to_github_repo(os.getcwd(), url) 387 | build_id = _wait_for_travis_build(url, commit, committed) 388 | _watch_travis_build(build_id) 389 | 390 | 391 | def main(argv=None): # pragma: no coverage 392 | """ Main entry point when the user runs the `trytravis` command. """ 393 | try: 394 | colorama.init() 395 | if argv is None: 396 | argv = sys.argv[1:] 397 | _main(argv) 398 | except RuntimeError as e: 399 | print(colorama.Fore.RED + 'ERROR: ' + 400 | str(e) + colorama.Style.RESET_ALL) 401 | sys.exit(1) 402 | else: 403 | sys.exit(0) 404 | 405 | 406 | if __name__ == '__main__': 407 | main() 408 | --------------------------------------------------------------------------------