From eb5828dadef0698a2bc50b8c361a1908b494f6e9 Mon Sep 17 00:00:00 2001 From: Johannes Wesch Date: Tue, 9 Apr 2024 12:10:12 +0200 Subject: [PATCH] WIP: created Jira Adapter --- poetry.lock | 79 +++++++++++++++++++++++++++++++++++++++++++-- pyproject.toml | 1 + src/jira_adapter.py | 48 +++++++++++++++++++++++++++ 3 files changed, 126 insertions(+), 2 deletions(-) create mode 100644 src/jira_adapter.py diff --git a/poetry.lock b/poetry.lock index 6f70ad904..cfafc0909 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 1.7.1 and should not be changed by hand. +# This file is automatically @generated by Poetry 1.8.2 and should not be changed by hand. [[package]] name = "aiodns" @@ -1715,6 +1715,33 @@ MarkupSafe = ">=2.0" [package.extras] i18n = ["Babel (>=2.7)"] +[[package]] +name = "jira" +version = "3.8.0" +description = "Python library for interacting with JIRA via REST APIs." +optional = false +python-versions = ">=3.8" +files = [ + {file = "jira-3.8.0-py3-none-any.whl", hash = "sha256:12190dc84dad00b8a6c0341f7e8a254b0f38785afdec022bd5941e1184a5a3fb"}, + {file = "jira-3.8.0.tar.gz", hash = "sha256:63719c529a570aaa01c3373dbb5a104dab70381c5be447f6c27f997302fa335a"}, +] + +[package.dependencies] +defusedxml = "*" +packaging = "*" +Pillow = ">=2.1.0" +requests = ">=2.10.0" +requests-oauthlib = ">=1.1.0" +requests-toolbelt = "*" +typing-extensions = ">=3.7.4.2" + +[package.extras] +async = ["requests-futures (>=0.9.7)"] +cli = ["ipython (>=4.0.0)", "keyring"] +docs = ["furo", "sphinx (>=5.0.0)", "sphinx-copybutton"] +opt = ["PyJWT", "filemagic (>=1.6)", "requests-jwt", "requests-kerberos"] +test = ["MarkupSafe (>=0.23)", "PyYAML (>=5.1)", "docutils (>=0.12)", "flaky", "oauthlib", "parameterized (>=0.8.1)", "pytest (>=6.0.0)", "pytest-cache", "pytest-cov", "pytest-instafail", "pytest-sugar", "pytest-timeout (>=1.3.1)", "pytest-xdist (>=2.2)", "requests-mock", "requires.io", "tenacity", "wheel (>=0.24.0)", "yanc (>=0.3.3)"] + [[package]] name = "joblib" version = "1.3.2" @@ -2798,6 +2825,22 @@ files = [ {file = "numpy-1.26.4.tar.gz", hash = "sha256:2a02aba9ed12e4ac4eb3ea9421c420301a0c6460d9830d74a9df87efa4912010"}, ] +[[package]] +name = "oauthlib" +version = "3.2.2" +description = "A generic, spec-compliant, thorough implementation of the OAuth request-signing logic" +optional = false +python-versions = ">=3.6" +files = [ + {file = "oauthlib-3.2.2-py3-none-any.whl", hash = "sha256:8139f29aac13e25d502680e9e19963e83f16838d48a0d71c287fe40e7067fbca"}, + {file = "oauthlib-3.2.2.tar.gz", hash = "sha256:9859c40929662bec5d64f34d01c99e093149682a3f38915dc0655d5a633dd918"}, +] + +[package.extras] +rsa = ["cryptography (>=3.0.0)"] +signals = ["blinker (>=1.4.0)"] +signedtoken = ["cryptography (>=3.0.0)", "pyjwt (>=2.0.0,<3)"] + [[package]] name = "opentelemetry-api" version = "1.23.0" @@ -4195,6 +4238,38 @@ urllib3 = ">=1.21.1,<3" socks = ["PySocks (>=1.5.6,!=1.5.7)"] use-chardet-on-py3 = ["chardet (>=3.0.2,<6)"] +[[package]] +name = "requests-oauthlib" +version = "2.0.0" +description = "OAuthlib authentication support for Requests." +optional = false +python-versions = ">=3.4" +files = [ + {file = "requests-oauthlib-2.0.0.tar.gz", hash = "sha256:b3dffaebd884d8cd778494369603a9e7b58d29111bf6b41bdc2dcd87203af4e9"}, + {file = "requests_oauthlib-2.0.0-py2.py3-none-any.whl", hash = "sha256:7dd8a5c40426b779b0868c404bdef9768deccf22749cde15852df527e6269b36"}, +] + +[package.dependencies] +oauthlib = ">=3.0.0" +requests = ">=2.0.0" + +[package.extras] +rsa = ["oauthlib[signedtoken] (>=3.0.0)"] + +[[package]] +name = "requests-toolbelt" +version = "1.0.0" +description = "A utility belt for advanced users of python-requests" +optional = false +python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" +files = [ + {file = "requests-toolbelt-1.0.0.tar.gz", hash = "sha256:7681a0a3d047012b5bdc0ee37d7f8f07ebe76ab08caeccfc3921ce23c88d5bc6"}, + {file = "requests_toolbelt-1.0.0-py2.py3-none-any.whl", hash = "sha256:cccfdd665f0a24fcf4726e690f65639d272bb0637b9b92dfd91a5568ccf6bd06"}, +] + +[package.dependencies] +requests = ">=2.0.1,<3.0.0" + [[package]] name = "rfc3339-validator" version = "0.1.4" @@ -5558,4 +5633,4 @@ testing = ["big-O", "jaraco.functools", "jaraco.itertools", "more-itertools", "p [metadata] lock-version = "2.0" python-versions = ">=3.10,<3.12" -content-hash = "8f09d7bebe2ac44c5ee721c61667417847fd46a6e4597919f508ac5abf6e1d99" +content-hash = "ffdd50431e8ddc178b9b2338ed1143bbcf13601137cda5becda7afd0e2815b8b" diff --git a/pyproject.toml b/pyproject.toml index dfcaf4353..f3bee5c75 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -33,6 +33,7 @@ opentelemetry-api = "^1.22.0" opentelemetry-sdk = "^1.22.0" huggingface-hub = "^0.22.2" opentelemetry-exporter-otlp-proto-http = "1.23.0" +jira = "^3.8.0" [tool.poetry.group.dev.dependencies] # lint & format diff --git a/src/jira_adapter.py b/src/jira_adapter.py new file mode 100644 index 000000000..9793697c8 --- /dev/null +++ b/src/jira_adapter.py @@ -0,0 +1,48 @@ +import os +from typing import Sequence +from dotenv import load_dotenv +from jira import JIRA, Issue + + +class Ticket(): + jira_id: str + text: str + labels: Sequence[str] + is_active: bool + + + +class JiraAdapater(): + def __init__(self, domain: str, email: str, token: str): + self.jira = JIRA(domain, basic_auth=(email, token)) + + def get_tickets(self, project_id: str) -> Sequence[Ticket]: + issues = jira_adapter.jira.search_issues(f'project={project_id}') + return [self.issue_to_ticket(issue) for issue in issues] + + def get_tickets_by_id(project_id: str, ticket_ids: Sequence[str]) -> Sequence[Ticket]: + pass + + def update_ticket(self, ticket_id: str, new_label: str) -> bool: + pass + + def issue_to_ticket(self, issue: Issue) -> Ticket: + return Ticket( + jira_id = issue.id, + text = issue.fields.summary + issue.fields.description, + labels = issue.fields.labels, + is_active = issue.fields.status == "Done" # TODO + + ) + + + + +if __name__ == "__main__": + load_dotenv() + token = os.getenv("JIRA_TOKEN") + email = os.getenv("JIRA_EMAIL") + domain = 'https://aleph-alpha.atlassian.net' + jira_adapter = JiraAdapater(domain, email, token) + issue_retrieved = jira_adapter.jira.search_issues('project=IL AND issue=22475')[0] + issue = jira_adapter.jira.issue(id = issue_retrieved.id)