From 2a4b9bcce18b6cab9e7532bd7eb32fc9dce8c064 Mon Sep 17 00:00:00 2001 From: Doug Beatty Date: Fri, 22 Jul 2022 16:21:06 -0600 Subject: [PATCH 1/3] Resolve name conflict between a local module and the git package's cmd module --- hubcap/{cmd.py => git_helper.py} | 0 hubcap/hubcap.py | 2 +- hubcap/records.py | 8 ++++---- hubcap/setup.py | 2 +- hubcap/version.py | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) rename hubcap/{cmd.py => git_helper.py} (100%) diff --git a/hubcap/cmd.py b/hubcap/git_helper.py similarity index 100% rename from hubcap/cmd.py rename to hubcap/git_helper.py diff --git a/hubcap/hubcap.py b/hubcap/hubcap.py index b428319..b23439c 100644 --- a/hubcap/hubcap.py +++ b/hubcap/hubcap.py @@ -10,7 +10,7 @@ import package import release_carrier -from cmd import * +from git_helper import * from records import * # == diff --git a/hubcap/records.py b/hubcap/records.py index bc51441..11c88b5 100644 --- a/hubcap/records.py +++ b/hubcap/records.py @@ -1,6 +1,6 @@ '''Interface for objects useful to processing hub entries''' -import cmd +import git_helper import hashlib import json import logging @@ -71,7 +71,7 @@ def run(self, main_dir): for tag in self.new_tags: # go to repo dir to checkout tag and tag-commit specific package list os.chdir(self.local_path_to_repo) - cmd.run_cmd(f'git checkout tags/{tag}') + git_helper.run_cmd(f'git checkout tags/{tag}') packages = package.parse_pkgs(Path(os.getcwd())) # return to hub and build spec @@ -88,7 +88,7 @@ def run(self, main_dir): msg = f'hubcap: Adding tag {tag} for {self.github_username}/{self.github_repo_name}' logging.info(msg) - cmd.run_cmd('git add -A') + git_helper.run_cmd('git add -A') subprocess.run(args=['git', 'commit', '-am', f'{msg}'], capture_output=True) # if succesful return branchname @@ -102,7 +102,7 @@ def cut_version_branch(self): completed_subprocess = subprocess.run(['git', 'checkout', '-q', '-b', branch_name]) if completed_subprocess.returncode == 128: - run_cmd(f'git checkout -q {branch_name}') + git_helper.run_cmd(f'git checkout -q {branch_name}') return branch_name diff --git a/hubcap/setup.py b/hubcap/setup.py index 99fc7b7..4bcf0b5 100644 --- a/hubcap/setup.py +++ b/hubcap/setup.py @@ -9,7 +9,7 @@ import requests from pathlib import Path -from cmd import * +from git_helper import * from records import * NOW = int(datetime.datetime.now().timestamp()) diff --git a/hubcap/version.py b/hubcap/version.py index e442555..580ec50 100644 --- a/hubcap/version.py +++ b/hubcap/version.py @@ -6,7 +6,7 @@ import package -from cmd import * +from git_helper import * def parse_semver_tag(tag): From eb043d77429f072a298ee2635f717b1edc7bad59 Mon Sep 17 00:00:00 2001 From: Doug Beatty Date: Sat, 23 Jul 2022 17:06:40 -0600 Subject: [PATCH 2/3] Simple unit tests for SemVer 2.0 version numbers --- hubcap/__init__.py | 0 tests/__init__.py | 0 tests/test_version_regex.py | 111 ++++++++++++++++++++++++++++++++++++ 3 files changed, 111 insertions(+) create mode 100644 hubcap/__init__.py create mode 100644 tests/__init__.py create mode 100644 tests/test_version_regex.py diff --git a/hubcap/__init__.py b/hubcap/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_version_regex.py b/tests/test_version_regex.py new file mode 100644 index 0000000..5b3b240 --- /dev/null +++ b/tests/test_version_regex.py @@ -0,0 +1,111 @@ +import pytest +from hubcap.version import is_valid_semver_tag + + +@pytest.fixture +def semver_20_valid(): + """Valid SemVer 2.0 versions""" + # Most test cases from https://regex101.com/r/Ly7O1x/3/ + return [ + # Begin test cases from https://regex101.com/r/Ly7O1x/3/ + "0.0.4", + "1.2.3", + "10.20.30", + "1.1.2-prerelease+meta", + "1.1.2+meta", + "1.1.2+meta-valid", + "1.0.0-alpha", + "1.0.0-beta", + "1.0.0-alpha.beta", + "1.0.0-alpha.beta.1", + "1.0.0-alpha.1", + "1.0.0-alpha0.valid", + "1.0.0-alpha.0valid", + "1.0.0-alpha-a.b-c-somethinglong+build.1-aef.1-its-okay", + "1.0.0-rc.1+build.1", + "2.0.0-rc.1+build.123", + "1.2.3-beta", + "10.2.3-DEV-SNAPSHOT", + "1.2.3-SNAPSHOT-123", + "1.0.0", + "2.0.0", + "1.1.7", + "2.0.0+build.1848", + "2.0.1-alpha.1227", + "1.0.0-alpha+beta", + "1.2.3----RC-SNAPSHOT.12.9.1--.12+788", + "1.2.3----R-S.12.9.1--.12+meta", + "1.2.3----RC-SNAPSHOT.12.9.1--.12", + "1.0.0+0.build.1-rc.10000aaa-kk-0.1", + "99999999999999999999999.999999999999999999.99999999999999999", + "1.0.0-0A.is.legal", + # Begin custom test cases + "1.0.3-post1", + "0.8.0-a1", + "0.8.0-b2", + "0.8.0-rc3", + ] + + +@pytest.fixture +def semver_20_invalid(): + """Invalid SemVer 2.0 versions""" + # Most test cases from https://regex101.com/r/Ly7O1x/3/ + return [ + # Begin test cases from https://regex101.com/r/Ly7O1x/3/ + "1", + "1.2", + "1.2.3-0123", + "1.2.3-0123.0123", + "1.1.2+.123", + "+invalid", + "-invalid", + "-invalid+invalid", + "-invalid.01", + "alpha", + "alpha.beta", + "alpha.beta.1", + "alpha.1", + "alpha+beta", + "alpha_beta", + "alpha.", + "alpha..", + "beta", + "1.0.0-alpha_beta", + "-alpha.", + "1.0.0-alpha..", + "1.0.0-alpha..1", + "1.0.0-alpha...1", + "1.0.0-alpha....1", + "1.0.0-alpha.....1", + "1.0.0-alpha......1", + "1.0.0-alpha.......1", + "01.1.1", + "1.01.1", + "1.1.01", + "1.2", + "1.2.3.DEV", + "1.2-SNAPSHOT", + "1.2.31.2.3----RC-SNAPSHOT.12.09.1--..12+788", + "1.2-RC-SNAPSHOT", + "-1.0.3-gamma+b7718", + "+justmeta", + "9.8.7+meta+meta", + "9.8.7-whatever+meta+meta", + "99999999999999999999999.999999999999999999.99999999999999999----RC-SNAPSHOT.12.09.1--------------------------------..12", + # Begin custom test cases + "1.0.3.post1", + "0.8.0a1", + "0.8.0b2", + "0.8.0rc3", + ] + + +def test_regex_valid(semver_20_valid): + for version in semver_20_valid: + assert is_valid_semver_tag(version) + + +def test_regex_invalid(semver_20_invalid): + for version in semver_20_invalid: + assert not is_valid_semver_tag(version) From c3580f8555d77987823c98099cdd771c6057e146 Mon Sep 17 00:00:00 2001 From: Doug Beatty Date: Sat, 23 Jul 2022 17:07:28 -0600 Subject: [PATCH 3/3] Contributing instructions (including how to run tests locally) --- CONTRIBUTING.md | 71 ++++++++++++++++++++++++++++++++++++++++++++ config.example.json | 2 +- dev-requirements.txt | 2 ++ 3 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 CONTRIBUTING.md create mode 100644 dev-requirements.txt diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..75650ce --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,71 @@ +# Contributing to this repo + +## Setup + +### Personal access token (PAT) + +Follow [these](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token) instructions to configurate a personal access token. + +Only permissions needed: +- public_repo + +Save the token to a secure location. Click the "Configure SSO" button and "Authorize" if applicable. + +### Config + +```shell +cp config.example.json config.json + +# Add your GitHub username and token +$EDITOR config.json + +# Export the JSON credentials into an environment variable +export CONFIG=$(