def test_run_with_reopening_existing_parent_issue(self, *args):
   """
   Test JiraManager.run on reopening a parent issue.
   Expect: jira.reopen_issue is called once.
   """
   dep_name = 'group0:artifact0'
   owners_yaml = """
                 deps:
                   group0:artifact0:
                     group: group0
                     artifact: artifact0
                     owners: owner0
                 """
   summary = self._get_experct_summary('group0')
   description = self._get_expected_description(dep_name, MOCKED_DEP_LATEST_VERSION, [])
   with patch('__builtin__.open', mock_open(read_data=owners_yaml)):
     with patch('jira_utils.jira_manager.JiraManager._search_issues',
       side_effect = [[MockedJiraIssue('BEAM-1000', summary, description, 'Closed')],
                     []]):
       manager = JiraManager('url', 'username', 'password', owners_yaml)
       manager.run(dep_name,
                   MOCKED_DEP_CURRENT_VERSION,
                   MOCKED_DEP_LATEST_VERSION,
                   sdk_type='Java',
                   group_id='group0')
       manager.jira.reopen_issue.assert_called_once()
  def test_run_with_creating_new_subtask(self, *args):
    """
    Test JiraManager.run on creating a new sub-task.
    Expect: jira.create_issue is called once with certain parameters.
    """
    dep_name = 'group0:artifact0'
    dep_latest_version = '1.0'
    owners_yaml = """
                  deps:
                    group0:artifact0:
                      group: group0
                      artifact: artifact0
                      owners: owner0
                  """
    summary = self._get_experct_summary('group0', None)
    description = self._get_expected_description(dep_name, dep_latest_version, [])

    with patch('__builtin__.open', mock_open(read_data=owners_yaml)):
      with patch('jira_utils.jira_manager.JiraManager._search_issues',
        side_effect = [[MockedJiraIssue('BEAM-1000', summary, description, 'Open')],
                      []]):
        manager = JiraManager('url', 'username', 'password', owners_yaml)
        manager.run(dep_name, dep_latest_version, 'Java', group_id='group0')
        manager.jira.create_issue.assert_called_once_with(self._get_experct_summary(dep_name, dep_latest_version),
                                                          ['dependencies'],
                                                          self._get_expected_description(dep_name, dep_latest_version, []),
                                                          assignee='owner0',
                                                          parent_key='BEAM-1000',
                                                          )
 def test_run_with_reopening_existing_parent_issue(self, *args):
     """
 Test JiraManager.run on reopening a parent issue.
 Expect: jira.reopen_issue is called once.
 """
     dep_name = 'group0:artifact0'
     dep_latest_version = '1.0'
     owners_yaml = """
               deps:
                 group0:artifact0:
                   group: group0
                   artifact: artifact0
                   owners: owner0
               """
     summary = self._get_experct_summary('group0', None)
     description = self._get_expected_description(dep_name,
                                                  dep_latest_version, [])
     with patch('__builtin__.open', mock_open(read_data=owners_yaml)):
         with patch('jira_utils.jira_manager.JiraManager._search_issues',
                    side_effect=[[
                        MockedJiraIssue('BEAM-1000', summary, description,
                                        'Closed')
                    ], []]):
             manager = JiraManager('url', 'username', 'password',
                                   owners_yaml)
             manager.run(dep_name,
                         dep_latest_version,
                         sdk_type='Java',
                         group_id='group0')
             manager.jira.reopen_issue.assert_called_once()
    def test_run_with_updating_existing_task(self, *args):
        """
    Test JiraManager.run on updating an existing issue.
    Expect: jira.update_issue is called once.
    """
        dep_name = 'dep0'
        dep_latest_version = '1.0'
        owners_yaml = """
                  deps:
                    dep0:
                      owners:
                  """
        summary = self._get_experct_summary(dep_name, dep_latest_version)
        description = self._get_expected_description(dep_name,
                                                     dep_latest_version, [])

        with patch('__builtin__.open', mock_open(read_data=owners_yaml)):
            with patch('jira_utils.jira_manager.JiraManager._search_issues',
                       return_value=[
                           MockedJiraIssue('BEAM-1000', summary, description,
                                           'Open')
                       ]):
                manager = JiraManager('url', 'username', 'password',
                                      owners_yaml)
                manager.run(dep_name, dep_latest_version, 'Python')
                manager.jira.update_issue.assert_called_once()
