Skip to content
This repository has been archived by the owner on Oct 13, 2023. It is now read-only.

Commit

Permalink
Target Release customfield change (#560)
Browse files Browse the repository at this point in the history
  • Loading branch information
thegreyd authored Jun 9, 2023
1 parent b460b86 commit 0e64997
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 21 deletions.
34 changes: 20 additions & 14 deletions elliottlib/bzutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,7 @@ def version(self):

@property
def blocked_by_bz(self):
# field "Blocked by Bugzilla Bug"
url = self.bug.fields.customfield_12322152
url = getattr(self.bug.fields, JIRABugTracker.FIELD_BLOCKED_BY_BZ)
if not url:
return None
bug_id = re.search(r"id=(\d+)", url)
Expand All @@ -289,8 +288,7 @@ def blocked_by_bz(self):

@property
def target_release(self):
# field "Target Version"
tr_field = self.bug.fields.customfield_12319940
tr_field = getattr(self.bug.fields, JIRABugTracker.FIELD_TARGET_VERSION)
if not tr_field:
raise ValueError(f'bug {self.id} does not have `Target Version` field set')
return [x.name for x in tr_field]
Expand Down Expand Up @@ -351,24 +349,27 @@ def whiteboard_component(self):

def _get_release_blocker(self):
# release blocker can be ['None','Approved'=='+','Proposed'=='?','Rejected'=='-']
if self.bug.fields.customfield_12319743:
return self.bug.fields.customfield_12319743.value == 'Approved'
field = getattr(self.bug.fields, JIRABugTracker.FIELD_RELEASE_BLOCKER)
if field:
return field.value == 'Approved'
return False

def _get_blocked_reason(self):
if self.bug.fields.customfield_12316544:
return self.bug.fields.customfield_12316544.value
field = getattr(self.bug.fields, JIRABugTracker.FIELD_BLOCKED_REASON)
if field:
return field.value
return None

def _get_severity(self):
if self.bug.fields.customfield_12316142:
if "Urgent" in self.bug.fields.customfield_12316142.value:
field = getattr(self.bug.fields, JIRABugTracker.FIELD_SEVERITY)
if field:
if "Urgent" in field.value:
return "Urgent"
if "High" in self.bug.fields.customfield_12316142.value:
if "High" in field.value:
return "High"
if "Medium" in self.bug.fields.customfield_12316142.value:
if "Medium" in field.value:
return "Medium"
if "Low" in self.bug.fields.customfield_12316142.value:
if "Low" in field.value:
return "Low"
return None

Expand Down Expand Up @@ -566,6 +567,11 @@ def get_flaw_bugs(self, bug_ids: List, strict: bool = True, verbose: bool = Fals

class JIRABugTracker(BugTracker):
JIRA_BUG_BATCH_SIZE = 50
FIELD_BLOCKED_BY_BZ = 'customfield_12322152' # "Blocked by Bugzilla Bug"
FIELD_TARGET_VERSION = 'customfield_12323140' # "Target Version"
FIELD_RELEASE_BLOCKER = 'customfield_12319743' # "Release Blocker"
FIELD_BLOCKED_REASON = 'customfield_12316544' # "Blocked Reason"
FIELD_SEVERITY = 'customfield_12316142' # "Severity"

@staticmethod
def get_config(runtime) -> Dict:
Expand Down Expand Up @@ -647,7 +653,7 @@ def create_bug(self, bug_title: str, bug_description: str, target_status: str, k
'issuetype': {'name': 'Bug'},
'components': [{'name': 'Release'}],
'versions': [{'name': self.config.get('version')[0]}], # Affects Version/s
'customfield_12319940': [{'name': self.config.get('target_release')[0]}], # Target Version
self.FIELD_TARGET_VERSION: [{'name': self.config.get('target_release')[0]}], # Target Version
'summary': bug_title,
'labels': keywords,
'description': bug_description
Expand Down
3 changes: 2 additions & 1 deletion elliottlib/cli/find_bugs_kernel_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from elliottlib.config_model import KernelBugSweepConfig
from elliottlib.exceptions import ElliottFatalError
from elliottlib.util import green_print
from elliottlib.bzutil import JIRABugTracker


class FindBugsKernelCli:
Expand Down Expand Up @@ -254,7 +255,7 @@ def _new_jira_fields_from_bug(bug: Bug, ocp_target_version: str, kmaint_tracker:
"description": description,
"issuetype": {"name": "Bug"},
"versions": [{"name": ocp_target_version[:ocp_target_version.rindex(".")]}],
"customfield_12319940": [{
f"{JIRABugTracker.FIELD_TARGET_VERSION}": [{
"name": ocp_target_version,
}],
"labels": ["art:cloned-kernel-bug", f"art:bz#{bug.id}"],
Expand Down
6 changes: 4 additions & 2 deletions elliottlib/cli/find_bugs_kernel_clones_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from elliottlib.config_model import KernelBugSweepConfig
from elliottlib.exceptions import ElliottFatalError
from elliottlib.util import green_print
from elliottlib.bzutil import JIRABugTracker


class FindBugsKernelClonesCli:
Expand Down Expand Up @@ -78,9 +79,10 @@ def _get_jira_issues(self, jira_client: JIRA, issue_keys: List[str], config: Ker
components = {c.name for c in issue.fields.components}
if config.target_jira.component not in components:
raise ValueError(f"Jira {key} is not set to component {config.target_jira.component}")
target_releases = {t.name for t in issue.fields.customfield_12319940}
target_versions = getattr(issue.fields, JIRABugTracker.FIELD_TARGET_VERSION)
target_releases = {t.name for t in target_versions}
if config.target_jira.target_release not in target_releases:
raise ValueError(f"Jira {key} has invalid target version: {issue.fields.customfield_12319940.name}")
raise ValueError(f"Jira {key} has invalid target version: {target_versions}")
found_issues.append(issue)
return found_issues

Expand Down
7 changes: 4 additions & 3 deletions tests/test_find_bugs_kernel_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from elliottlib.cli.find_bugs_kernel_cli import FindBugsKernelCli
from elliottlib.config_model import KernelBugSweepConfig
from elliottlib.runtime import Runtime
from elliottlib.bzutil import JIRABugTracker


class TestFindBugsKernelCli(IsolatedAsyncioTestCase):
Expand Down Expand Up @@ -101,7 +102,7 @@ def test_clone_bugs1(self):
"description": "Cloned from https://example.com/1 by OpenShift ART Team:\n----\nfake description 1",
"issuetype": {"name": "Bug"},
"versions": [{"name": "4.14"}],
"customfield_12319940": [{"name": "4.14.z"}],
f"{JIRABugTracker.FIELD_TARGET_VERSION}": [{"name": "4.14.z"}],
"labels": ["art:cloned-kernel-bug", "art:bz#1", "art:kmaint:TRACKER-1"]
}
jira_client.create_issue.assert_called_once_with(expected_fields)
Expand Down Expand Up @@ -144,7 +145,7 @@ def test_clone_bugs2(self):
"description": "Cloned from https://example.com/1 by OpenShift ART Team:\n----\nfake description 1",
"issuetype": {"name": "Bug"},
"versions": [{"name": "4.14"}],
"customfield_12319940": [{"name": "4.14.z"}],
f"{JIRABugTracker.FIELD_TARGET_VERSION}": [{"name": "4.14.z"}],
"labels": ["art:cloned-kernel-bug", "art:bz#1", "art:kmaint:TRACKER-1"]
}
found_issues[0].update.assert_called_once_with(expected_fields)
Expand Down Expand Up @@ -229,7 +230,7 @@ def test_new_jira_fields_from_bug(self):
"description": "Cloned from https://example.com/12345 by OpenShift ART Team:\n----\nfake description 12345",
"issuetype": {"name": "Bug"},
"versions": [{"name": "4.12"}],
"customfield_12319940": [{"name": "4.12.z"}],
f"{JIRABugTracker.FIELD_TARGET_VERSION}": [{"name": "4.12.z"}],
"labels": ["art:cloned-kernel-bug", "art:bz#12345", "art:kmaint:TRACKER-1"],
}
self.assertEqual(actual, expected)
Expand Down
3 changes: 2 additions & 1 deletion tests/test_find_bugs_kernel_clones_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from elliottlib.assembly import AssemblyTypes
from elliottlib.cli.find_bugs_kernel_clones_cli import FindBugsKernelClonesCli
from elliottlib.config_model import KernelBugSweepConfig
from elliottlib.bzutil import JIRABugTracker


class TestFindBugsKernelClonesCli(IsolatedAsyncioTestCase):
Expand Down Expand Up @@ -45,7 +46,7 @@ def test_get_jira_issues(self):
"fields.labels": ["art:cloned-kernel-bug"],
"fields.project.key": "OCPBUGS",
"fields.components": [component],
"fields.customfield_12319940": [target_release],
f"fields.{JIRABugTracker.FIELD_TARGET_VERSION}": [target_release],
})
actual = cli._get_jira_issues(jira_client, ["FOO-1", "FOO-2", "FOO-3"], self._config)
self.assertEqual([issue.key for issue in actual], ["FOO-1", "FOO-2", "FOO-3"])
Expand Down

0 comments on commit 0e64997

Please sign in to comment.