Add very preliminary support for commits.

pull/1/head
Simon Quigley 7 years ago
parent 8d888dea87
commit b7d3569bc7

107
lugito

@ -77,65 +77,70 @@ def main():
print(data) print(data)
print print
taskexists = True exists = True
try: try:
tasksearch = phab.transaction.search(objectIdentifier=data["object"]["phid"])["data"] search = phab.transaction.search(objectIdentifier=data["object"]["phid"])["data"]
except http.client.HTTPException: except http.client.HTTPException:
taskexists = False exists = False
if taskexists: if exists:
print("Task exists, checking to see if it's new.") print("Object exists, checking to see if it's a task or a commit.")
newtask = isnewtask(tasksearch)
if newtask: if data["object"]["type"] == "TASK":
print("Yes, it's a new task.") print("This is a task. Checking if it's new.")
else: newtask = isnewtask(search)
print("No, it's not a new task.") if newtask:
print("Yes, it's a new task.")
else:
print("No, it's not a new task.")
# If it's not a new task, let's see if it's a comment, and if it's just an edit # If it's not a new task, let's see if it's a comment, and if it's just an edit
comment = None comment = None
commentid = None
edited = None
if not newtask:
commentid = None commentid = None
edited = False edited = None
for task in tasksearch: if not newtask:
dataepoch = data["action"]["epoch"] commentid = None
datemodified = task["dateModified"] edited = False
# All comments within ten seconds of the request are fair game for task in search:
if datemodified >= (dataepoch - 10) and datemodified <= (dataepoch + 10) and task["comments"] != []: dataepoch = data["action"]["epoch"]
print("It's a comment, yes.") datemodified = task["dateModified"]
comment = True # All comments within ten seconds of the request are fair game
commentid = task["id"] if datemodified >= (dataepoch - 10) and datemodified <= (dataepoch + 10) and task["comments"] != []:
if datemodified != task["dateCreated"]: print("It's a comment, yes.")
print("The comment was edited.") comment = True
edited = True commentid = task["id"]
if datemodified != task["dateCreated"]:
print("The comment was edited.")
edited = True
else:
print("The comment was NOT edited.")
edited = False
break
else: else:
print("The comment was NOT edited.") comment = False
edited = False
break
else:
comment = False
if comment or edited or newtask: if comment or edited or newtask:
# We should also know who did this thing # We should also know who did this thing
userlookup = tasksearch[0]["authorPHID"] userlookup = search[0]["authorPHID"]
who = dict(phab.phid.query(phids=[userlookup]))[userlookup]["fullName"] who = dict(phab.phid.query(phids=[userlookup]))[userlookup]["fullName"]
fulltaskname = phab.phid.query(phids=[data["object"]["phid"]])[data["object"]["phid"]]["fullName"] fulltaskname = phab.phid.query(phids=[data["object"]["phid"]])[data["object"]["phid"]]["fullName"]
link = "\x032" + phab.phid.query(phids=[data["object"]["phid"]])[data["object"]["phid"]]["uri"] link = "\x032" + phab.phid.query(phids=[data["object"]["phid"]])[data["object"]["phid"]]["uri"]
if commentid: if commentid:
link = link + "#" + str(commentid) + "\x03" link = link + "#" + str(commentid) + "\x03"
else: else:
link = link + "\x03" link = link + "\x03"
message = "\x033[\x03\x0313"+ fulltaskname +"\x03\x033]\x03 \x0315" + str(who) + "\x03 " message = "\x033[\x03\x0313"+ fulltaskname +"\x03\x033]\x03 \x0315" + str(who) + "\x03 "
if comment: if comment:
message = message + "commented on the task: " + link message = message + "commented on the task: " + link
elif edited: elif edited:
message = message + "edited a message on the task: " + link message = message + "edited a message on the task: " + link
elif newtask: elif newtask:
message = message + "just created this task: " + link message = message + "just created this task: " + link
print(message) print(message)
sendnotice(message) sendnotice(message)
elif data["object"]["type"] == "CMIT":
print("It's a commit!")
return "OK" return "OK"

Loading…
Cancel
Save