Exemple #5
0
 def test_run_with_reopening_issue_with_new_release_available(self, *args):
     """
 Test JiraManager.run that reopens an issue once 3 versions releases after 6
 months since previous closure.
 Expect: jira.reopen_issue is called once.
 """
     dep_name = 'dep0'
     issue_closed_version = '1.0'
     dep_latest_version = '1.3'
     owners_yaml = """
                 deps:
                   dep0:
                     owners:
                 """
     summary = self._get_experct_summary(dep_name)
     description = self._get_expected_description(dep_name,
                                                  issue_closed_version, [])
     with patch('__builtin__.open', mock_open(read_data=owners_yaml)):
         with patch('jira_utils.jira_manager.JiraManager._search_issues',
                    side_effect=[[
                        MockedJiraIssue('BEAM-1000', summary, description,
                                        'Closed')
                    ], []]):
             manager = JiraManager('url', 'username', 'password',
                                   owners_yaml)
             manager.run(dep_name, MOCKED_DEP_CURRENT_VERSION,
                         dep_latest_version, 'Python')
             manager.jira.reopen_issue.assert_called_once()
Exemple #6
0
 def test_run_with_reopening_issue_with_fixversions(self, *args):
     """
 Test JiraManager.run on reopening an issue when JIRA fixVersions hits the release version.
 Expect: jira.reopen_issue is called once.
 """
     dep_name = 'dep0'
     owners_yaml = """
               deps:
                 dep0:
                   owners:
               """
     summary = self._get_experct_summary(dep_name)
     description = self._get_expected_description(
         dep_name, MOCKED_DEP_LATEST_VERSION, [])
     with patch('__builtin__.open', mock_open(read_data=owners_yaml)):
         with patch('jira_utils.jira_manager.JiraManager._search_issues',
                    side_effect=[[
                        MockedJiraIssue('BEAM-1000', summary, description,
                                        'Closed')
                    ], []]):
             manager = JiraManager('url', 'username', 'password',
                                   owners_yaml)
             manager.run(dep_name, MOCKED_DEP_CURRENT_VERSION,
                         MOCKED_DEP_LATEST_VERSION, 'Python')
             manager.jira.reopen_issue.assert_called_once()
 def test_run_with_reopening_issue_with_new_release_available(self, *args):
   """
   Test JiraManager.run that reopens an issue once 3 versions releases after 6
   months since previous closure.
   Expect: jira.reopen_issue is called once.
   """
   dep_name = 'dep0'
   issue_closed_version = '1.0'
   dep_latest_version = '1.3'
   owners_yaml = """
                   deps:
                     dep0:
                       owners:
                   """
   summary = self._get_experct_summary(dep_name)
   description = self._get_expected_description(dep_name, issue_closed_version, [])
   with patch('__builtin__.open', mock_open(read_data=owners_yaml)):
     with patch('jira_utils.jira_manager.JiraManager._search_issues',
                side_effect = [[MockedJiraIssue('BEAM-1000', summary, description, 'Closed')],
                               []]):
       manager = JiraManager('url', 'username', 'password', owners_yaml)
       manager.run(dep_name,
                   MOCKED_DEP_CURRENT_VERSION,
                   dep_latest_version,
                   'Python')
       manager.jira.reopen_issue.assert_called_once()
 def __init__(self):
     meta_db = config['ora_dcm']
     connection_string = "{0}/{1}@{2}:{3}/{4}".format(
         meta_db['user'], meta_db['pwd'], meta_db['host'], meta_db['port'],
         meta_db['sid'])
     self.db_manager = DBManager(connection_string)
     self.jira = JiraManager(config['jira'])
     schedule.every(1).minute.do(self.__job)
