Esempio n. 1
0
def watch(build_queue):
    while True:
        debug.set_prefix("repository_watcher")
        debug.message("Retrieving projects")
        try:
            projects = Api.get_projects()

            for project in projects:
                debug.message("Check repository status for project %s" % project["Name"])
                repository = Git(get_path(project), get_origin_url(project))
                commit_count = handle_incoming_commits(repository.check_for_new_commits_on_origin(), project,
                                                       repository, build_queue)
                if commit_count > 0:
                    repository.merge_origin()

                # Add <initial_nr_commits> commits if this is a new repository
                if project["Commits"] is None or len(project["Commits"]) == 0:
                    handle_incoming_commits(
                        repository.get_commits(registry.config["repositories"]["initial_nr_commits"]), project,
                        repository, build_queue)

        except ValueError, e:
            debug.exception("Error retrieving projects", e)
        except GitError, e:
            debug.exception("Error with Git repository", e)
Esempio n. 2
0
def pull_request():
    args = _make_argparser().parse_args()

    if args.debug:
        logging.disable(logging.NOTSET)

    try:
        git = Git()
    except GitException as ex:
        print('ERROR: ' + ex.message)
        return 1

    config = CmdprConfig(CONFIG)

    try:
        github = GitHub(get_token(config))

        base = args.base[0]
        title, body = '', ''
        if args.message is None:
            title, body = create_request_title(git.get_commits(base))
        else:
            title = args.message[0]

        if title is None:
            print('ERROR: There\'s no title for pull request')
            return 1

        repo_info = git.get_repo_info()
        bug_tracker = config.get("bug_tracker")
        if bug_tracker:
            body = bug_tracker.format(task=repo_info['branch'])

        pr_url = github.create_pull_request(repo_info, title, base, body)
        print(pr_url)
    except GitHubException as ex:
        print('ERROR: ' + ex.message)
        return 1