Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DO NOT MERGE, [BEAM-4687] test Jenkins JIRA plugin #5920

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 16 additions & 0 deletions .test-infra/jenkins/jira_utils/__init__.py
@@ -0,0 +1,16 @@
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
119 changes: 119 additions & 0 deletions .test-infra/jenkins/jira_utils/jira_client.py
@@ -0,0 +1,119 @@
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#


from jira import JIRA

class JiraClient:
def __init__(self, options, basic_auth, project):
self.jira = JIRA(options, basic_auth=basic_auth)
self.project = project


def get_issues_by_summary(self, summary):
"""
Find issues by using the summary (issue title)
Args:
summary
Return:
a list of issues
"""
try:
issues = self.jira.search_issues("project={0} AND summary ~ '{1}'".format(self.project, summary))
except Exception:
raise
return issues


def get_issue_by_key(self, key):
"""
Find issue by using the key (e.g BEAM-1234)
Args:
key
Return:
issue
"""
try:
issue = self.jira.issue(key)
except Exception:
raise
return issue


def create_issue(self, summary, components, description='', issuetype='Bug', assignee=None, parent_key=None):
"""
Create a new issue
Args:
summary - Issue title
components - A list of components
description (optional) - A string that describes the issue
issuetype (optional) - Bug, Improvement, New Feature, Sub-task, Task, Wish, etc.
assignee (optional) - A string of JIRA user name
parent_key (optional) - The parent issue key is required when creating a subtask.
Return:
Issue created
"""
feilds = {
'project': {'key': self.project},
'summary': summary,
'description': description,
'issuetype': {'name': issuetype},
'components': [],
}
for component in components:
feilds['components'].append({'name': component})
if assignee is not None:
feilds['assignee'] = {'name': assignee}
if parent_key is not None:
feilds['parent'] = {'key': parent_key}
feilds['issuetype'] = {'name': 'Sub-task'}
try:
new_issue = self.jira.create_issue(fields = feilds)
except Exception:
raise
return new_issue


def update_issue(self, issue, summary=None, components=None, description=None, assignee=None, notify=True):
"""
Create a new issue
Args:
issue - Jira issue object
summary (optional) - Issue title
components (optional) - A list of components
description (optional) - A string that describes the issue
assignee (optional) - A string of JIRA user name
notify - Query parameter notifyUsers. If true send the email with notification that the issue was updated to users that watch it.
Admin or project admin permissions are required to disable the notification.
Return:
Issue created
"""
fields={}
if summary is not None:
fields['summary'] = summary
if description is not None:
fields['description'] = description
if assignee is not None:
fields['assignee'] = {'name': assignee}
if components is not None:
fields['components'] = []
for component in components:
fields['components'].append({'name': component})
try:
issue.update(fields=fields, notify=notify)
except Exception:
raise
119 changes: 119 additions & 0 deletions .test-infra/jenkins/jira_utils/jira_manager.py
@@ -0,0 +1,119 @@
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

import logging
import yaml
from datetime import datetime
from jira_client import JiraClient

_JIRA_PROJECT_NAME = 'BEAM'
_JIRA_COMPONENT = 'dependencies'

class JiraManager:

def __init__(self, jira_url, jira_username, jira_password, owners_file, sdk_type='Java'):
options = {
'server': jira_url
}
basic_auth = (jira_username, jira_password)
self.jira = JiraClient(options, basic_auth, _JIRA_PROJECT_NAME)
with open(owners_file) as f:
owners = yaml.load(f)
self.owners_map = owners['deps']
logging.getLogger().setLevel(logging.INFO)


def _create_issue(self, dep_name, dep_latest_version, is_subtask=False, parent_key=None):
"""
Create a new issue or subtask
Args:
dep_name
dep_latest_version
is_subtask
parent_key - only required if the 'is_subtask'is true.
"""
logging.info("Creating a new JIRA issue to track {0} upgrade process").format(dep_name)
assignee, owners = self._find_assignees(dep_name)
summary = 'Beam Dependency Update Request: ' + dep_name
description = """\n\n {0} \n
Please review and upgrade the {1} to the latest version {2} \n
cc: """.format(
datetime.today(),
dep_name,
dep_latest_version
)
for owner in owners:
description.append("[~{0}],".format(owner))
try:
if not is_subtask:
self.jira.create_issue(summary, _JIRA_COMPONENT, description=description, assignee=assignee)
else:
self.jira.create_issue(summary, _JIRA_COMPONENT, description=description, assignee=assignee, parent_key=parent_key)
except Exception as e:
logging.error("Error while creating issue: "+ str(e))


def _search_issues(self, dep_name):

pass


def _append_descriptions(self, issue, dep_name, dep_latest_version):
logging.info("Updating JIRA issue to {0} track {1} upgrade process").format(
issue.key['name'],
dep_name)
description = issue.description + """\n\n {0} \n
Please review and upgrade the {1} to the latest version {2} \n
cc: """.format(
datetime.today(),
dep_name,
dep_latest_version
)
_, owners = self._find_assignees(dep_name)
for owner in owners:
description.append("[~{0}],".format(owner))
try:
self.jira.update_issue(issue, description=description)
except Exception as e:
logging.error("Error while updating issue: "+ str(e))



def _find_owners(self, dep_name):
try:
dep_info = self.owners_map[dep_name]
owners = dep_info['owners']
if not owners:
logging.info("Could not find owners for " + dep_name)
return None, []
except KeyError:
logging.info("Could not find {0} in the ownership configurations.".format(dep_name))
return None, []
except Exception as e:
logging.error("Error while finding dependency owners: "+ str(e))
return None, None

logging.info("Found owners of {0}: {1}".format(dep_name, owners))
owners = owners.split(',')
primary = owners[0]
del owners[0]
return primary, owners


def run(self, dep_name, dep_latest_version, group_id=None, artifact_id=None):

pass
38 changes: 38 additions & 0 deletions .test-infra/jenkins/jira_utils/jira_manager_test.py
@@ -0,0 +1,38 @@
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

import unittest, mock
from jira_manager import JiraManager

class JiraManagerTest(unittest.TestCase):
"""Tests for `jira_manager.py`."""

def setUp(self):
print("Test name:", self._testMethodName)


def test_find_owners_with_single_owner(self):
pass

def test_find_owners_with_multi_owners(self):
pass

def test_find_owners_with_no_owners_defined(self):
pass

def test_find_owners_with_no_dep_defined(self):