Exemple #9
0
def sync_issue(issue_code: str):
    """ Reads the given issue from Jira and transfers to Notion """
    my_config = Config()
    my_jira_manager = JiraManager(my_config)
    my_notion_manager = NotionManager(my_config)

    issue = my_jira_manager.get_issue(issue_code)
    my_notion_manager.create_page(issue, my_jira_manager)
    sys.exit(0)
 def test_find_owners_with_single_owner(self, *args):
   """
   Test on _find_owners with single owner
   Expect: the primary owner is 'owner0', an empty list of other owners.
   """
   owners_yaml = """
                 deps:
                   dep0:
                     owners: owner0,
                 """
   with patch('__builtin__.open', mock_open(read_data=owners_yaml)):
     manager = JiraManager('url', 'username', 'password', owners_yaml)
     primary, owners = manager._find_owners('dep0')
     self.assertEqual(primary, 'owner0')
     self.assertEqual(len(owners), 0)
 def test_find_owners_with_single_owner(self, *args):
     """
 Test on _find_owners with single owner
 Expect: the primary owner is 'owner0', an empty list of other owners.
 """
     owners_yaml = """
               deps:
                 dep0:
                   owners: owner0,
               """
     with patch('__builtin__.open', mock_open(read_data=owners_yaml)):
         manager = JiraManager('url', 'username', 'password', owners_yaml)
         primary, owners = manager._find_owners('dep0')
         self.assertEqual(primary, 'owner0')
         self.assertEqual(len(owners), 0)
 def test_find_owners_with_no_dep_defined(self, *args):
     """
 Test on _find_owners with non-defined dep.
 Expect: through out KeyErrors. The primary owner is None, an empty list of other owners.
 """
     owners_yaml = """
               deps:
                 dep0:
                   owners:
               """
     with patch('__builtin__.open', mock_open(read_data=owners_yaml)):
         manager = JiraManager('url', 'username', 'password', owners_yaml)
         primary, owners = manager._find_owners('dep1')
         self.assertIsNone(primary)
         self.assertEqual(len(owners), 0)
 def test_find_owners_with_no_owners_defined(self, *args):
   """
   Test on _find_owners without owner.
   Expect: the primary owner is None, an empty list of other owners.
   """
   owners_yaml = """
                 deps:
                   dep0:
                     owners:
                 """
   with patch('__builtin__.open', mock_open(read_data=owners_yaml)):
     manager = JiraManager('url', 'username', 'password', owners_yaml)
     primary, owners = manager._find_owners('dep0')
     self.assertIsNone(primary)
     self.assertEqual(len(owners), 0)
 def test_run_with_creating_new_issue(self, *args):
   """
   Test JiraManager.run on creating a new issue.
   Expect: jira.create_issue is called once with certain parameters.
   """
   owners_yaml = """
                 deps:
                   dep0:
                     owners: owner0, owner1 , owner2,
                 """
   with patch('__builtin__.open', mock_open(read_data=owners_yaml)):
     manager = JiraManager('url', 'username', 'password', owners_yaml)
     manager.run('dep0', '1.0', 'Python')
     manager.jira.create_issue.assert_called_once_with(self._get_experct_summary('dep0', '1.0'),
                                                       ['dependencies'],
                                                       self._get_expected_description('dep0', '1.0', ['owner1', 'owner2']),
                                                       assignee='owner0')
 def test_find_owners_with_multi_owners(self, *args):
   """
   Test on _find_owners with multiple owners.
   Expect: the primary owner is 'owner0', a list contains 'owner1' and 'owner2'.
   """
   owners_yaml = """
                 deps:
                   dep0:
                     owners: owner0, owner1 , owner2,
                 """
   with patch('__builtin__.open', mock_open(read_data=owners_yaml)):
     manager = JiraManager('url', 'username', 'password', owners_yaml)
     primary, owners = manager._find_owners('dep0')
     self.assertEqual(primary, 'owner0')
     self.assertEqual(len(owners), 2)
     self.assertIn('owner1', owners)
     self.assertIn('owner2', owners)
 def test_find_owners_with_multi_owners(self, *args):
     """
 Test on _find_owners with multiple owners.
 Expect: the primary owner is 'owner0', a list contains 'owner1' and 'owner2'.
 """
     owners_yaml = """
               deps:
                 dep0:
                   owners: owner0, owner1 , owner2,
               """
     with patch('__builtin__.open', mock_open(read_data=owners_yaml)):
         manager = JiraManager('url', 'username', 'password', owners_yaml)
         primary, owners = manager._find_owners('dep0')
         self.assertEqual(primary, 'owner0')
         self.assertEqual(len(owners), 2)
         self.assertIn('owner1', owners)
         self.assertIn('owner2', owners)
 def test_run_with_creating_new_issue(self, *args):
     """
 Test JiraManager.run on creating a new issue.
 Expect: jira.create_issue is called once with certain parameters.
 """
     owners_yaml = """
               deps:
                 dep0:
                   owners: owner0, owner1 , owner2,
               """
     with patch('__builtin__.open', mock_open(read_data=owners_yaml)):
         manager = JiraManager('url', 'username', 'password', owners_yaml)
         manager.run('dep0', '1.0', 'Python')
         manager.jira.create_issue.assert_called_once_with(
             self._get_experct_summary('dep0', '1.0'), ['dependencies'],
             self._get_expected_description('dep0', '1.0',
                                            ['owner1', 'owner2']),
             assignee='owner0')
