You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kibble.apache.org by hu...@apache.org on 2018/12/31 04:53:36 UTC
[kibble-scanners] branch master updated: Fake user email if nto
provided by JIRA
This is an automated email from the ASF dual-hosted git repository.
humbedooh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kibble-scanners.git
The following commit(s) were added to refs/heads/master by this push:
new ac30427 Fake user email if nto provided by JIRA
ac30427 is described below
commit ac30427ace2767750c905883b7495304852190d3
Author: Daniel Gruno <hu...@apache.org>
AuthorDate: Mon Dec 31 05:50:32 2018 +0100
Fake user email if nto provided by JIRA
In some instances, JIRA will have email visibility turned
off for the REST API. In such instances, we should use the
domain of the JIRA instance and the username (which is still
visible to us) to fake an email address. While not perfect,
this still allows us to get a good unique count of actors.
---
src/plugins/scanners/jira.py | 26 +++++++++++++++++++++-----
1 file changed, 21 insertions(+), 5 deletions(-)
diff --git a/src/plugins/scanners/jira.py b/src/plugins/scanners/jira.py
index 82703bc..0320ffe 100644
--- a/src/plugins/scanners/jira.py
+++ b/src/plugins/scanners/jira.py
@@ -111,6 +111,15 @@ def scanTicket(KibbleBit, key, u, source, creds, openTickets):
found = True
doc= None
parseIt = False
+
+ # the 'domain' var we try to figure out here is used
+ # for faking email addresses and keep them unique,
+ # in case JIRA has email visibility turned off.
+ domain = 'jira'
+ m = re.search(r"https?://([^/]+)", u)
+ if m:
+ domain = m.group(1)
+
found = KibbleBit.exists('issue', dhash)
if not found:
KibbleBit.pprint("[%s] We've never seen this ticket before, parsing..." % key)
@@ -129,7 +138,7 @@ def scanTicket(KibbleBit, key, u, source, creds, openTickets):
#KibbleBit.pprint("[%s] Ticket hasn't changed, ignoring..." % key)
if parseIt:
- KibbleBit.pprint("[%s] Parsing data from JIRA..." % key)
+ KibbleBit.pprint("[%s] Parsing data from JIRA at %s..." % (key, domain))
queryURL = "%s/rest/api/2/issue/%s?fields=creator,reporter,status,issuetype,summary,assignee,resolutiondate,created,priority,changelog,comment,resolution,votes&expand=changelog" % (u, key)
jiraURL = "%s/browse/%s" % (u, key)
try:
@@ -156,12 +165,16 @@ def scanTicket(KibbleBit, key, u, source, creds, openTickets):
comments = 0
if 'comment' in tjson['fields'] and tjson['fields']['comment']:
comments = tjson['fields']['comment']['total']
- assignee = tjson['fields']['assignee'].get('emailAddress') if tjson['fields'].get('assignee') else None
- creator = tjson['fields']['reporter'].get('emailAddress') if tjson['fields'].get('reporter') else None
+ assignee = tjson['fields']['assignee'].get('emailAddress', # Try email, fall back to username
+ tjson['fields']['assignee'].get('name')) if tjson['fields'].get('assignee') else None
+ creator = tjson['fields']['reporter'].get('emailAddress', # Try email, fall back to username
+ tjson['fields']['reporter'].get('name')) if tjson['fields'].get('reporter') else None
title = tjson['fields']['summary']
if closer:
#print("Parsing closer")
- closerEmail = closer.get('emailAddress', 'unknown@kibble').replace(" dot ", ".", 10).replace(" at ", "@", 1)
+ closerEmail = closer.get('emailAddress', closer.get('name')).replace(" dot ", ".", 10).replace(" at ", "@", 1)
+ if not '@' in closerEmail:
+ closerEmail = '%s@%s' % (closerEmail, domain)
displayName = closer.get('displayName', 'Unkown')
if displayName and len(displayName) > 0:
# Add to people db
@@ -177,6 +190,8 @@ def scanTicket(KibbleBit, key, u, source, creds, openTickets):
if creator:
creator = creator.replace(" dot ", ".", 10).replace(" at ", "@", 1)
+ if not '@' in creator:
+ creator = '%s@%s' % (creator, domain)
displayName = tjson['fields']['reporter']['displayName'] if tjson['fields']['reporter'] else None
if displayName and len(displayName) > 0:
# Add to people db
@@ -189,7 +204,8 @@ def scanTicket(KibbleBit, key, u, source, creds, openTickets):
'upsert': True
}
KibbleBit.append('person', jsp)
-
+ if assignee and not '@' in assignee:
+ assignee = '%s@%s' % (assignee, domain)
jso = {
'id': dhash,
'key': key,