-
Notifications
You must be signed in to change notification settings - Fork 0
/
JIRA_copyProjectVersions.py
78 lines (64 loc) · 2.66 KB
/
JIRA_copyProjectVersions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# Script for copying project version from project A to project B
# Requirements:
# 'jira' package
# Usage:
# Just change the Jira URL, username and password and define your project keys
from jira.client import JIRA
import re
import urllib3
jiraHost = 'https://jira.domain.com'
jiraUser = 'username'
jiraPass = 'password'
projectA = 'PROJECTKEYOLD'
projectB = 'PROJECTKEYNEW'
options = JIRA.DEFAULT_OPTIONS
options['server'] = jiraHost
# disable SSL verification
options['verify'] = False
urllib3.disable_warnings()
# initiate
jira = JIRA(options=options, basic_auth=(jiraUser, jiraPass))
# optional - deleting all existing versions in the target project
print(f"Deleting all unused versions in the project '{projectB}'...")
for ver in jira.project_versions(projectB):
print(ver, '... ', end='')
verCount = jira.version_count_related_issues(ver.id)
if verCount['issuesFixedCount'] or \
verCount['issuesAffectedCount'] or \
verCount['issueCountWithCustomFieldsShowingVersion']:
print('existing issues - skipping...')
else:
ver.delete()
print("deleted")
print(f"Copying all versions from project '{projectA}' to project '{projectB}'...")
for ver in jira.project_versions(projectA):
verDesc = ver.raw['description'] if 'description' in ver.raw else ""
verStart = ver.raw['startDate'] if 'startDate' in ver.raw else None
verEnd = ver.raw['releaseDate'] if 'releaseDate' in ver.raw else None
print(ver, '... ', end='')
# some condition added - e.g. when we don't want archived ver or specific
if ver.archived:
print("skipped - archived")
continue
if not re.search(r'^1.[0-9]', ver.name):
print("skipped - doesn't matach")
continue
verB = jira.get_project_version_by_name(projectB, ver.name)
if verB: # if target version exists, just update it
verB.update(description=verDesc,
startDate=verStart,
releaseDate=verEnd,
archived=ver.archived,
released=ver.released)
print("updated")
else: # create a new one
verB = jira.create_version(ver.name,
projectB,
description=verDesc,
startDate=verStart,
releaseDate=verEnd,
released=ver.released)
# set archived flag in the second call (because of bug https://jira.atlassian.com/browse/JRASERVER-61990)
if ver.archived:
verB.update(archived=True)
print("created")