Skip to content
Permalink
Browse files

Add a new method (#47)

* add a new method delete page from trash, get all pages from space and from trash

* Add small docs

* rename method name

* Add method work with drafts for clean old drafts

* Add search functionality

* provide a new method for generate the report assignable users

* Exlude python 3.3 env

* Fix problem with cyrrilic on py2

* Normalize the urls

* Add method for the get user group members

* Correct repo for travis

* Buml

* add into requirements six modul

* Just change tox.ini

* Revert the config

* add method search users using user string as username or display name phrase

* Remove slashes from method url

* Remove slashes from method url

* Add a new method delete brach
  • Loading branch information...
gonchik authored and AstroMatt committed May 30, 2018
1 parent 9899ef3 commit dc3d2b54d0c92dcce0ad49c173d8edc88e068e1d
Showing with 106 additions and 37 deletions.
  1. +1 −1 README.rst
  2. +1 −1 atlassian/VERSION
  3. +1 −0 atlassian/bamboo.py
  4. +44 −14 atlassian/bitbucket.py
  5. +1 −0 atlassian/crowd.py
  6. +51 −20 atlassian/jira.py
  7. +1 −0 atlassian/portfolio.py
  8. +1 −0 atlassian/rest_client.py
  9. +1 −0 atlassian/utils.py
  10. +1 −0 requirements.txt
  11. +3 −1 tox.ini
@@ -2,7 +2,7 @@
Atlassian Python API wrapper
============================

.. image:: https://travis-ci.org/cattz/atlassian-python-api.svg?branch=master
.. image:: https://travis-ci.org/AstroMatt/atlassian-python-api.svg?branch=master

For users
=========
@@ -1 +1 @@
1.6.0
1.6.1
@@ -1,3 +1,4 @@
# -*- coding: utf8 -*-
import logging
from .rest_client import AtlassianRestAPI

@@ -1,21 +1,20 @@
# -*- coding: utf8 -*-
import logging
from .rest_client import AtlassianRestAPI


log = logging.getLogger(__name__)


class Bitbucket(AtlassianRestAPI):

def project_list(self):
return self.get('/rest/api/1.0/projects')['values']
return self.get('rest/api/1.0/projects')['values']

def project(self, key):
url = '/rest/api/1.0/projects/{0}'.format(key)
url = 'rest/api/1.0/projects/{0}'.format(key)
return self.get(url)['values']

def project_users(self, key, limit=99999):
url = '/rest/api/1.0/projects/{key}/permissions/users?limit={limit}'.format(key=key, limit=limit)
url = 'rest/api/1.0/projects/{key}/permissions/users?limit={limit}'.format(key=key, limit=limit)
return self.get(url)['values']

def project_users_with_administrator_permissions(self, key):
@@ -27,7 +26,7 @@ def project_users_with_administrator_permissions(self, key):
return project_administrators

def project_groups(self, key, limit=99999):
url = '/rest/api/1.0/projects/{key}/permissions/groups?limit={limit}'.format(key=key, limit=limit)
url = 'rest/api/1.0/projects/{key}/permissions/groups?limit={limit}'.format(key=key, limit=limit)
return self.get(url)['values']

def project_groups_with_administrator_permissions(self, key):
@@ -41,7 +40,7 @@ def project_summary(self, key):
'groups': self.project_groups(key)}

def group_members(self, group, limit=99999):
url = '/rest/api/1.0/admin/groups/more-members?context={group}&limit={limit}'.format(group=group, limit=limit)
url = 'rest/api/1.0/admin/groups/more-members?context={group}&limit={limit}'.format(group=group, limit=limit)
return self.get(url)['values']

def all_project_administrators(self):
@@ -53,12 +52,43 @@ def all_project_administrators(self):
'project_administrators': [{'email': x['emailAddress'], 'name': x['displayName']}
for x in self.project_users_with_administrator_permissions(project['key'])]}

def get_branches(self, project, repository, filter='', limit=99999):
url = '/rest/api/1.0/projects/{project}/repos/{repository}/branches?limit={limit}&filterText={filter}'.format(
def repo_list(self, project_key, limit=25):
url = 'rest/api/1.0/projects/{projectKey}/repos?limit={limit}'.format(projectKey=project_key, limit=limit)
return self.get(url)['values']

def get_branches(self, project, repository, filter='', limit=99999, details=True):
url = 'rest/api/1.0/projects/{project}/repos/{repository}/branches?limit={limit}&filterText={filter}&details={details}'.format(
project=project,
repository=repository,
limit=limit,
filter=filter)
filter=filter,
details=details
)
return self.get(url)['values']

def delete_branch(self, project, repository, name, end_point):
"""
:param project:
:param repository:
:param name:
:param end_point:
:return:
"""
url = 'rest/branch-utils/latest/projects/{project}/repos/{repository}/branches'.format(
project=project,
repository=repository)
data = {"name": str(name), "endPoint": str(end_point)}
return self.delete(url, data=data)