Exemple #18
0
def main():
    jira = JiraManager()
    jira_connection = jira.start_connection()
    issues_of_proj = jira.get_issues_of_proj(jira_connection)

    sprint_name = jira.get_sprint_name(jira_connection, issues_of_proj[0])
    report = Report()
    tasks, developers = report.parse_issues_and_developers(issues_of_proj)
    tasks_per_developer = report.get_issues_per_developer(tasks, developers)

    start_date = date.today() + timedelta(
        7)  #It does not exist a start_date for sprints that dont are running
    #sprint_name = 'Sprint 3'

    doc_manager = DocsManager()
    doc = doc_manager.create_doc(sprint_name)
    doc_manager.share_doc(doc)
    worksheet = doc_manager.insert_labels(doc, sprint_name, start_date)
    doc_manager.insert_data_in_doc(worksheet, tasks_per_developer)
class NotifyJiraService(object):
    def __init__(self):
        meta_db = config['ora_dcm']
        connection_string = "{0}/{1}@{2}:{3}/{4}".format(
            meta_db['user'], meta_db['pwd'], meta_db['host'], meta_db['port'],
            meta_db['sid'])
        self.db_manager = DBManager(connection_string)
        self.jira = JiraManager(config['jira'])
        schedule.every(1).minute.do(self.__job)

    def run(self):
        while True:
            schedule.run_pending()
            time.sleep(1)

    def __job(self):
        for cs in self.db_manager.get_cs():
            print(cs)
            self.jira.create_issue(cs)
            self.db_manager.update_flag(cs)
            print('done upd')
  def test_run_with_updating_existing_task(self, *args):
    """
    Test JiraManager.run on updating an existing issue.
    Expect: jira.update_issue is called once.
    """
    dep_name = 'dep0'
    dep_latest_version = '1.0'
    owners_yaml = """
                  deps:
                    dep0:
                      owners:
                  """
    summary = self._get_experct_summary(dep_name, dep_latest_version)
    description = self._get_expected_description(dep_name, dep_latest_version, [])

    with patch('__builtin__.open', mock_open(read_data=owners_yaml)):
      with patch('jira_utils.jira_manager.JiraManager._search_issues',
        return_value=[MockedJiraIssue('BEAM-1000', summary, description, 'Open')]):
        manager = JiraManager('url', 'username', 'password', owners_yaml)
        manager.run(dep_name, dep_latest_version, 'Python')
        manager.jira.update_issue.assert_called_once()
    def test_run_with_creating_new_subtask(self, *args):
        """
    Test JiraManager.run on creating a new sub-task.
    Expect: jira.create_issue is called once with certain parameters.
    """
        dep_name = 'group0:artifact0'
        dep_latest_version = '1.0'
        owners_yaml = """
                  deps:
                    group0:artifact0:
                      group: group0
                      artifact: artifact0
                      owners: owner0
                  """
        summary = self._get_experct_summary('group0', None)
        description = self._get_expected_description(dep_name,
                                                     dep_latest_version, [])

        with patch('__builtin__.open', mock_open(read_data=owners_yaml)):
            with patch('jira_utils.jira_manager.JiraManager._search_issues',
                       side_effect=[[
                           MockedJiraIssue('BEAM-1000', summary, description,
                                           'Open')
                       ], []]):
                manager = JiraManager('url', 'username', 'password',
                                      owners_yaml)
                manager.run(dep_name,
                            dep_latest_version,
                            'Java',
                            group_id='group0')
                manager.jira.create_issue.assert_called_once_with(
                    self._get_experct_summary(dep_name, dep_latest_version),
                    ['dependencies'],
                    self._get_expected_description(dep_name,
                                                   dep_latest_version, []),
                    assignee='owner0',
                    parent_key='BEAM-1000',
                )
 def test_run_with_reopening_issue_with_fixversions(self, *args):
   """
   Test JiraManager.run on reopening an issue when JIRA fixVersions hits the release version.
   Expect: jira.reopen_issue is called once.
   """
   dep_name = 'dep0'
   owners_yaml = """
                 deps:
                   dep0:
                     owners:
                 """
   summary = self._get_experct_summary(dep_name)
   description = self._get_expected_description(dep_name, MOCKED_DEP_LATEST_VERSION, [])
   with patch('__builtin__.open', mock_open(read_data=owners_yaml)):
     with patch('jira_utils.jira_manager.JiraManager._search_issues',
                side_effect = [[MockedJiraIssue('BEAM-1000', summary, description, 'Closed')],
                               []]):
       manager = JiraManager('url', 'username', 'password', owners_yaml)
       manager.run(dep_name,
                   MOCKED_DEP_CURRENT_VERSION,
                   MOCKED_DEP_LATEST_VERSION,
                   'Python')
       manager.jira.reopen_issue.assert_called_once()
