Skip to content

Commit

Permalink
Job id prefix (jid) is now using travis numbers, shoudl work for PRs …
Browse files Browse the repository at this point in the history
…too.

Change-Id: I17bb2e4ab0651edb6aad7b1cad0c9d65c7ebfb63
Signed-off-by: Sorin Sbarnea <ssbarnea@redhat.com>
  • Loading branch information
ssbarnea committed Nov 12, 2016
1 parent 743081e commit 9004766
Show file tree
Hide file tree
Showing 14 changed files with 145 additions and 92 deletions.
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
# All configuration values have a default; values that are commented out
# serve to show the default.

import sys
import os
import sphinx_rtd_theme
import sys

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
Expand Down
2 changes: 1 addition & 1 deletion examples/basic_auth.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# This script shows how to connect to a JIRA instance with a
# username and password over HTTP BASIC authentication.

from jira import JIRA
from collections import Counter
from jira import JIRA

# By default, the client will connect to a JIRA instance started from the Atlassian Plugin SDK.
# See
Expand Down
2 changes: 1 addition & 1 deletion examples/basic_use.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This script shows how to use the client in anonymous mode
# against jira.atlassian.com.
import re
from jira import JIRA
import re

# 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).
Expand Down
86 changes: 44 additions & 42 deletions jira/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,42 +17,46 @@

import collections
import copy
import json
import logging
import os
import re
import tempfile
import logging
try: # Python 2.7+
from logging import NullHandler
except ImportError:
class NullHandler(logging.Handler):

def emit(self, record):
pass
import json
import warnings
import sys
import datetime
import time
import xml.etree.ElementTree as etree
import calendar
import datetime
import hashlib
from numbers import Number
import requests
import sys
import time
import warnings

# noinspection PyUnresolvedReferences
from six.moves.urllib.parse import urlparse
from six import iteritems
from requests.utils import get_netrc_auth
from six import iteritems
from six.moves.urllib.parse import urlparse
# JIRA specific resources
from .resources import Resource, Issue, Comment, Project, Attachment, Component, Dashboard, Filter, Votes, Watchers, \
Worklog, IssueLink, IssueLinkType, IssueType, Priority, Version, Role, Resolution, SecurityLevel, Status, User, \
CustomFieldOption, RemoteLink
from jira.resources import * # NOQA
import xml.etree.ElementTree as etree

# GreenHopper specific resources
from .resources import GreenHopperResource, Board, Sprint
from .resilientsession import ResilientSession, raise_on_error
from . import __version__
from .utils import threaded_requests, json_loads, CaseInsensitiveDict
from .exceptions import JIRAError
from jira.exceptions import JIRAError
from jira.resilientsession import raise_on_error
from jira.resilientsession import ResilientSession
from jira.resources import Board
from jira.resources import GreenHopperResource
from jira.resources import Sprint

from jira import __version__
from jira.utils import CaseInsensitiveDict
from jira.utils import json_loads
from jira.utils import threaded_requests
from pkg_resources import parse_version

try:
Expand All @@ -61,7 +65,9 @@ def emit(self, record):
# noinspection PyUnresolvedReferences
from ordereddict import OrderedDict

from six import string_types, integer_types
from six import integer_types
from six import string_types

# six.moves does not play well with pyinstaller, see https://github.com/pycontribs/jira/issues/38
# from six.moves import html_parser
if sys.version_info < (3, 0, 0):
Expand All @@ -71,7 +77,7 @@ def emit(self, record):
try:
# noinspection PyUnresolvedReferences
from requests_toolbelt import MultipartEncoder
except:
except ImportError:
pass

