From 8efe8fc01cb353ae2b1349b6dfca525ec8c6325d Mon Sep 17 00:00:00 2001 From: Peter Mosmans Date: Wed, 22 Feb 2017 11:59:40 +1100 Subject: [PATCH] Recognize keywords 'recommendation' and 'impact' in notes Treat them accordingly. Note that the keyword can only be used in one note, and has to be on the first line of the note. Re-order notes (oldest note first). --- chatops/python/gitlab-to-pentext.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/chatops/python/gitlab-to-pentext.py b/chatops/python/gitlab-to-pentext.py index d2ad9ed..d30df18 100644 --- a/chatops/python/gitlab-to-pentext.py +++ b/chatops/python/gitlab-to-pentext.py @@ -58,13 +58,21 @@ def add_finding(issue, options): filename = 'findings/{0}.xml'.format(finding_id) finding = u'{0}\n'.format(title) finding += '{0}\n\n'.format(convert_text(issue.description)) + impact = 'TODO' + recommendation = '\n'; technical_description = '' - for note in [x for x in issue.notes.list() if not x.system]: - technical_description += u'{0}\n'.format(convert_text(note.body)) - finding += '\n{0}\n\n'.format(technical_description) - finding += '\nTODO\n\n' - finding += '\n\n\n' - finding = u'{0}\n{4}\n'.format(DECLARATION, + for note in [x for x in reversed(issue.notes.list()) if not x.system]: + if len(note.body.splitlines()): + if 'impact' in note.body.split()[0].lower(): + impact = convert_text(''.join(note.body.splitlines(True)[1:])) + elif 'recommendation' in note.body.split()[0].lower(): + recommendation = convert_text(''.join(note.body.splitlines(True)[1:])) + else: + technical_description += u'{0}\n'.format(convert_text(note.body)) + finding += '\n{0}\n\n\n'.format(technical_description) + finding += '\n{0}\n\n\n'.format(impact) + finding += '\n{0}\n\n\n'.format(recommendation) + finding = u'{0}\n{4}'.format(DECLARATION, finding_id, threat_level, finding_type, @@ -100,7 +108,7 @@ def add_non_finding(issue, options): filename = 'non-findings/{0}.xml'.format(non_finding_id) non_finding = u'{0}\n{1}\n'.format(title, convert_text(issue.description)) - for note in [x for x in issue.notes.list() if not x.system]: + for note in [x for x in reversed(issue.notes.list()) if not x.system]: non_finding += u'

{0}

\n'.format(convert_text(note.body)) non_finding = u'{0}\n{2}\n\n'.format(DECLARATION, non_finding_id, @@ -191,6 +199,7 @@ def preflight_checks(): Checks if all tools are there. Exits with 0 if everything went okilydokily. """ + gitserver = None try: gitserver = gitlab.Gitlab.from_config('remote') gitserver.auth()