def selftest_function(opts): """ This test will attempt to login to jira. If successful, the session is ended """ options = opts.get("jira", {}) # auth/1/session url = '/'.join((options['url'], SESSION_PARAM)) payload = { "username": options['user'], "password": options['password'] } verify_flag = parse_bool(options['verify_cert']) try: result = execute_call(log, 'post', url, None, None, json.dumps(payload), verify_flag, HTTP_HEADERS) jsessionID = HTTP_HEADERS.copy() jsessionID['cookie'] = "{}={}".format(result['session']['name'], result['session']['value']) result = execute_call(log, 'delete', url, None, None, None, verify_flag, jsessionID) return {"state": "success"} except Exception as e: log and log.error(e) return {"state": "failure", "reason": e }
def create_comment(log, appDict): """Function: create a jira comment in a Jira issue. No JSON is returned on success :return: dictionary for a comment """ url = '/'.join((appDict['url'], COMMENT_PARAM)) payload = _mkCommentPayload(appDict) log and log.info(payload) resp = execute_call(log, 'post', url, appDict['user'], appDict['password'], payload, appDict['verifyFlag'], HTTP_HEADERS) # successfully added comments return an empty dictionary: { } return resp
def create_issue(log, appDict): """Function: create a jira issue. :return the raw JSON returned from the api call """ issue_url = '/'.join((appDict['url'], ISSUE_URL)) payload = _mkCreatePayload(appDict) log and log.info(payload) result = execute_call(log, 'post', issue_url, appDict['user'], appDict['password'], payload, appDict['verifyFlag'], HTTP_HEADERS) return result
def find_transitions(log, appDict): """ determine the ticket transitions for a given issue :param log: :param appDict: :return: None """ url = '/'.join((appDict['url'], TRANSITION_PARAM)) result = execute_call(log, 'get', url, appDict['user'], appDict['password'], None, appDict['verifyFlag'], HTTP_HEADERS) log and log.debug(result) return result
def transition_issue(log, appDict): """Function: transition a jira issue. :return: the raw JSON returned from the api call """ url = '/'.join((appDict['url'], TRANSITION_PARAM)) payload = _mkTransitionPayload(appDict) log and log.debug(payload) #find_transitions(log, appDict) # uncomment to see transitions for this enterprise result = execute_call(log, 'post', url, appDict['user'], appDict['password'], payload, appDict['verifyFlag'], HTTP_HEADERS) log and log.debug(result) return result
def transition_issue(log, appDict): """Function: transition a jira issue. :return: the raw JSON returned from the api call """ url = '/'.join((appDict['url'], TRANSITION_PARAM)) payload = _mkTransitionPayload(appDict) log and log.info(payload) result = execute_call(log, 'post', url, appDict['user'], appDict['password'], payload, appDict['verifyFlag'], HTTP_HEADERS) # log.info(result) if appDict['comment']: create_comment(log, appDict) return result