Skip to content

Conversation

@m-blaha
Copy link
Member

@m-blaha m-blaha commented Dec 18, 2025

Post a comment on the commit only when the commit SHA is available. Otherwise, post on the pull request; if the pull request ID is also unavailable, log a warning.

Resolves issue when GitlabAPIException was raised from exception handler preventing CoprBuildEndHandler to finish correctly.

Resolves: #2838

@m-blaha m-blaha requested a review from a team as a code owner December 18, 2025 14:47
@m-blaha m-blaha requested review from nforro and removed request for a team December 18, 2025 14:47
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request effectively addresses an exception handling issue in set_status when falling back to posting a comment. The new logic, which checks for a commit SHA, then a pull request ID, before logging a warning, is a robust improvement and has been correctly applied to the GitHub, GitLab, and Pagure reporters. The accompanying test changes are thorough and correctly validate the new behavior.

I have one suggestion to refactor duplicated exception handling logic into the base class to improve maintainability. Please see my comment.

Comment on lines 61 to 82
if self.commit_sha:
logger.debug(
f"Failed to set status for {self.commit_sha},"
f" commenting on commit as a fallback: {e}",
)
self._add_commit_comment_with_status(state, description, check_name, url)
elif self.pr_id:
logger.debug(
f"Failed to set status and no commit SHA available,"
f" commenting on PR {self.pr_id} as a fallback: {e}",
)
self.report_status_by_comment(
state,
url,
check_name,
description,
)
else:
logger.warning(
f"Failed to set status and cannot comment as a fallback,"
f" no commit SHA and no PR id: {e}",
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This exception handling logic is duplicated in packit_service/worker/reporting/reporters/gitlab.py. To improve maintainability and reduce code duplication, consider moving this logic to a new method in the StatusReporter base class in packit_service/worker/reporting/reporters/base.py.

For example, you could add a method like _handle_set_status_failure to StatusReporter:

# in packit_service/worker/reporting/reporters/base.py
def _handle_set_status_failure(self, e, state, description, check_name, url):
    if self.commit_sha:
        logger.debug(
            f"Failed to set status for {self.commit_sha},"
            f" commenting on commit as a fallback: {e}",
        )
        self._add_commit_comment_with_status(state, description, check_name, url)
    elif self.pr_id:
        logger.debug(
            f"Failed to set status and no commit SHA available,"
            f" commenting on PR {self.pr_id} as a fallback: {e}",
        )
        self.report_status_by_comment(
            state,
            url,
            check_name,
            description,
        )
    else:
        logger.warning(
            f"Failed to set status and cannot comment as a fallback,"
            f" no commit SHA and no PR id: {e}",
        )

Then you could call this helper from both StatusReporterGithubStatuses and StatusReporterGitlab.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, I've implemented it.

@centosinfra-prod-github-app
Copy link
Contributor

Post a comment on the commit only when the commit SHA is available.
Otherwise, post on the pull request; if the pull request ID is also
unavailable, log a warning.

Resolves: packit#2838

Signed-off-by: Marek Blaha <mblaha@redhat.com>
Signed-off-by: Marek Blaha <mblaha@redhat.com>
@centosinfra-prod-github-app
Copy link
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: new

Development

Successfully merging this pull request may close these issues.

GitlabAPIException: Commit None was not found.

1 participant