diff --git a/.gitignore b/.gitignore index b6e4761..8ced6b4 100644 --- a/.gitignore +++ b/.gitignore @@ -127,3 +127,6 @@ dmypy.json # Pyre type checker .pyre/ + +# Jetbrains IDEs +.idea diff --git a/README.md b/README.md index 0293bdf..258c632 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,2 @@ # Gerrit-to-Github-Issues -Set of scripts that can be used to synchronize/update Github Issues with data from a Gerrit instance. +A set of scripts that can be used to synchronize/update Github Issues with data from a Gerrit instance. diff --git a/gerrit_to_github_issues/__main__.py b/gerrit_to_github_issues/cli.py similarity index 94% rename from gerrit_to_github_issues/__main__.py rename to gerrit_to_github_issues/cli.py index 60255c0..8566693 100644 --- a/gerrit_to_github_issues/__main__.py +++ b/gerrit_to_github_issues/cli.py @@ -13,8 +13,8 @@ import argparse import logging import os -import errors -from engine import update +from gerrit_to_github_issues import errors +from gerrit_to_github_issues.engine import update LOG_FORMAT = '%(asctime)s %(levelname)-8s %(name)s:' \ '%(funcName)s [%(lineno)3d] %(message)s' # noqa @@ -29,7 +29,7 @@ def validate(namespace: argparse.Namespace): return arg_dict -if __name__ == '__main__': +def main(): parser = argparse.ArgumentParser( prog='gerrit-to-github-issues', usage='synchronizes GitHub Issues with new changes found in Gerrit', @@ -41,7 +41,8 @@ if __name__ == '__main__': '4. If the Gerrit change\'s commit message contains a "WIP" or "DNM" tag, add the "wip" label and ' 'to the issue remove other process labels such as "ready for review".\n' '5. If no "WIP" or "DNM" tag is found in the change\'s commit message, add the "ready for review" ' - 'label to the issue and remove other process labels such as "ready for review".' + 'label to the issue and remove other process labels such as "ready for review".', + formatter_class=argparse.RawDescriptionHelpFormatter ) parser.add_argument('-g', '--gerrit-url', action='store', required=True, type=str, default=os.getenv('GERRIT_URL', default=None), help='Target Gerrit URL.') @@ -69,3 +70,7 @@ if __name__ == '__main__': logging.basicConfig(format=LOG_FORMAT, level=logging.INFO) args.pop('verbose') update(**args) + + +if __name__ == '__main__': + main() diff --git a/gerrit_to_github_issues/engine.py b/gerrit_to_github_issues/engine.py index 10bce0f..6977d51 100644 --- a/gerrit_to_github_issues/engine.py +++ b/gerrit_to_github_issues/engine.py @@ -14,8 +14,8 @@ import logging import github from github.Repository import Repository -import gerrit -import github_issues +from gerrit_to_github_issues import gerrit +from gerrit_to_github_issues import github_issues LOG = logging.getLogger(__name__) @@ -48,7 +48,7 @@ def process_change(change: dict, repo: Repository, gerrit_url: str): LOG.debug(f'Issue #{issue_number} was closed, reopening...') #issue.edit(state='open') #issue.create_comment('Issue reopened due to new activity on Gerrit.\n\n') - labels = issue.get_labels() + labels = [str(l.name) for l in list(issue.get_labels())] if 'WIP' in change['commitMessage'] or 'DNM' in change['commitMessage']: if 'wip' not in labels: LOG.debug(f'add `wip` to #{issue_number}') diff --git a/gerrit_to_github_issues/github_issues.py b/gerrit_to_github_issues/github_issues.py index f99af79..a198a39 100644 --- a/gerrit_to_github_issues/github_issues.py +++ b/gerrit_to_github_issues/github_issues.py @@ -16,7 +16,7 @@ import github from github.Issue import Issue from github.Repository import Repository -import errors +from gerrit_to_github_issues import errors LOG = logging.getLogger(__name__) diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..3e39f8f --- /dev/null +++ b/setup.cfg @@ -0,0 +1,24 @@ +[metadata] +name = gerrit-to-github-issues +version = 0.0.1 +summary = Updates Github Issues with new related Gerrit changes +description = A set of scripts that can be used to synchronize/update Github Issues with data from a Gerrit instance. +description-file = README.md +author = Ian H. Pittwood +license = Apache-2 +requires-python = >=3.6 +classifier = + Intended Audience :: Information Technology + License :: OSI Approved :: Apache Software License + Programming Language :: Python + Programming Language :: Python :: 3 + Programming Language :: Python :: 3.6 + Programming Language :: Python :: 3.7 + +[files] +packages = + gerrit_to_github_issues + +[entry_points] +console_scripts = + gerrit-to-github-issues = gerrit_to_github_issues.cli:main \ No newline at end of file diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..b27838f --- /dev/null +++ b/setup.py @@ -0,0 +1,14 @@ +# Licensed under the Apache License, Version 2.0 (the 'License'); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an 'AS IS' BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import setuptools + +setuptools.setup(setup_requires=['pbr>=2.0.0'], pbr=True)