Exemplo n.º 1
0
def current_branch_mark_status(repo_dir, state):
    """
    _current_branch_mark_status_

    Mark the CI status of the current branch.

    :param repo_dir: directory of git repository
    :param state: state of the last test run, such as "success" or "failure"

    """

    LOGGER.info(u"Setting CI status for current branch to {}".format(state))

    config = load_configuration()
    token = get_github_auth()[1]
    sha = git.Repo(repo_dir).head.commit.hexsha

    try:
        # @HACK: Do a push that we expect will fail -- we just want to
        # tell the server about our sha. A more elegant solution would
        # probably be to push a detached head.
        push(repo_dir)
    except RuntimeError as ex:
        if "rejected" not in unicode_(ex):
            raise

    url = "https://api.github.com/repos/{org}/{repo}/statuses/{sha}".format(
        org=config.organisation_name(),
        repo=config.package_name(),
        sha=sha
    )

    headers = {
        'Authorization': 'token {0}'.format(token),
        'Content-Type': 'application/json'
    }

    data = json.dumps(
        {
            "state": state,
            "description": "State after cirrus check.",
            # @HACK: use the travis context, which is technically
            # true, because we wait for Travis tests to pass before
            # cutting a release. In the future, we need to setup a
            # "cirrus" context, for clarity.
            "context": "continuous-integration/travis-ci"
        }
    )
    resp = requests.post(url, headers=headers, data=data)
    resp.raise_for_status()
Exemplo n.º 2
0
def current_branch_mark_status(repo_dir, state):
    """
    _current_branch_mark_status_

    Mark the CI status of the current branch.

    :param repo_dir: directory of git repository
    :param state: state of the last test run, such as "success" or "failure"

    """

    LOGGER.info(u"Setting CI status for current branch to {}".format(state))

    config = load_configuration()
    token = get_github_auth()[1]
    sha = git.Repo(repo_dir).head.commit.hexsha

    try:
        # @HACK: Do a push that we expect will fail -- we just want to
        # tell the server about our sha. A more elegant solution would
        # probably be to push a detached head.
        push(repo_dir)
    except RuntimeError as ex:
        if "rejected" not in unicode_(ex):
            raise

    url = "https://api.github.com/repos/{org}/{repo}/statuses/{sha}".format(
        org=config.organisation_name(),
        repo=config.package_name(),
        sha=sha
    )

    headers = {
        'Authorization': 'token {0}'.format(token),
        'Content-Type': 'application/json'
    }

    data = json.dumps(
        {
            "state": state,
            "description": "State after cirrus check.",
            # @HACK: use the travis context, which is technically
            # true, because we wait for Travis tests to pass before
            # cutting a release. In the future, we need to setup a
            # "cirrus" context, for clarity.
            "context": "continuous-integration/travis-ci"
        }
    )
    resp = requests.post(url, headers=headers, data=data)
    resp.raise_for_status()
Exemplo n.º 3
0
def setup_branches(opts):
    """
    set up git branches, starting from master
    """
    do_push = not opts.no_remote
    LOGGER.info("setting up branches master={} develop={}".format(
        opts.master, opts.develop))
    with working_dir(opts.repo):
        branch(opts.repo, opts.master, opts.master)
        branch(opts.repo, opts.develop, opts.master)
        if do_push:
            LOGGER.info("Pushing {}...".format(opts.develop))
            push(opts.repo)

    LOGGER.info("Working on {}".format(get_active_branch(opts.repo)))
Exemplo n.º 4
0
def new_feature_branch(opts):
    """
    _new_feature_branch_

    Checks out branch, creates new branch 'name', optionally
    pushes new branch to remote
    """
    config = load_configuration()
    repo_dir = os.getcwd()
    checkout_and_pull(repo_dir, config.gitflow_branch_name())
    LOGGER.info("Checked out and pulled {0}".format(
        config.gitflow_branch_name()))
    branch_name = ''.join((config.gitflow_feature_prefix(), opts.name[0]))
    branch(repo_dir, branch_name, config.gitflow_branch_name())
    LOGGER.info("Created branch {0}".format(branch_name))
    if opts.push:
        push(repo_dir)
        LOGGER.info("Branch {0} pushed to remote".format(branch_name))