Exemple #23
0
    def create_page(self,
                    issue: Issue,
                    jira_man: JiraManager,
                    with_comments: bool = False):
        """ Creation of a new Notion page """
        try:
            title_key = issue.fields.parent.key
        except Exception:
            title_key = issue.key

        title = title_key + " - " + issue.fields.summary

        subpage = self._page.children.add_new(PageBlock, title=title)

        subpage.children.add_new(BookmarkBlock,
                                 link=jira_man.get_url(issue.key),
                                 title=issue.key,
                                 description=issue.fields.summary)
        subpage.children.add_new(TextBlock, title=issue.fields.description)
        subpage.children.add_new(DividerBlock)
        subpage.children.add_new(HeaderBlock, title="İşler")
        subpage.children.add_new(TodoBlock, title="...")
        subpage.children.add_new(DividerBlock)
        subpage.children.add_new(HeaderBlock,
                                 title="Bittiğinde Jira'ya yazılacak")
        subpage.children.add_new(SubheaderBlock, title="Request notu")
        subpage.children.add_new(TextBlock, title="...")
        subpage.children.add_new(SubheaderBlock, title="Soft Config")
        subpage.children.add_new(TextBlock, title="...")
        subpage.children.add_new(SubheaderBlock, title="Yorum")
        subpage.children.add_new(TextBlock, title="...")

        if with_comments:
            subpage.children.add_new(DividerBlock)
            subpage.children.add_new(HeaderBlock, title="Mevcut yorumlar")

            for i in range(self._config.notion_comment_count):
                comment_idx = issue.fields.comment.total - 1 - i
                if comment_idx < 0:
                    break
                current_comment = issue.fields.comment.comments[comment_idx]
                subpage.children.add_new(QuoteBlock,
                                         title=current_comment.body)
                subpage.children.add_new(DividerBlock)
Exemple #24
0
from temp_file import TempFile
from subprocess import call
import os

##############################
# Initialization
##############################

my_config = config.Config()

##############################
# Read issue from Jira
##############################

url = sys.argv[1]
my_jira = JiraManager(my_config)
issue = my_jira.get_issue_by_url(url)

##############################
# Download temp file
##############################

my_temp_file = TempFile(my_config, my_jira)
my_temp_file.write_file(issue, url)

##############################
# Create new Apple Note
##############################

path = os.path.dirname(os.path.abspath(__file__)).replace(" ", "\ ")
path = os.path.join(path, "tmp2note.app")
Exemple #25
0
from config import Config
from notion_manager import NotionManager
from jira_manager import JiraManager
import sys

desired_issue = sys.argv[1]
#desired_issue="VOL-6370"

my_config = Config()
my_jira_manager = JiraManager(my_config)
my_notion_manager = NotionManager(my_config)

