Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#732 Update Travis URL on README #7

Merged
merged 5 commits into from Apr 12, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions bincrafters_conventions/actions/update_travis_url.py
@@ -0,0 +1,7 @@
def update_travis_url(main, file):
uilianries marked this conversation as resolved.
Show resolved Hide resolved
""" Update Travis CI URL
"""
if main.replace_in_file(file, "https://travis-ci.org/bincrafters", "https://travis-ci.com/bincrafters"):
main.output_result_update(title="README: Update Travis URL")
uilianries marked this conversation as resolved.
Show resolved Hide resolved
return True
return False
14 changes: 14 additions & 0 deletions bincrafters_conventions/bincrafters_conventions.py
Expand Up @@ -32,6 +32,7 @@
from .actions.update_t_linux_python_version import update_t_linux_python_version
from .actions.update_other_travis_to_ci_dir_name import update_other_travis_to_ci_dir_name
from .actions.update_other_pyenv_python_version import update_other_pyenv_python_version
from .actions.update_travis_url import update_travis_url


__version__ = '0.5.3'
Expand Down Expand Up @@ -118,6 +119,8 @@ def _parse_arguments(self, *args):
help='Project pattern to filter over user projects e.g bincrafters/conan-*')
parser.add_argument('--branch-pattern', '-bp', type=str,
help='Branch pattern to filter over user projects e.g stable/*')
parser.add_argument('--readme', '-r', type=str, nargs='?', const='README.md',
help='README file path to be updated')
group.add_argument('--version', '-v', action='version', version='%(prog)s {}'.format(__version__))
args = parser.parse_args(*args)
return args
Expand All @@ -134,6 +137,7 @@ def run(self, *args):
if os.path.isfile("appveyor.yml"):
self._update_appveyor_file("appveyor.yml")
self._update_conanfile("conanfile.py")
self._update_readme("README.md")
uilianries marked this conversation as resolved.
Show resolved Hide resolved
self._run_conventions_checks()
else:
if arguments.remote:
Expand All @@ -145,6 +149,8 @@ def run(self, *args):
else:
if arguments.conanfile:
self._update_conanfile(arguments.conanfile)
if arguments.readme:
self._update_readme(arguments.readme)
if arguments.travisfile:
self._update_compiler_jobs(arguments.travisfile)
if arguments.appveyorfile:
Expand Down Expand Up @@ -291,6 +297,14 @@ def _update_conanfile(self, conanfile):
update_c_generic_exception_to_invalid_conf(self, conanfile),
update_c_openssl_version_patch(self, conanfile, openssl_version_matrix))

def _update_readme(self, readme):
""" Update README.md file with new URL

:param readme: Readme file path
:return: True if updated. Otherwise, False.
"""
return update_travis_url(self, readme)

def _run_conventions_checks(self, conanfile="conanfile.py"):
""" Checks for conventions which we can't automatically update
when they should fail
Expand Down
44 changes: 44 additions & 0 deletions tests/test_update_file.py
Expand Up @@ -497,6 +497,32 @@ def package_info(self):
- python build.py
"""

README_FILE = """## Package Status

| Bintray | Appveyor | Travis |
|---------|------------|--------|
|[![Download](https://api.bintray.com/packages/bincrafters/public-conan/glog%3Abincrafters/images/download.svg) ](https://bintray.com/bincrafters/public-conan/glog%3Abincrafters/_latestVersion)|[![Build status](https://ci.appveyor.com/api/projects/status/github/bincrafters/conan-glog?svg=true)](https://ci.appveyor.com/project/bincrafters/conan-glog)|[![Build Status](https://travis-ci.org/bincrafters/conan-glog.svg)](https://travis-ci.org/bincrafters/conan-glog)|

## Conan.io Information

Bincrafters packages can be found in the following public Conan repository:

[Bincrafters Public Conan Repository on Bintray](https://bintray.com/bincrafters/public-conan)
"""

EXPECTED_README_FILE = """## Package Status

| Bintray | Appveyor | Travis |
|---------|------------|--------|
|[![Download](https://api.bintray.com/packages/bincrafters/public-conan/glog%3Abincrafters/images/download.svg) ](https://bintray.com/bincrafters/public-conan/glog%3Abincrafters/_latestVersion)|[![Build status](https://ci.appveyor.com/api/projects/status/github/bincrafters/conan-glog?svg=true)](https://ci.appveyor.com/project/bincrafters/conan-glog)|[![Build Status](https://travis-ci.com/bincrafters/conan-glog.svg)](https://travis-ci.com/bincrafters/conan-glog)|

## Conan.io Information

Bincrafters packages can be found in the following public Conan repository:

[Bincrafters Public Conan Repository on Bintray](https://bintray.com/bincrafters/public-conan)
"""


def test_update_travis_file():
""" Create a standard travis file and update it.
Expand Down Expand Up @@ -604,3 +630,21 @@ def test_update_travis_file_with_global():
command.run(args)

assert filecmp.cmp(travis_path, expected_path)


def test_travis_update_url():
""" Create a README.md file and update it.
"""
_, readme_path = tempfile.mkstemp(prefix='README', suffix='.md')
with open(readme_path, 'w') as file:
file.write(README_FILE)

_, expected_path = tempfile.mkstemp(prefix='README', suffix='.md')
with open(expected_path, 'w') as file:
file.write(EXPECTED_README_FILE)

args = ['--readme', readme_path]
command = Command()
command.run(args)

assert filecmp.cmp(readme_path, expected_path)