Exemplo n.º 5
0
    def set_branch_state(self, state, context, branch=None):
        """
        _current_branch_mark_status_

        Mark the CI status of the current branch.

        :param state: state of the last test run, such as "success" or "failure"
        :param context: The GH context string to use for the state, eg
           "continuous-integration/travis-ci"

        :param branch: Optional branch name or sha to set state on,
           defaults to current active branch

        """
        if branch is None:
            branch = self.repo.active_branch.name

        LOGGER.info(u"Setting CI status for branch {} to {}".format(branch, state))

        sha = self.repo.head.commit.hexsha

        try:
            # @HACK: Do a push that we expect will fail -- we just want to
            # tell the server about our sha. A more elegant solution would
            # probably be to push a detached head.
            push(self.repo_dir)
        except RuntimeError as ex:
            if "rejected" not in unicode_(ex):
                raise

        url = "https://api.github.com/repos/{org}/{repo}/statuses/{sha}".format(
            org=self.config.organisation_name(),
            repo=self.config.package_name(),
            sha=sha
        )
        data = json.dumps(
            {
                "state": state,
                "description": "State after cirrus check.",
                "context": context
            }
        )
        resp = self.session.post(url, data=data)
        resp.raise_for_status()
Exemplo n.º 6
0
    def set_branch_state(self, state, context, branch=None):
        """
        _current_branch_mark_status_

        Mark the CI status of the current branch.

        :param state: state of the last test run, such as "success" or "failure"
        :param context: The GH context string to use for the state, eg
           "continuous-integration/travis-ci"

        :param branch: Optional branch name or sha to set state on,
           defaults to current active branch

        """
        if branch is None:
            branch = self.repo.active_branch.name

        LOGGER.info(u"Setting CI status for branch {} to {}".format(branch, state))

        sha = self.repo.head.commit.hexsha

        try:
            # @HACK: Do a push that we expect will fail -- we just want to
            # tell the server about our sha. A more elegant solution would
            # probably be to push a detached head.
            push(self.repo_dir)
        except RuntimeError as ex:
            if "rejected" not in unicode_(ex):
                raise

        url = "https://api.github.com/repos/{org}/{repo}/statuses/{sha}".format(
            org=self.config.organisation_name(),
            repo=self.config.package_name(),
            sha=sha
        )
        data = json.dumps(
            {
                "state": state,
                "description": "State after cirrus check.",
                "context": context
            }
        )
        resp = self.session.post(url, data=data)
        resp.raise_for_status()
Exemplo n.º 7
0
def new_feature_branch(opts):
    """
    _new_feature_branch_

    Checks out branch, creates new branch 'name', optionally
    pushes new branch to remote
    """
    config = load_configuration()
    repo_dir = repo_directory()
    checkout_and_pull(
        repo_dir,
        config.gitflow_branch_name(),
        pull=not opts.no_remote
    )
    LOGGER.info("Checked out and pulled {0}".format(
        config.gitflow_branch_name()))
    branch_name = ''.join((config.gitflow_feature_prefix(), opts.name[0]))
    branch(repo_dir,
           branch_name,
           config.gitflow_branch_name())
    LOGGER.info("Created branch {0}".format(branch_name))
    if not opts.no_remote:
        push(repo_dir)
        LOGGER.info("Branch {0} pushed to remote".format(branch_name))
Exemplo n.º 8
0
 def test_push(self):
     """
     _test_push_
     """
     push(None)
     self.failUnless(self.mock_git.Repo.called)
Exemplo n.º 9
0
 def test_push(self):
     """
     _test_push_
     """
     push(None)
     self.failUnless(self.mock_git.Repo.called)