Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skipping CCd users without GAIA accounts for buganizer issues #4406

Merged
merged 7 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/clusterfuzz/_internal/cron/oss_fuzz_apply_ccs.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ def cc_users_for_job(job_type, security_flag):


def main():
"""Cron handler for adding new CC's to oss-fuzz bugs.."""
"""Cron handler for adding new CC's to oss-fuzz bugs."""
error_count = 0
for testcase in get_open_testcases_with_bugs():
issue_tracker = issue_tracker_utils.get_issue_tracker_for_testcase(testcase)
if not issue_tracker:
Expand Down Expand Up @@ -67,7 +68,16 @@ def main():
logging.info('CCing %s on %s', cc, issue.id)
issue.ccs.add(cc)

issue.save(notify=True)
try:
issue.save(notify=True)
except Exception as e:
error_count += 1
logging.error('Failed to apply ccs for test case '
'%s: %s.', testcase.key, e)

if error_count:
vitorguidi marked this conversation as resolved.
Show resolved Hide resolved
logging.error('OSS fuzz apply ccs failed.')
return False

logging.info('OSS fuzz apply ccs succeeded.')
return True
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

import datetime
import enum
import functools
import re
from typing import List
from typing import Optional
from typing import Sequence
Expand Down Expand Up @@ -68,6 +70,24 @@ def _get_access_limit_from_labels(labels: issue_tracker.LabelStore):
return None


def retry_on_invalid_gaia_accounts(func):
"""Decorator to retry saving an issue, skipping CCs
without a GAIA account."""

@functools.wraps(func)
def wrapper(self, *args, **kwargs):
try:
return func(self, *args, **kwargs)
except Exception as e:
# Try to handle the case where a 400 buganizer response is
# received due to a non gaia email.
email_regex = r'[\w\.\-\+]+@[\w\.-]+'
emails_to_skip = re.findall(email_regex, str(e))
return func(self, *args, **kwargs, skip_emails=emails_to_skip)

return wrapper


class IssueTrackerError(Exception):
"""Base issue tracker error."""

Expand Down Expand Up @@ -719,8 +739,10 @@ def _update_issue(self, new_comment=None, notify=True):
issueId=str(self.id)))
return result

def save(self, new_comment=None, notify=True):
@retry_on_invalid_gaia_accounts
def save(self, new_comment=None, notify=True, skip_emails=[]): # pylint: disable=dangerous-default-value
"""Saves the issue."""
logs.info(f'Skipping supposed non gaia emails emails: {skip_emails}.')
if self._is_new:
logs.info('google_issue_tracker: Creating new issue..')
priority = _extract_label(self.labels, 'Pri-') or _DEFAULT_PRIORITY
Expand Down Expand Up @@ -793,7 +815,9 @@ def save(self, new_comment=None, notify=True):

if self.component_id:
self._data['issueState']['componentId'] = int(self.component_id)
ccs = list(self._ccs)
# TODO(vitorguidi): delete this hack once we have a solution for GAIA.
# Skip CCd users w/o a GAIA account
ccs = list(set(self._ccs) - set(skip_emails))
if ccs:
self._data['issueState']['ccs'] = _make_users(ccs)
collaborators = list(self._collaborators)
Expand Down Expand Up @@ -822,6 +846,10 @@ def save(self, new_comment=None, notify=True):
self._is_new = False
else:
logs.info('google_issue_tracker: Updating issue..')
# TODO(vitorguidi): remove this once we have a fix for GAIA.
# Remove all CCd users w/o GAIA accounts
for email in skip_emails:
self.ccs.remove(email)
result = self._update_issue(new_comment=new_comment, notify=notify)
self._reset_tracking()
self._data = result
Expand Down
Loading