log the work item id when notifying ado (#2291)

* log the work item id when notifying ado

* format

* refactoring

* fix build

* fix

* format
This commit is contained in:
Cheick Keita
2022-08-26 12:08:31 -07:00
committed by GitHub
parent 55a29cf1cd
commit c94ae0bbb6

View File

@ -135,7 +135,7 @@ class ADO:
continue continue
yield item yield item
def update_existing(self, item: WorkItem) -> None: def update_existing(self, item: WorkItem, notification_info: str) -> None:
if self.config.on_duplicate.comment: if self.config.on_duplicate.comment:
comment = self.render(self.config.on_duplicate.comment) comment = self.render(self.config.on_duplicate.comment)
self.client.add_comment( self.client.add_comment(
@ -175,6 +175,13 @@ class ADO:
if document: if document:
self.client.update_work_item(document, item.id, project=self.project) self.client.update_work_item(document, item.id, project=self.project)
logging.info(
f"notify ado: updated work item {item.id} - {notification_info}"
)
else:
logging.info(
f"notify ado: no update for work item {item.id} - {notification_info}"
)
def render_new(self) -> Tuple[str, List[JsonPatchOperation]]: def render_new(self) -> Tuple[str, List[JsonPatchOperation]]:
task_type = self.render(self.config.type) task_type = self.render(self.config.type)
@ -195,7 +202,7 @@ class ADO:
) )
return (task_type, document) return (task_type, document)
def create_new(self) -> None: def create_new(self) -> WorkItem:
task_type, document = self.render_new() task_type, document = self.render_new()
entry = self.client.create_work_item( entry = self.client.create_work_item(
@ -209,15 +216,19 @@ class ADO:
self.project, self.project,
entry.id, entry.id,
) )
return entry
def process(self) -> None: def process(self, notification_info: str) -> None:
seen = False seen = False
for work_item in self.existing_work_items(): for work_item in self.existing_work_items():
self.update_existing(work_item) self.update_existing(work_item, notification_info)
seen = True seen = True
if not seen: if not seen:
self.create_new() entry = self.create_new()
logging.info(
"notify ado: created new work item" f" {entry.id} - {notification_info}"
)
def is_transient(err: Exception) -> bool: def is_transient(err: Exception) -> bool:
@ -251,18 +262,16 @@ def notify_ado(
return return
notification_info = ( notification_info = (
"job_id:%s task_id:%s container:%s filename:%s", f"job_id:%s{report.job_id} task_id:{report.task_id}"
report.job_id, f" container:{container} filename:{filename}"
report.task_id,
container,
filename,
) )
logging.info("notify ado: %s", notification_info) logging.info("notify ado: %s", notification_info)
try: try:
ado = ADO(container, filename, config, report) ado = ADO(container, filename, config, report)
ado.connect() ado.connect()
ado.process() ado.process(notification_info)
except ( except (
AzureDevOpsAuthenticationError, AzureDevOpsAuthenticationError,
AzureDevOpsClientError, AzureDevOpsClientError,