def get_pull_requests(self, project, repository, state='OPEN', order='newest', limit=100, start=0):
url = 'rest/api/latest/projects/{project}/repos/{repository}/pull-requests?state={state}&limit={limit}&start={start}&order={order}'.format(
project=project,
repository=repository,
limit=limit,
state=state,
start=start,
order=order)
return self.get(url)['values']

def get_tags(self, project, repository, filter='', limit=99999):
@@ -70,7 +100,7 @@ def get_tags(self, project, repository, filter='', limit=99999):
return self.get(url)['values']

def get_diff(self, project, repository, path, hash_oldest, hash_newest):
url = '/rest/api/1.0/projects/{project}/repos/{repository}/compare/diff/{path}?from={hash_oldest}&to={hash_newest}'.format(
url = 'rest/api/1.0/projects/{project}/repos/{repository}/compare/diff/{path}?from={hash_oldest}&to={hash_newest}'.format(
project=project,
repository=repository,
path=path,
@@ -79,7 +109,7 @@ def get_diff(self, project, repository, path, hash_oldest, hash_newest):
return self.get(url)['diffs']

def get_commits(self, project, repository, hash_oldest, hash_newest, limit=99999):
url = '/rest/api/1.0/projects/{project}/repos/{repository}/commits?since={hash_from}&until={hash_to}&limit={limit}'.format(
url = 'rest/api/1.0/projects/{project}/repos/{repository}/commits?since={hash_from}&until={hash_to}&limit={limit}'.format(
project=project,
repository=repository,
hash_from=hash_oldest,
@@ -88,7 +118,7 @@ def get_commits(self, project, repository, hash_oldest, hash_newest, limit=99999
return self.get(url)['values']

def get_changelog(self, project, repository, ref_from, ref_to, limit=99999):
url = '/rest/api/1.0/projects/{project}/repos/{repository}/compare/commits?from={ref_from}&to={ref_to}&limit={limit}'.format(
url = 'rest/api/1.0/projects/{project}/repos/{repository}/compare/commits?from={ref_from}&to={ref_to}&limit={limit}'.format(
project=project,
repository=repository,
ref_from=ref_from,
@@ -97,7 +127,7 @@ def get_changelog(self, project, repository, ref_from, ref_to, limit=99999):
return self.get(url)['values']

def get_content_of_file(self, project, repository, filename):
url = '/projects/{project}/repos/{repository}/browse/{filename}?raw'.format(
url = 'projects/{project}/repos/{repository}/browse/{filename}?raw'.format(
project=project,
repository=repository,
filename=filename)
@@ -1,3 +1,4 @@
# -*- coding: utf8 -*-
import logging
from .rest_client import AtlassianRestAPI

@@ -9,38 +9,56 @@
class Jira(AtlassianRestAPI):

def reindex_status(self):
return self.get('/rest/api/2/reindex')
return self.get('rest/api/2/reindex')

def reindex(self):
return self.post('/rest/api/2/reindex')
return self.post('rest/api/2/reindex')

def jql(self, jql, fields='*all', limit=999999):
return self.get('/rest/api/2/search?maxResults={limit}&fields={fields}&jql={jql}'.format(
return self.get('rest/api/2/search?maxResults={limit}&fields={fields}&jql={jql}'.format(
limit=limit,
fields=fields,
jql=jql))

def user(self, username):
return self.get('/rest/api/2/user?username={0}'.format(username))
return self.get('rest/api/2/user?username={0}'.format(username))

def user_find_by_user_string(self, username, start=0, limit=50, include_inactive_users=False):
"""
Fuzzy search using username and display name
:param username:
:param start:
:param limit:
:param include_inactive_users:
:return:
"""
url = "rest/api/2/user/search?username={username}&includeInactive={include_inactive}&startAt={start}&maxResults={limit}".format(
username=username, include_inactive=include_inactive_users, start=start, limit=limit)
return self.get(url)

def projects(self):
return self.get('/rest/api/2/project')
return self.get('rest/api/2/project')

def project(self, key):
return self.get('/rest/api/2/project/{0}'.format(key))
return self.get('rest/api/2/project/{0}'.format(key))

def get_project_components(self, key):
return self.get('/rest/api/2/project/{0}/components'.format(key))
"""
Get project components using project key
:param key: str
:return:
"""
return self.get('rest/api/2/project/{0}/components'.format(key))

def issue(self, key, fields='*all'):
return self.get('/rest/api/2/issue/{0}?fields={1}'.format(key, fields))
return self.get('rest/api/2/issue/{0}?fields={1}'.format(key, fields))

def issue_field_value(self, key, field):
issue = self.get('/rest/api/2/issue/{0}?fields={1}'.format(key, field))
issue = self.get('rest/api/2/issue/{0}?fields={1}'.format(key, field))
return issue['fields'][field]

def update_issue_field(self, key, fields='*all'):
return self.put('/rest/api/2/issue/{0}'.format(key), data={'fields': fields})
return self.put('rest/api/2/issue/{0}'.format(key), data={'fields': fields})

def project_leaders(self):
for project in self.projects():
@@ -55,7 +73,7 @@ def project_leaders(self):
'lead_email': lead['emailAddress']}

def rename_sprint(self, sprint_id, name, start_date, end_date):
return self.put('/rest/greenhopper/1.0/sprint/{0}'.format(sprint_id), data={
return self.put('rest/greenhopper/1.0/sprint/{0}'.format(sprint_id), data={
'name': name,
'startDate': start_date,
'endDate': end_date})
@@ -90,6 +108,19 @@ def get_all_assignable_users_for_project(self, project_key, start=0, limit=50):
limit=limit)
return self.get(url)

def get_all_users_from_group(self, group, include_inactive_users=False, start=0, limit=50):
"""
Just wrapping method user group members
:param group:
:param include_inactive_users:
:param start:
:param limit:
:return:
"""
url = "rest/api/2/group/member?groupname={group}&includeInactiveUsers={include_inactive}&startAt={start}&maxResults={limit}".format(
group=group, include_inactive=include_inactive_users, start=start, limit=limit)
return self.get(url)

def issue_exists(self, issuekey):
try:
self.issue(issuekey, fields='*none')
@@ -114,12 +145,12 @@ def issue_deleted(self, issuekey):

def issue_update(self, issuekey, fields):
log.warning('Updating issue "{issuekey}" with "{fields}"'.format(issuekey=issuekey, fields=fields))
url = '/rest/api/2/issue/{0}'.format(issuekey)
url = 'rest/api/2/issue/{0}'.format(issuekey)
return self.put(url, data={'fields': fields})

def issue_create(self, fields):
log.warning('Creating issue "{summary}"'.format(summary=fields['summary']))
url = '/rest/api/2/issue/'
url = 'rest/api/2/issue/'
return self.post(url, data={'fields': fields})

def issue_create_or_update(self, fields):
@@ -139,12 +170,12 @@ def issue_create_or_update(self, fields):
return self.issue_update(issuekey, fields)

def get_issue_transitions(self, issuekey):
url = '/rest/api/2/issue/{issuekey}?expand=transitions.fields&fields=status'.format(issuekey=issuekey)
url = 'rest/api/2/issue/{issuekey}?expand=transitions.fields&fields=status'.format(issuekey=issuekey)
return [{'name': transition['name'], 'id': int(transition['id']), 'to': transition['to']['name']}
for transition in self.get(url)['transitions']]

def get_status_id_from_name(self, status_name):
url = '/rest/api/2/status/{name}'.format(name=status_name)
url = 'rest/api/2/status/{name}'.format(name=status_name)
return int(self.get(url)['id'])

def get_transition_id_to_status_name(self, issuekey, status_name):
@@ -156,22 +187,22 @@ def issue_transition(self, issuekey, status):
return self.set_issue_status(issuekey, status)

def set_issue_status(self, issuekey, status_name):
url = '/rest/api/2/issue/{issuekey}/transitions'.format(issuekey=issuekey)
url = 'rest/api/2/issue/{issuekey}/transitions'.format(issuekey=issuekey)
transition_id = self.get_transition_id_to_status_name(issuekey, status_name)
return self.post(url, data={'transition': {'id': transition_id}})

def get_issue_status(self, issuekey):
url = '/rest/api/2/issue/{issuekey}?fields=status'.format(issuekey=issuekey)
url = 'rest/api/2/issue/{issuekey}?fields=status'.format(issuekey=issuekey)
return self.get(url)['fields']['status']['name']

def component(self, componentid):
return self.get('/rest/api/2/component/{componentid}'.format(componentid=componentid))
return self.get('rest/api/2/component/{componentid}'.format(componentid=componentid))

def create_component(self, component):
log.warning('Creating component "{name}"'.format(name=component['name']))
url = '/rest/api/2/component/'
url = 'rest/api/2/component/'
return self.post(url, data=component)

def delete_component(self, componentid):
log.warning('Deleting component "{componentid}"'.format(componentid=componentid))
return self.delete('/rest/api/2/component/{componentid}'.format(componentid=componentid))
return self.delete('rest/api/2/component/{componentid}'.format(componentid=componentid))
@@ -1,3 +1,4 @@
# -*- coding: utf8 -*-
import logging
from .rest_client import AtlassianRestAPI

@@ -1,3 +1,4 @@
# -*- coding: utf8 -*-
import json
import logging
from six.moves.urllib.parse import urlencode, urljoin
@@ -1,3 +1,4 @@
# -*- coding: utf8 -*-
import logging
import re

@@ -1 +1,2 @@
six
requests
@@ -1,5 +1,7 @@
[tox]
envlist = py27, py3
envlist = py27,py3
skip_missing_interpreters = True

[testenv]
deps = pytest
commands = pytest -v

0 comments on commit dc3d2b5

Please sign in to comment.
You can’t perform that action at this time.