omkarkhatavkar / jirasync

This CLI tool to sync and track GitHub issues, pr's, pr_reviews with Jira. Currently supported to only for create, update and close status.
MIT License
4 stars 3 forks source link

Extract search query into a shared function #2

Closed rochacbruno closed 5 years ago

rochacbruno commented 5 years ago

This query: https://github.com/rochacbruno/jirasync/blob/redmine/plugins/redmine.py#L46-L50

can be shared across plugins (redmine/github) so the idea is to extract this query in a function or constant.

idea:

Encapsulate the method inside the JiraWrapper

jirawrapper.py

class MyJiraWrapper(JiraWrapper):
    ...
    def search_existing_task(self, issue_text, assignee=None):
        # check if it already exists
        search_query = (
            'project = {} '
            'AND status != Done '
            'AND summary ~ \\"{}\\"'
        ).format(
            self.project_id,
            assignee,
            issue_text.replace('#', '\u0023')
        )
       if assignee is not None:
           search_query = search_query + " AND assignee = {}".format(assignee)
        echo(
            "Searching Jira for {0} using query [{1}]".format(
                issue_text, search_query
            )
        )
        tasks = self.jira.search_issues(
            search_query
        )
        task_count = len(tasks)
        echo("Found {}: {}".format(task_count, tasks))
       return tasks 

and then wherever we have a jira wrapper instance we can call this method passing issue_text and assignee information.

rochacbruno commented 5 years ago

The assignee must be optional to build the query see: #6