Advertisement
Guest User

Untitled

a guest
Apr 19th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. def getTicketComments(ticketID):
  2. """ Gets a list of the comments (in order from oldest to newest) for a given ticket """
  3.  
  4. url = URL_PREFACE + "_apis/wit/workitems/" + str(ticketID) + "/comments?api-version=3.0-preview&order=asc"
  5. jsonDict = readURL(url)
  6.  
  7. return jsonDict["comments"]
  8.  
  9. commentList = getTicketComments(ticketID)
  10. hourSum = 0
  11. for comment in commentList:
  12. try:
  13. hourSum += float(comment["text"]) # Will break if it's not a number
  14. except:
  15. pass
  16.  
  17. def updateHours(ticketID, completedHours):
  18. """
  19. params = {
  20. "code": code,
  21. "client_id": CLIENT_ID,
  22. "client_secret" : CLIENT_SECRET,
  23. "redirect_uri": REDIRECT_URI,
  24. "grant_type": "authorization_code"
  25. }
  26. """
  27.  
  28. headers = {"Content-Type": "application/json-patch+json"}
  29.  
  30. url = URL_PREFACE + "_apis/wit/workitems/" + str(ticketID) + "?api-version=1.0"
  31.  
  32. body = """[
  33. {
  34. "op": "replace",
  35. "path": "/fields/Microsoft.VSTS.Scheduling.CompletedWork",
  36. "value": """ + str(completedHours) + """
  37. }
  38. ]"""
  39.  
  40. username = 'username' # Doesn't matter
  41. password = token
  42.  
  43. session = requests.Session()
  44. request = requests.Request(method="PATCH", headers=headers, auth=(username, password),
  45. url=url, data=body)
  46. prepped = request.prepare()
  47. response = session.send(prepped)
  48.  
  49. return response
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement