I am doing automation in python for jira with the addition of jql search inside the service As a result: two JQL queries, one to search for “closed tickets” and the second to search for “created tickets”
But as a result, I can’t add rows now.
JavaScript
x
20
20
1
2
#Day 0 - current day , Day '-1' - Yesterday
3
jql_day = ['','-1','-2','-3']
4
jql_list_one_str = []
5
jql_list_two_str = []
6
7
action = ['resolved','created']
8
9
for i in jql_day:
10
jql_str = 'project = MRCHNT AND '+ action[0]+' >= startOfDay(' + i + ')', 'project = MRCHNT AND '+ action[1]+' >= startOfDay(' + i + ')'
11
jql_list_one_str.append(jql_str)
12
jql_str_2 = 'AND '+ action[0] +' <= startOfDay(' + i + ')','AND '+ action[1] +' <= startOfDay(' + i + ')'
13
jql_list_two_str.append(jql_str_2)
14
15
# jql_request = [' '.join(x) for x in zip(jql_list_one_str[1:], jql_list_two_str[:-1])]# Split list
16
# jql_request.insert(0,jql_list_one_str[0])
17
18
19
print(jql_list_one_str,jql_list_two_str)
20
Expected Result:
JavaScript
1
7
1
1 list resolved:
2
3
'project = MRCHNT AND resolved >= startOfDay()'
4
'project = MRCHNT AND resolved >= startOfDay(-1) AND resolved <= startOfDay()'
5
'project = MRCHNT AND resolved >= startOfDay(-2) AND resolved <= startOfDay(-1)'
6
'project = MRCHNT AND resolved >= startOfDay(-3) AND resolved <= startOfDay(-2)'
7
JavaScript
1
8
1
2 list created:
2
3
'project = MRCHNT AND created >= startOfDay()
4
'project = MRCHNT AND created >= startOfDay(-1) AND created <= startOfDay()'
5
'project = MRCHNT AND created >= startOfDay(-2) AND created <= startOfDay(-1)'
6
'project = MRCHNT AND created >= startOfDay(-3) AND created <= startOfDay(-2)'
7
8
I got two lists inside with tuples. enter image description here
“second result” enter image description here
Advertisement
Answer
You should use f-strings to resolve this issue.
JavaScript
1
13
13
1
jql_day = ['','-1','-2','-3']
2
jql_list_one_str = []
3
jql_list_two_str = []
4
5
action = ['resolved','created']
6
7
for i in jql_day:
8
jql_str = [f'project = MRCHNT AND {action[0]} >= startOfDay({i})', f'project = MRCHNT AND {action[1]} >= startOfDay({i})']
9
jql_list_one_str.append(jql_str)
10
jql_str_2 = [f'AND {action[0]} <= startOfDay({i})', f'AND {action[1]} <= startOfDay({i})']
11
jql_list_two_str.append(jql_str_2)
12
13
To then get the relevant strings you are interested in I should think you should use:
JavaScript
1
19
19
1
created = []
2
resolved = []
3
4
for idx, day in enumerate(jql_day):
5
6
if idx == 0:
7
string1 = jql_list_one_str[idx][0]
8
string2 = jql_list_one_str[idx][1]
9
else:
10
string1 = jql_list_one_str[idx][0] + " , " + jql_list_two_str[idx-1][0]
11
string2 = jql_list_one_str[idx][1] + " , " + jql_list_two_str[idx-1][1]
12
13
resolved.append(string1)
14
created.append(string2)
15
16
print(resolved)
17
print(created)
18
19