Skip to content

Commit 0ccc9a3

Browse files
authored
Merge pull request #84 from cxpsemea/dev-jc
build: fix labels
2 parents 099b0c6 + 61a28bb commit 0ccc9a3

File tree

2 files changed

+59
-51
lines changed

2 files changed

+59
-51
lines changed

cxoneflow/src/cxjirafeedback.py

+45-48
Original file line numberDiff line numberDiff line change
@@ -1106,61 +1106,58 @@ def __processjiraticket( self, scanner: str, ticketsummary: str, ticket: cxresul
11061106
ticketkey = jiraticket.get('key')
11071107
current_status = jiraticket['fields']['status']['name']
11081108

1109-
# >>> TEMP CONDITION TO REMOVE
1110-
if ticketkey in ['GINFOSEC-75333', 'GINFOSEC-72118', 'GINFOSEC-72120'] :
1111-
1112-
# If it's not opened, let's reopen it
1113-
if (str(current_status).lower() in self.jiraparams.closedstatus) :
1114-
if self.jiraparams.opentransition :
1115-
try :
1116-
retdata = self.jira.tickettransition( ticketkey, self.jiraparams.opentransition )
1117-
except HTTPError as e:
1118-
raise Exception( self.__processjiraexception( False, False, e ) )
1119-
except Exception as e:
1120-
if str(e) :
1121-
raise e
1122-
else :
1123-
raise Exception( 'Error transitioning jira ticket' )
1124-
1125-
reopened = True
1126-
else :
1127-
cxlogger.logwarning( 'Open transtion missing. Cannot reopen "' + str(ticketkey) + '"' )
1128-
# Check if description changed
1129-
newdescription = None
1130-
if description and (not description == jiraticket['fields'].get('description')) :
1131-
newdescription = description
1132-
# Check if priority changed
1133-
newpriority = None
1134-
ticketpriority = None
1135-
if jiraticket['fields'].get('priority') :
1136-
ticketpriority = jiraticket['fields']['priority'].get('name')
1137-
if priority and (not priority == ticketpriority) :
1138-
newpriority = priority
1139-
# Check if labels changed
1140-
newlabels = []
1141-
existinglabels = jiraticket['fields'].get('labels')
1142-
if not existinglabels :
1143-
existinglabels = []
1144-
for label in labels :
1145-
found = next( filter( lambda el: el == label, existinglabels), None )
1146-
if not found :
1147-
newlabels.append(label)
1148-
if len(newlabels) == 0 :
1149-
newlabels = None
1150-
# Check fields
1151-
if len(fields) == 0 :
1152-
fields = None
1153-
1154-
if newdescription or newpriority or newlabels or fields :
1109+
# If it's not opened, let's reopen it
1110+
if (str(current_status).lower() in self.jiraparams.closedstatus) :
1111+
if self.jiraparams.opentransition :
11551112
try :
1156-
self.jira.projecteditissue( ticketkey, newdescription, fields, newlabels, newpriority )
1113+
retdata = self.jira.tickettransition( ticketkey, self.jiraparams.opentransition )
11571114
except HTTPError as e:
11581115
raise Exception( self.__processjiraexception( False, False, e ) )
11591116
except Exception as e:
11601117
if str(e) :
11611118
raise e
11621119
else :
1163-
raise Exception( 'Error updating jira ticket' )
1120+
raise Exception( 'Error transitioning jira ticket' )
1121+
1122+
reopened = True
1123+
else :
1124+
cxlogger.logwarning( 'Open transtion missing. Cannot reopen "' + str(ticketkey) + '"' )
1125+
# Check if description changed
1126+
newdescription = None
1127+
if description and (not description == jiraticket['fields'].get('description')) :
1128+
newdescription = description
1129+
# Check if priority changed
1130+
newpriority = None
1131+
ticketpriority = None
1132+
if jiraticket['fields'].get('priority') :
1133+
ticketpriority = jiraticket['fields']['priority'].get('name')
1134+
if priority and (not priority == ticketpriority) :
1135+
newpriority = priority
1136+
# Check if labels changed
1137+
newlabels = []
1138+
existinglabels = jiraticket['fields'].get('labels')
1139+
if not existinglabels :
1140+
existinglabels = []
1141+
for label in labels :
1142+
found = next( filter( lambda el: el == label, existinglabels), None )
1143+
if not found :
1144+
newlabels.append(label)
1145+
if len(newlabels) == 0 :
1146+
newlabels = None
1147+
# Check fields
1148+
if len(fields) == 0 :
1149+
fields = None
1150+
1151+
if newdescription or newpriority or newlabels or fields :
1152+
try :
1153+
self.jira.projecteditissue( ticketkey, newdescription, fields, newlabels, newpriority )
1154+
except HTTPError as e:
1155+
raise Exception( self.__processjiraexception( False, False, e ) )
1156+
except Exception as e:
1157+
if str(e) :
1158+
raise e
1159+
else :
1160+
raise Exception( 'Error updating jira ticket' )
11641161

11651162
if reopened :
11661163
cxlogger.verbose( '- JIRA issue ' + ticketkey + ' re-opened, type ' + scanner.upper() + ', prev status "' + current_status + '", with key "' + ticketsummary + '"' )

cxoneflow/src/cxprocessscan.py

+14-3
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,25 @@ def results(self) :
5454

5555
# Get scan information, wait for completion
5656
def __getscandata(self, scanid: str, waitforit: bool = True ) :
57+
go: bool = True
5758
# Get scan and status. Error is thrown if scan does not exists
5859
scan = self.conn.cxone.get( '/api/scans/' + scanid )
59-
while scan['status'] != 'Completed' and waitforit :
60+
scanstatus = str(scan['status']).lower()
61+
# while scan['status'] != 'Completed' and waitforit :
62+
while scanstatus not in ['completed', 'failed', 'partial', 'canceled'] and waitforit :
6063
# 30 seconds
6164
time.sleep(30.0)
6265
scan = self.conn.cxone.get( '/api/scans/' + scanid )
66+
scanstatus = str(scan['status']).lower()
67+
if scanstatus in ['failed', 'canceled'] :
68+
go = False
69+
cxlogger.verbose( 'Aborted processing ' + scanstatus + ' scan' )
70+
elif scanstatus == 'partial' :
71+
cxlogger.verbose( 'Processing a ' + scanstatus + ' scan' )
6372
# Get associated project data
6473
project = self.conn.cxone.get( '/api/projects/' + scan['projectId'] )
6574
self.__scan.updatescandata( scan, project )
75+
return go
6676

6777

6878
# Check branch name and scanners for processing go/no-go
@@ -278,9 +288,10 @@ def processscan(self) :
278288

279289
self.__allcounter = 0
280290

281-
self.__getscandata( self.cxparams.scanid )
291+
go = self.__getscandata( self.cxparams.scanid )
282292

283-
go = self.__checkscandata()
293+
if go :
294+
go = self.__checkscandata()
284295

285296
if go :
286297

0 commit comments

Comments
 (0)