From a4906db619c98d2dc8be600412522f7893d38d56 Mon Sep 17 00:00:00 2001 From: Tobias Henkel Date: Fri, 12 Feb 2021 09:39:00 +0100 Subject: [PATCH] Gracefully handle non-existent label on unlabel When unlabling and the label is non-existing on an issue zuul fails to continue to report with other actions like the check run result. This is caused by not handling the NotFoundError thrown by github3 in this case [1]. Handle and ignore this exception to fix this. [1] Trace: ERROR zuul.GithubReporter: Exception processing report item Traceback (most recent call last): File "/opt/zuul/lib/python3.8/site-packages/zuul/reporter/__init__.py", line 76, in doReport ret = self.report(item) File "/opt/zuul/lib/python3.8/site-packages/zuul/driver/github/githubreporter.py", line 90, in report self.setLabels(item) File "/opt/zuul/lib/python3.8/site-packages/zuul/driver/github/githubreporter.py", line 305, in setLabels self.connection.unlabelPull(project, pr_number, label, File "/opt/zuul/lib/python3.8/site-packages/zuul/driver/github/githubconnection.py", line 1974, in unlabelPull pull_request.remove_label(label) File "/opt/zuul/lib/python3.8/site-packages/github3/decorators.py", line 31, in auth_wrapper return func(self, *args, **kwargs) File "/opt/zuul/lib/python3.8/site-packages/github3/issues/issue.py", line 383, in remove_label json = self._json(self._delete(url), 200, 404) File "/opt/zuul/lib/python3.8/site-packages/github3/models.py", line 156, in _json raise exceptions.error_for(response) github3.exceptions.NotFoundError: 404 Label does not exist Change-Id: I29e14d6c5851e3869e0fff14c46113c4d2fde07e --- zuul/driver/github/githubconnection.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/zuul/driver/github/githubconnection.py b/zuul/driver/github/githubconnection.py index 8c1ceecccb..550fc0cd7c 100644 --- a/zuul/driver/github/githubconnection.py +++ b/zuul/driver/github/githubconnection.py @@ -1934,7 +1934,11 @@ class GithubConnection(CachedBranchConnection): github = self.getGithubClient(project, zuul_event_id=zuul_event_id) owner, proj = project.split('/') pull_request = github.issue(owner, proj, pr_number) - pull_request.remove_label(label) + try: + pull_request.remove_label(label) + except github3.exceptions.NotFoundError: + # The label is not existing, so everything ok + log.debug('Label %s not found on %s#%s', label, proj, pr_number) log.debug("Removed label %s from %s#%s", label, proj, pr_number) def updateCheck(self, project, pr_number, sha, status, completed, context,