Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- URL_PREFACE = "https://yourproject.visualstudio.com/defaultcollection/"
- def getTicketComments(ticketID):
- """ Gets a list of the comments (in order from oldest to newest) for a given ticket """
- url = URL_PREFACE + "_apis/wit/workitems/" + str(ticketID) + "/comments?api-version=3.0-preview&order=asc"
- jsonDict = readURL(url)
- return jsonDict["comments"]
- def getHoursSum(ticketID):
- """ For the given ticket, gets their comments, and calculates the hours
- """
- commentList = getTicketComments(ticketID)
- hourSum = 0
- for comment in commentList:
- try:
- hourSum += float(comment["text"]) # Will break if it's not a number
- except:
- pass
- return hourSum
- def updateHours(ticketID, completedHours):
- headers = {"Content-Type": "application/json-patch+json"}
- url = URL_PREFACE + "_apis/wit/workitems/" + str(ticketID) + "?api-version=1.0"
- body = """[
- {
- "op": "replace",
- "path": "/fields/Microsoft.VSTS.Scheduling.CompletedWork",
- "value": """ + str(completedHours) + """
- }
- ]"""
- username = 'username' # Doesn't matter
- password = TOKEN
- # TO GET TOKEN:
- # Log into https://yourproject.visualstudio.com/
- # Click on your name -> My Profile
- # In the left-hand sidebar, click on "Security"
- # Under "Personal Accesss Tokens," click "Add"
- # Under "Description" give your token a name (doesn't matter)
- # Choose an expiration for your token (recommend: 1 yr)
- # "Authorized Scopes" = "All Scopes"
- # Click "Save"
- # Copy the token it gives you into token field below (paste between quotes)
- session = requests.Session()
- request = requests.Request(method="PATCH", headers=headers, auth=(username, password),
- url=url, data=body)
- prepped = request.prepare()
- response = session.send(prepped)
- return response
Add Comment
Please, Sign In to add comment