How to use the jira.client.GreenHopper function in jira

To help you get started, we’ve selected a few jira examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github simonjbeaumont / docker-xs-dev-dash / scripts / tickets.py View on Github external
def jira_login(endpoint, user=None):
    try:
        basic_auth = None
        if user:
            if sys.stdin.isatty():
                password = getpass.getpass(stream=sys.stderr)
            else:
                password = sys.stdin.readline().rstrip()
            basic_auth = (user, password)
        try:
            jira = GreenHopper({'server': endpoint}, basic_auth=basic_auth)
        except JIRAError:
            sys.stderr.write("warn: Autentication to JIRA failed," +
                             " continuing unauthenticated\n")
            jira = GreenHopper({'server': endpoint})
        # pylint: disable=protected-access
        if "JSESSIONID" in jira._session.cookies:
            # drop basic auth if we have a cookie (for performance)
            jira._session.auth = None
        return jira
    except JIRAError as exn:
        sys.stderr.write("Connection to JIRA failed: %s: %s\n" %
                         (exn.response.status_code, exn.response.reason))
        exit(4)
github simonjbeaumont / docker-xs-dev-dash / scripts / tickets.py View on Github external
def jira_login(endpoint, user=None):
    try:
        basic_auth = None
        if user:
            if sys.stdin.isatty():
                password = getpass.getpass(stream=sys.stderr)
            else:
                password = sys.stdin.readline().rstrip()
            basic_auth = (user, password)
        try:
            jira = GreenHopper({'server': endpoint}, basic_auth=basic_auth)
        except JIRAError:
            sys.stderr.write("warn: Autentication to JIRA failed," +
                             " continuing unauthenticated\n")
            jira = GreenHopper({'server': endpoint})
        # pylint: disable=protected-access
        if "JSESSIONID" in jira._session.cookies:
            # drop basic auth if we have a cookie (for performance)
            jira._session.auth = None
        return jira
    except JIRAError as exn:
        sys.stderr.write("Connection to JIRA failed: %s: %s\n" %
                         (exn.response.status_code, exn.response.reason))
        exit(4)
github GaretJax / lancet / lancet / jira.py View on Github external
__all__ = ['JIRA', 'JIRAError']


class ObliviousCookieJar(RequestsCookieJar):
    def set_cookie(self, *args, **kwargs):
        """Simply ignore any request to set a cookie."""
        pass

    def copy(self):
        """Make sure to return an instance of the correct class on copying."""
        return ObliviousCookieJar()


class JIRA(GreenHopper):
    def _create_http_basic_session(self, username, password):
        super(JIRA, self)._create_http_basic_session(username, password)

        # XXX: JIRA logs the web user out if we send the session cookies we get
        # back from the first request in any subsequent requests. As we don't
        # need cookies when accessing the API anyway, just ignore all of them.
        self._session.cookies = ObliviousCookieJar()

    def close(self):
        self._session.close()
github pycontribs / jira / examples / greenhopper.py View on Github external
# This script shows how to use the client in anonymous mode
# against jira.atlassian.com.
from jira.client import GreenHopper

# By default, the client will connect to a JIRA instance started from the Atlassian Plugin SDK
# (see https://developer.atlassian.com/display/DOCS/Installing+the+Atlassian+Plugin+SDK for details).
# Override this with the options parameter.
# GreenHopper is a plugin in a JIRA instance
options = {"server": "https://jira.atlassian.com"}
gh = GreenHopper(options)

# Get all boards viewable by anonymous users.
boards = gh.boards()

# Get the sprints in a specific board
board_id = 441
print("GreenHopper board: %s (%s)" % (boards[0].name, board_id))
sprints = gh.sprints(board_id)