我正在使用Matthew Walker的extract-msg模块(我喜欢);但是,msg.body在发布到Microsoft TFS(TFSAPI模块)时删除换行符时遇到问题。到目前为止,电子邮件的主题随签名一起出现,并且以前的答复使有时难以阅读。每封电子邮件都是不同的,所以我不确定如何拼接不需要的内容。
我不确定是引起问题的是TFSAPI还是extract-msg模块。
是否可以使换行符和格式与原始电子邮件保持一致?以下是TFS中显示的示例。
def e2tfs():
'''Extract details from emails and assign those fields to TFS Support Ticket'''
associate = form.getvalue('associate')
i=1
for file in os.listdir():
src = file
msg = extract_msg.Message(src)
msg_sender = msg.sender
msg_date = msg.date
msg_subj = msg.subject
msg_message = msg.body
i+=1
#Associate the emails details to the TFS fields
fields = {'System.Title' : 'E2TFS: {}'.format(msg_subj),
'Microsoft.VSTS.CMMI.Symptom': 'body: {}' .format(msg_message),
'Microsoft.VSTS.TCM.ReproSteps': 'TBD',
'Regions.Custom.DocumentationArea': 'Unknown',
'Regions.Custom.Application': 'nCino',
'Regions.Custom.Channel': 'Email',
'Microsoft.VSTS.CMMI.FoundInEnvironment': 'Production',
'Regions.Custom.ImpactedAssociate': 'Sender: {}'.format(msg_sender),
'Regions.Custom.Associate_Role': 'ALL USERS',
'Regions.Custom.BusinessGroupsImpacted2': 'All Business Groups',
'AFS.phase.dev': 'ALL USERS',
'Regions.Custom.PriorityCustomField': 'High',
'Regions.Custom.CaseOwner': associate,
'History': 'Ticket created from email sent directly to CBG Level II Support on {}'.format(msg_date)
}
client.create_workitem('Support Ticket', fields=fields)
query_tfs = "SELECT [System.Id], [System.Title] FROM workitems WHERE [System.CreatedDate] = @today AND [System.CreatedBy] = @me AND [System.WorkItemType] = 'Support Ticket'"
wiql = client.run_wiql(query_tfs)
# Get all found workitems
workitems = wiql.workitems
tfs_number = workitems[-1]['Id']
答案 0 :(得分:0)
下面是powershell脚本中的一个示例,该示例使用workitem update api来更新工作项description
字段
您还可以在Get Start页上参考其他编程语言的其他示例
$url= "https://dev.azure.com/{org}/{project}_/apis/wit/workitems/{workitem id}?api-version=5.1"
$body = '[
{
"op": "add",
"path": "/fields/System.Description",
"value": "<p>This is a H1 header<br/>This is a H2 header</p>"
}
]'
$connectionToken="<PAT>"
$base64AuthInfo= [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($connectionToken)"))
$result7 = Invoke-RestMethod -Uri $url -Headers @{authorization = "Basic $base64AuthInfo"} -Method patch -ContentType "application/json-patch+json" -Body $body