Prepare project for packaging

Adds setuptools configuration and CLI entry point

Fixes labels list retrieval to use strings
This commit is contained in:
Ian H Pittwood 2020-02-27 11:01:02 -06:00
parent cf6e9a94c1
commit 21c88fef51
7 changed files with 55 additions and 9 deletions

3
.gitignore vendored
View File

@ -127,3 +127,6 @@ dmypy.json
# Pyre type checker
.pyre/
# Jetbrains IDEs
.idea

View File

@ -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.

View File

@ -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()

View File

@ -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}')

View File

@ -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__)

24
setup.cfg Normal file
View File

@ -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

14
setup.py Normal file
View File

@ -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)