Example #1
0
# -*- coding: utf-8 -*-

from taiga import TaigaAPI
from taiga.exceptions import TaigaException

api = TaigaAPI(
    host='http://127.0.0.1:8000'
)

api.auth(
    username='******',
    password='******'
)

print (api.me())

new_project = api.projects.create('TEST PROJECT', 'TESTING API')

new_project.name = 'TEST PROJECT 3'
new_project.update()

print (new_project.members)

for member in new_project.members:
    print (member)

jan_feb_milestone = new_project.add_milestone(
    'New milestone jan feb', '2015-01-26', '2015-02-26'
)

userstory = new_project.add_user_story(
Example #2
0
def manage_issue(module,
                 taiga_host,
                 project_name,
                 issue_subject,
                 issue_priority,
                 issue_status,
                 issue_type,
                 issue_severity,
                 issue_description,
                 issue_attachment,
                 issue_attachment_description,
                 issue_tags,
                 state,
                 check_mode=False):
    """
    Method that creates/deletes issues depending whether they exist and the state desired

    The credentials should be passed via environment variables:
        - TAIGA_TOKEN
        - TAIGA_USERNAME and TAIGA_PASSWORD

    Returns a tuple with these elements:
        - A boolean representing the success of the operation
        - A descriptive message
        - A dict with the issue attributes, in case of issue creation, otherwise empty dict
    """

    changed = False

    try:
        token = getenv('TAIGA_TOKEN')
        if token:
            api = TaigaAPI(host=taiga_host, token=token)
        else:
            api = TaigaAPI(host=taiga_host)
            username = getenv('TAIGA_USERNAME')
            password = getenv('TAIGA_PASSWORD')
            if not any([username, password]):
                return (False, changed, "Missing credentials", {})
            api.auth(username=username, password=password)

        user_id = api.me().id
        project_list = filter(lambda x: x.name == project_name,
                              api.projects.list(member=user_id))
        if len(project_list) != 1:
            return (False, changed, "Unable to find project %s" % project_name,
                    {})
        project = project_list[0]
        project_id = project.id

        priority_list = filter(lambda x: x.name == issue_priority,
                               api.priorities.list(project=project_id))
        if len(priority_list) != 1:
            return (False, changed,
                    "Unable to find issue priority %s for project %s" %
                    (issue_priority, project_name), {})
        priority_id = priority_list[0].id

        status_list = filter(lambda x: x.name == issue_status,
                             api.issue_statuses.list(project=project_id))
        if len(status_list) != 1:
            return (False, changed,
                    "Unable to find issue status %s for project %s" %
                    (issue_status, project_name), {})
        status_id = status_list[0].id

        type_list = filter(lambda x: x.name == issue_type,
                           project.list_issue_types())
        if len(type_list) != 1:
            return (False, changed,
                    "Unable to find issue type %s for project %s" %
                    (issue_type, project_name), {})
        type_id = type_list[0].id

        severity_list = filter(lambda x: x.name == issue_severity,
                               project.list_severities())
        if len(severity_list) != 1:
            return (False, changed,
                    "Unable to find severity %s for project %s" %
                    (issue_severity, project_name), {})
        severity_id = severity_list[0].id

        issue = {
            "project": project_name,
            "subject": issue_subject,
            "priority": issue_priority,
            "status": issue_status,
            "type": issue_type,
            "severity": issue_severity,
            "description": issue_description,
            "tags": issue_tags,
        }

        # An issue is identified by the project_name, the issue_subject and the issue_type
        matching_issue_list = filter(
            lambda x: x.subject == issue_subject and x.type == type_id,
            project.list_issues())
        matching_issue_list_len = len(matching_issue_list)

        if matching_issue_list_len == 0:
            # The issue does not exist in the project
            if state == "present":
                # This implies a change
                changed = True
                if not check_mode:
                    # Create the issue
                    new_issue = project.add_issue(
                        issue_subject,
                        priority_id,
                        status_id,
                        type_id,
                        severity_id,
                        tags=issue_tags,
                        description=issue_description)
                    if issue_attachment:
                        new_issue.attach(
                            issue_attachment,
                            description=issue_attachment_description)
                        issue["attachment"] = issue_attachment
                        issue[
                            "attachment_description"] = issue_attachment_description
                return (True, changed, "Issue created", issue)

            else:
                # If does not exist, do nothing
                return (True, changed, "Issue does not exist", {})

        elif matching_issue_list_len == 1:
            # The issue exists in the project
            if state == "absent":
                # This implies a change
                changed = True
                if not check_mode:
                    # Delete the issue
                    matching_issue_list[0].delete()
                return (True, changed, "Issue deleted", {})

            else:
                # Do nothing
                return (True, changed, "Issue already exists", {})

        else:
            # More than 1 matching issue
            return (False, changed,
                    "More than one issue with subject %s in project %s" %
                    (issue_subject, project_name), {})

    except TaigaException as exc:
        msg = "An exception happened: %s" % to_native(exc)
        return (False, changed, msg, {})
from taiga import TaigaAPI
from settings import USER, PASS

api = TaigaAPI()
api.auth( username=USER, password=PASS)

me = api.me()

#Search for the members of all your projects
members = []
projects = api.projects.list(member=me.id)
for project in projects: 
	members += project.members

#Get the username of the members
for user_id in list(set(members)):
	user = api.users.get(user_id)
	print "({1}) {0}".format(user.username, user.id)
Example #4
0
 def test_me(self, mock_user_get):
     rm = RequestMaker('/api/v1', 'fakehost', 'faketoken')
     mock_user_get.return_value = User(rm, full_name='Andrea')
     api = TaigaAPI(token='f4k3')
     user = api.me()
     self.assertEqual(user.full_name, 'Andrea')
Example #5
0
 def test_me(self, mock_user_get):
     rm = RequestMaker("/api/v1", "fakehost", "faketoken")
     mock_user_get.return_value = User(rm, full_name="Andrea")
     api = TaigaAPI(token="f4k3")
     user = api.me()
     self.assertEqual(user.full_name, "Andrea")
Example #6
0
def manage_issue(
    module,
    taiga_host,
    project_name,
    issue_subject,
    issue_priority,
    issue_status,
    issue_type,
    issue_severity,
    issue_description,
    issue_attachment,
    issue_attachment_description,
    issue_tags,
    state,
    check_mode=False,
):
    """
    Method that creates/deletes issues depending whether they exist and the state desired

    The credentials should be passed via environment variables:
        - TAIGA_TOKEN
        - TAIGA_USERNAME and TAIGA_PASSWORD

    Returns a tuple with these elements:
        - A boolean representing the success of the operation
        - A descriptive message
        - A dict with the issue attributes, in case of issue creation, otherwise empty dict
    """

    changed = False

    try:
        token = getenv("TAIGA_TOKEN")
        if token:
            api = TaigaAPI(host=taiga_host, token=token)
        else:
            api = TaigaAPI(host=taiga_host)
            username = getenv("TAIGA_USERNAME")
            password = getenv("TAIGA_PASSWORD")
            if not any([username, password]):
                return (False, changed, "Missing credentials", {})
            api.auth(username=username, password=password)

        user_id = api.me().id
        project_list = filter(lambda x: x.name == project_name, api.projects.list(member=user_id))
        if len(project_list) != 1:
            return (False, changed, "Unable to find project %s" % project_name, {})
        project = project_list[0]
        project_id = project.id

        priority_list = filter(lambda x: x.name == issue_priority, api.priorities.list(project=project_id))
        if len(priority_list) != 1:
            return (
                False,
                changed,
                "Unable to find issue priority %s for project %s" % (issue_priority, project_name),
                {},
            )
        priority_id = priority_list[0].id

        status_list = filter(lambda x: x.name == issue_status, api.issue_statuses.list(project=project_id))
        if len(status_list) != 1:
            return (False, changed, "Unable to find issue status %s for project %s" % (issue_status, project_name), {})
        status_id = status_list[0].id

        type_list = filter(lambda x: x.name == issue_type, project.list_issue_types())
        if len(type_list) != 1:
            return (False, changed, "Unable to find issue type %s for project %s" % (issue_type, project_name), {})
        type_id = type_list[0].id

        severity_list = filter(lambda x: x.name == issue_severity, project.list_severities())
        if len(severity_list) != 1:
            return (False, changed, "Unable to find severity %s for project %s" % (issue_severity, project_name), {})
        severity_id = severity_list[0].id

        issue = {
            "project": project_name,
            "subject": issue_subject,
            "priority": issue_priority,
            "status": issue_status,
            "type": issue_type,
            "severity": issue_severity,
            "description": issue_description,
            "tags": issue_tags,
        }

        # An issue is identified by the project_name, the issue_subject and the issue_type
        matching_issue_list = filter(lambda x: x.subject == issue_subject and x.type == type_id, project.list_issues())
        matching_issue_list_len = len(matching_issue_list)

        if matching_issue_list_len == 0:
            # The issue does not exist in the project
            if state == "present":
                # This implies a change
                changed = True
                if not check_mode:
                    # Create the issue
                    new_issue = project.add_issue(
                        issue_subject,
                        priority_id,
                        status_id,
                        type_id,
                        severity_id,
                        tags=issue_tags,
                        description=issue_description,
                    )
                    if issue_attachment:
                        new_issue.attach(issue_attachment, description=issue_attachment_description)
                        issue["attachment"] = issue_attachment
                        issue["attachment_description"] = issue_attachment_description
                return (True, changed, "Issue created", issue)

            else:
                # If does not exist, do nothing
                return (True, changed, "Issue does not exist", {})

        elif matching_issue_list_len == 1:
            # The issue exists in the project
            if state == "absent":
                # This implies a change
                changed = True
                if not check_mode:
                    # Delete the issue
                    matching_issue_list[0].delete()
                return (True, changed, "Issue deleted", {})

            else:
                # Do nothing
                return (True, changed, "Issue already exists", {})

        else:
            # More than 1 matching issue
            return (
                False,
                changed,
                "More than one issue with subject %s in project %s" % (issue_subject, project_name),
                {},
            )

    except TaigaException:
        msg = "An exception happened: %s" % sys.exc_info()[1]
        return (False, changed, msg, {})
Example #7
0
# -*- coding: utf-8 -*-

from taiga import TaigaAPI
from taiga.exceptions import TaigaException

api = TaigaAPI(host='http://127.0.0.1:8000')

api.auth(username='******', password='******')

print(api.me())

new_project = api.projects.create('TEST PROJECT', 'TESTING API')

new_project.name = 'TEST PROJECT 3'
new_project.update()

print(new_project.members)

for member in new_project.members:
    print(member)

jan_feb_milestone = new_project.add_milestone('New milestone jan feb',
                                              '2015-01-26', '2015-02-26')

userstory = new_project.add_user_story('New Story',
                                       description='Blablablabla',
                                       milestone=jan_feb_milestone.id)
userstory.attach('README.md')

userstory.add_task('New Task 2',
                   new_project.task_statuses[0].id).attach('README.md')