예제 #1
0
def test():
    from pastamaker import gh_pr
    from pastamaker import utils

    utils.setup_logging()
    config.log()
    gh_pr.monkeypatch_github()

    parts = sys.argv[1].split("/")
    LOG.info("Getting repo %s ..." % sys.argv[1])

    if True:
        # With access_token got from oauth
        token = sys.argv[2]

        g = github.Github(token)
        user = g.get_user(parts[3])
        repo = user.get_repo(parts[4])
        pull = repo.get_pull(int(parts[6]))
        update_branch(pull, token)
    else:
        # With access_token got from integration
        integration = github.GithubIntegration(config.INTEGRATION_ID,
                                               config.PRIVATE_KEY)

        installation_id = utils.get_installation_id(integration, parts[3])
        token = integration.get_access_token(installation_id).token
        update_branch(pull, "x-access-token:%s" % token)
예제 #2
0
def test():
    import github

    from pastamaker import gh_pr
    from pastamaker import utils

    utils.setup_logging()
    config.log()
    gh_pr.monkeypatch_github()

    parts = sys.argv[1].split("/")

    LOG.info("Getting repo %s ..." % sys.argv[1])

    integration = github.GithubIntegration(config.INTEGRATION_ID,
                                           config.PRIVATE_KEY)

    installation_id = utils.get_installation_id(integration, parts[3])
    token = integration.get_access_token(installation_id).token
    g = github.Github(token)
    user = g.get_user(parts[3])
    repo = user.get_repo(parts[4])
    LOG.info("Protecting repo %s branch %s ..." % (sys.argv[1], sys.argv[2]))
    policy = get_branch_policy(repo, sys.argv[2])
    protect_if_needed(repo, sys.argv[2], policy)
예제 #3
0
def refresh(owner, repo, branch):

    integration = github.GithubIntegration(config.INTEGRATION_ID,
                                           config.PRIVATE_KEY)

    installation_id = utils.get_installation_id(integration, owner)
    if not installation_id:
        flask.abort(404, "%s have not installed pastamaker" % owner)

    # Mimic the github event format
    data = {
        'repository': {
            'name': repo,
            'full_name': '%s/%s' % (owner, repo),
            'owner': {
                'login': owner
            },
        },
        'installation': {
            'id': installation_id
        },
        "branch": branch,
    }
    get_queue().enqueue(worker.event_handler, "refresh", data)
    return "", 202
예제 #4
0
파일: web.py 프로젝트: sileht/pastamaker
def refresh(owner, repo, refresh_ref):
    authentification()

    integration = github.GithubIntegration(config.INTEGRATION_ID,
                                           config.PRIVATE_KEY)

    installation_id = utils.get_installation_id(integration, owner)
    if not installation_id:
        flask.abort(404, "%s have not installed pastamaker" % owner)

    if refresh_ref == "full":
        token = integration.get_access_token(installation_id).token
        g = github.Github(token)
        r = g.get_repo("%s/%s" % (owner, repo))
        pulls = r.get_pulls()
        branches = set([p.base.ref for p in pulls])
        for branch in branches:
            # Mimic the github event format
            data = {
                'repository': {
                    'name': repo,
                    'full_name': '%s/%s' % (owner, repo),
                    'owner': {
                        'login': owner
                    },
                },
                'installation': {
                    'id': installation_id
                },
                "refresh_ref": "branch/%s" % branch,
            }
            get_queue().enqueue(worker.event_handler, "refresh", data)
    else:
        # Mimic the github event format
        data = {
            'repository': {
                'name': repo,
                'full_name': '%s/%s' % (owner, repo),
                'owner': {
                    'login': owner
                },
            },
            'installation': {
                'id': installation_id
            },
            "refresh_ref": refresh_ref,
        }
        get_queue().enqueue(worker.event_handler, "refresh", data)

    return "", 202