try:
Expand Down Expand Up @@ -134,7 +140,7 @@ def __init__(self, iterable=None, _startAt=None, _maxResults=None, _total=None,
self.total = _total


class QshGenerator:
class QshGenerator(object):

def __init__(self, context_path):
self.context_path = context_path
Expand Down Expand Up @@ -184,7 +190,7 @@ class JIRA(object):

checked_version = False

# TODO: remove these two variables and use the ones defined in resources
# TODO(ssbarnea): remove these two variables and use the ones defined in resources
JIRA_BASE_URL = Resource.JIRA_BASE_URL
AGILE_BASE_URL = GreenHopperResource.AGILE_BASE_URL

Expand Down Expand Up @@ -313,7 +319,6 @@ def __init__(self, server=None, options=None, basic_auth=None, oauth=None, jwt=N
self._check_update_()
JIRA.checked_version = True

# TODO: check if this works with non-admin accounts
self._fields = {}
for f in self.fields():
if 'clauseNames' in f:
Expand Down Expand Up @@ -349,7 +354,6 @@ def __del__(self):
pass

def _check_for_html_error(self, content):
# TODO: Make it return errors when content is a webpage with errors
# JIRA has the bad habbit of returning errors in pages with 200 and
# embedding the error in a huge webpage.
if '<!-- SecurityTokenMissing -->' in content:
Expand Down Expand Up @@ -545,7 +549,6 @@ def add_attachment(self, issue, attachment, filename=None):
logging.warning(
"%s was not opened in 'rb' mode, attaching file may fail." % attachment.name)

# TODO: Support attaching multiple files at once?
url = self._get_url('issue/' + str(issue) + '/attachments')

fname = filename
Expand Down Expand Up @@ -1169,7 +1172,6 @@ def find_transitionid_by_name(self, issue, transition_name):

@translate_resource_args
def transition_issue(self, issue, transition, fields=None, comment=None, **fieldargs):
# TODO: Support update verbs (same as issue.update())
"""
Perform a transition on an issue.
Expand All @@ -1188,7 +1190,7 @@ def transition_issue(self, issue, transition, fields=None, comment=None, **field

try:
transitionId = int(transition)
except:
except Exception:
# cannot cast to int, so try to find transitionId by name
transitionId = self.find_transitionid_by_name(issue, transition)
if transitionId is None:
Expand Down Expand Up @@ -1346,7 +1348,7 @@ def add_worklog(self, issue, timeSpent=None, timeSpentSeconds=None, adjustEstima
'active': False
}
data['updateAuthor'] = data['author']
# TODO: report bug to Atlassian: author and updateAuthor parameters are
# report bug to Atlassian: author and updateAuthor parameters are
# ignored.
url = self._get_url('issue/{0}/worklog'.format(issue))
r = self._session.post(url, params=params, data=json.dumps(data))
Expand Down Expand Up @@ -1652,7 +1654,7 @@ def project_roles(self, project):
"""
roles_dict = self._get_json('project/' + project + '/role')
return roles_dict
# TODO: return on a list of Roles()
# TODO(ssbarnea): return a list of Roles()

@translate_resource_args
def project_role(self, project, id):
Expand Down Expand Up @@ -1700,7 +1702,6 @@ def search_issues(self, jql_str, startAt=0, maxResults=50, validate_query=True,
:param json_result: JSON response will be returned when this parameter is set to True.
Otherwise, ResultList will be returned.
"""
# TODO what to do about the expand, which isn't related to the issues?
if fields is None:
fields = []

Expand Down Expand Up @@ -2107,8 +2108,8 @@ def _create_http_basic_session(self, username, password):
def _create_oauth_session(self, oauth):
verify = self._options['verify']

from requests_oauthlib import OAuth1
from oauthlib.oauth1 import SIGNATURE_RSA
from requests_oauthlib import OAuth1

oauth = OAuth1(
oauth['consumer_key'],
Expand All @@ -2123,7 +2124,8 @@ def _create_oauth_session(self, oauth):
def _create_kerberos_session(self):
verify = self._options['verify']

from requests_kerberos import HTTPKerberosAuth, OPTIONAL
from requests_kerberos import HTTPKerberosAuth
from requests_kerberos import OPTIONAL

self._session = ResilientSession()
self._session.verify = verify
Expand Down Expand Up @@ -2264,7 +2266,7 @@ def rename_user(self, old_user, new_user):
merge = "true"
try:
self.user(new_user)
except:
except Exception:
merge = "false"

url = self._options['server'] + '/secure/admin/groovy/CannedScriptRunner.jspa#result'
Expand Down Expand Up @@ -2442,7 +2444,7 @@ def backup_progress(self):
# This is weird. I used to get xml, but now I'm getting json
try:
return json.loads(r.text)
except:
except Exception:
progress = {}
try:
root = etree.fromstring(r.text)
Expand Down Expand Up @@ -2484,7 +2486,7 @@ def backup_download(self, filename=None):
with open(local_file, 'wb') as file:
try:
resp = self._session.get(url, headers=self._options['headers'], stream=True)
except:
except Exception:
raise JIRAError()
if not resp.ok:
logging.error("Something went wrong with download: %s" % resp.text)
Expand Down Expand Up @@ -2659,7 +2661,7 @@ def add_user(self, username, email, directoryId=1, password=None,
'''
if not fullname:
fullname = username
# TODO: default the directoryID to the first directory in jira instead
# TODO(ssbarnea): default the directoryID to the first directory in jira instead
# of 1 which is the internal one.
url = self._options['server'] + '/rest/api/latest/user'

Expand Down Expand Up @@ -2857,7 +2859,7 @@ def completed_issues(self, board_id, sprint_id):
:param board_id: the board retrieving issues from
:param sprint_id: the sprint retieving issues from
"""
# TODO need a better way to provide all the info from the sprintreport
# We need a better way to provide all the info from the sprintreport
# incompletedIssues went to backlog but not it not completed
# issueKeysAddedDuringSprint used to mark some with a * ?
# puntedIssues are for scope change?
Expand Down Expand Up @@ -2926,7 +2928,7 @@ def removedIssuesEstimateSum(self, board_id, sprint_id):
return self._get_json('rapid/charts/sprintreport?rapidViewId=%s&sprintId=%s' % (board_id, sprint_id),
base=self.AGILE_BASE_URL)['contents']['puntedIssuesEstimateSum']['value']

# TODO: remove sprint_info() method, sprint() method suit the convention more
# TODO(ssbarnea): remove sprint_info() method, sprint() method suit the convention more
def sprint_info(self, board_id, sprint_id):
"""
Return the information about a sprint.
Expand All @@ -2943,9 +2945,9 @@ def sprint(self, id):
sprint.find(id)
return sprint

# TODO: remove this as we do have Board.delete()
# TODO(ssbarnea): remove this as we do have Board.delete()
def delete_board(self, id):
""" Deletes an agile board. """
"""Deletes an agile board. """
board = Board(self._options, self._session, raw={'id': id})
board.delete()

Expand Down Expand Up @@ -3078,7 +3080,7 @@ def add_issues_to_epic(self, epic_id, issue_keys, ignore_epics=True):
:param ignore_epics: ignore any issues listed in ``issue_keys`` that are epics
"""
if self._options['agile_rest_path'] != GreenHopperResource.GREENHOPPER_REST_PATH:
# TODO: simulate functionality using issue.update()?
# TODO(ssbarnea): simulate functionality using issue.update()?
raise NotImplementedError('JIRA Agile Public API does not support this request')

data = {}
Expand All @@ -3089,7 +3091,7 @@ def add_issues_to_epic(self, epic_id, issue_keys, ignore_epics=True):
return self._session.put(
url, data=json.dumps(data))

# TODO: Both GreenHopper and new JIRA Agile API support moving more than one issue.
# TODO(ssbarnea): Both GreenHopper and new JIRA Agile API support moving more than one issue.
def rank(self, issue, next_issue):
"""
Rank an issue before another using the default Ranking field, the one named 'Rank'.
Expand Down
4 changes: 2 additions & 2 deletions jira/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
import sys
try:
import configparser
except:
except ImportError:
from six.moves import configparser

from .client import JIRA
from jira.client import JIRA


def get_jira(profile=None, url="http://localhost:2990", username="admin", password="admin", appid=None, autofix=False, verify=True):
Expand Down
9 changes: 5 additions & 4 deletions jira/jirashell.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,23 @@

try:
import configparser
except:
except ImportError:
from six.moves import configparser
from six.moves import input

from six.moves.urllib.parse import parse_qsl

import argparse
from getpass import getpass
from sys import exit
from jira import __version__
from jira import JIRA
from oauthlib.oauth1 import SIGNATURE_RSA
import os
import requests
from oauthlib.oauth1 import SIGNATURE_RSA
from requests_oauthlib import OAuth1
from sys import exit

import webbrowser
from jira import JIRA, __version__

CONFIG_PATH = os.path.join(
os.path.expanduser('~'), '.jira-python', 'jirashell.ini')
Expand Down
9 changes: 5 additions & 4 deletions jira/resilientsession.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from requests import Session
from requests.exceptions import ConnectionError
import json
import logging
try: # Python 2.7+
from logging import NullHandler
Expand All @@ -11,9 +10,11 @@ class NullHandler(logging.Handler):
def emit(self, record):
pass
import random
from requests.exceptions import ConnectionError
from requests import Session
import time
import json
from .exceptions import JIRAError

from jira.exceptions import JIRAError

logging.getLogger('jira').addHandler(NullHandler())

Expand Down

0 comments on commit 9004766

Please sign in to comment.