issue = my_jira_manager.get_issue(desired_issue)
my_notion_manager.create_page(issue, my_jira_manager)
Exemple #26
0
    def create_note(self, issue: Issue, jira_man: JiraManager):

        # ______________________________
        # Note object

        note = ttypes.Note()
        note.notebookGuid = self._notebook.guid

        # ______________________________
        # Attributes

        issue_url = jira_man.get_url(issue.key)
        note.attributes = ttypes.NoteAttributes(sourceURL=issue_url)
        note.tagNames = self._config.evernote_tags

        # ______________________________
        # Title

        try:
            note.title = issue.fields.parent.key + " - " + self._get_safe_text(issue.fields.summary)
        except:
            note.title = issue.key + " - " + self._get_safe_text(issue.fields.summary)

        # ______________________________
        # Body

        # Header

        body = '<?xml version="1.0" encoding="UTF-8"?>'
        body += '<!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd">'
        body += '<en-note>'

        # URL

        body += 'Madde: <a href="' + issue_url + '">' + issue_url + '</a><br/>'
        try:
            parent_url = jira_man.get_url(issue.fields.parent.key)
            body += 'Üst madde: <a href="' + parent_url + '">' + parent_url + '</a><br/>'
        except:
            pass

        # Summary

        summary = ""

        try:
            summary = self._get_safe_text(issue.fields.summary)
        except:
            pass

        try:
            summary2 = self._get_safe_text(issue.fields.description)
            summary += "<br/><br/>" + summary2
        except:
            pass

        body += '<br/>' + summary + '<br/><br/>'

        # To do

        body += '<hr/><b>İşler</b><br/><br/>'
        body += '<en-todo/>Jira''yı ilerlet<br/><br/>'
        body += '<en-todo/>Geliştirme<br/><br/>'
        body += '<en-todo/>EPC + Task Release<br/><br/>'
        body += '<en-todo/>Teknik test<br/><br/>'
        body += '<en-todo/>Jira''yı ilerlet ve yorum yaz<br/><br/>'

        # Comments

        for i in range(self._config.evernote_comment_count):
            comment_idx = issue.fields.comment.total - 1 - i
            if comment_idx < 0:
                break
            if i == 0:
                body += '<hr/><b>Son yorumlar</b><br/><br/>'
            current_comment = issue.fields.comment.comments[comment_idx]
            comment_body = self._get_safe_text(current_comment.body).replace("\r\n", "<br/>")
            body += '<b>' + current_comment.author.displayName + ", " + current_comment.created + ':</b> <br/>' + comment_body + "<br/><br/>"

        # Bottom

        body += '<br/><hr/><br/>'

        # Finish

        body += '</en-note>'
        note.content = body

        # ______________________________
        # Flush

        self._note_store.createNote(note)
Exemple #27
0
    def create_page(self,
                    issue: Issue,
                    jira_man: JiraManager,
                    with_comments: bool = False):
        """ Creation of a new Notion page """
        global _PAGE_URL

        # Get details from JIRA
        try:
            title_key = issue.fields.parent.key
        except Exception:
            title_key = issue.key

        title = title_key + " - " + issue.fields.summary
        link = jira_man.get_url(issue.key)

        description = issue.fields.description
        if description is None:
            description = "(No description)"

        # Post to Notion
        headers = {
            "Content-Type": "application/json",
            "Notion-Version": self._config.notion_official_version,
            "Authorization": "Bearer " + self._config.notion_official_token
        }

        body = {
            "parent": {
                "database_id": self._config.notion_official_database
            },
            "properties": {
                "title": {
                    "title": [{
                        "text": {
                            "content": title
                        }
                    }]
                },
                "URL": {
                    "type": "url",
                    "url": link
                }
            },
            "children": [{
                "object": "block",
                "type": "heading_1",
                "heading_1": {
                    "text": [{
                        "type": "text",
                        "text": {
                            "content": "Comments"
                        }
                    }]
                }
            }, {
                "object": "block",
                "type": "paragraph",
                "paragraph": {
                    "text": [{
                        "type": "text",
                        "text": {
                            "content": "..."
                        }
                    }]
                }
            }]
        }

        response = requests.post(_PAGE_URL,
                                 data=json.dumps(body),
                                 headers=headers)

        if response.status_code != 200:
            raise Exception("Notion API error: " + response.reason)