Example #1
0
def test_repo_to_installation_id(app):

    with app.app_context():
        with patch('requests.post') as post:
            post.return_value.ok = True
            post.return_value.json.return_value = TOKEN_RESPONSE_VALID
            with patch('requests.get', requests_patch):

                assert repo_to_installation_id('test1') == 3331

                with pytest.raises(ValueError) as exc:
                    repo_to_installation_id('test3')
                assert exc.value.args[
                    0] == 'Repository not recognized - should be one of:\n\n  - test1\n  - test2'
def main(argv=None):

    parser = argparse.ArgumentParser(
        description='Check for stale pull requests and close them if needed.')

    parser.add_argument(
        '--repository',
        dest='repository',
        required=True,
        help='The repository in which to check for stale pull requests')

    parser.add_argument(
        '--warn-seconds',
        dest='warn_seconds',
        action='store',
        type=int,
        required=True,
        help='After how many seconds to warn about stale issues')

    parser.add_argument('--close-seconds',
                        dest='close_seconds',
                        action='store',
                        type=int,
                        required=True,
                        help='After how many seconds to close stale issues')

    args = parser.parse_args(argv or sys.argv[1:])

    installation = repo_to_installation_id(args.repository)

    process_pull_requests(args.repository,
                          installation,
                          warn_seconds=args.warn_seconds,
                          close_seconds=args.close_seconds)