Skip to content

Fix status reporting on PRs with the magic exit code #9807

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

Merged
merged 8 commits into from
Feb 2, 2023
Merged

Conversation

ericholscher
Copy link
Member

@ericholscher ericholscher commented Dec 13, 2022

This was because we were using this logic to return a relative URL,
and then sending it to GitHub:

Fixes #9791

@ericholscher ericholscher requested a review from a team as a code owner December 13, 2022 18:48
@ericholscher ericholscher requested a review from humitos December 13, 2022 18:48
Copy link
Member

@humitos humitos left a comment

Choose a reason for hiding this comment

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

This looks good.

I think there are is a little more to dig into here, since it seems we are missing some cases. For example, in this part of the code we are not passing link_to_build=:

success = service.send_build_status(build, commit, status)

Also, it seems there is only one case where we want link_to_build=False (when the build completes successfully 1) and for all the other cases, we want link_to_build=True. However, we are using False as default argument having to change it in most of the cases. Inverting the default, or even better, removing the default and making it always explicit, would be easier to follow and will avoid the first problem that I found while reviewing this code.

Finally, this part of the workflow seems to be broken

if not link_to_build and state == BUILD_STATUS_SUCCESS:
target_url = build.version.get_absolute_url()

We were hitting it and generating relative URLs which GitHub does not accept that. Since we should never send relative URLs, we should delete that code completely to avoid hitting it again.

...

Aha! You linked to the first part of Version.get_absolute_url! However, the second part, uses a full absolute URL (not relative). See:

return self.project.get_docs_url(
version_slug=self.slug,
external=external,
)

Footnotes

  1. in that case we link directly to the built documentation from the PR

@ericholscher
Copy link
Member Author

I think I misunderstood this code, so I made it a bit more explicit.

@@ -456,7 +456,7 @@ def send_build_status(self, build, commit, state, link_to_build=False):
target_url = build.get_full_url()
statuses_url = f'https://api.github.com/repos/{owner}/{repo}/statuses/{commit}'

if not link_to_build and state == BUILD_STATUS_SUCCESS:
if not link_to_build and not build.version.built and not build.version.uploaded:
Copy link
Member Author

Choose a reason for hiding this comment

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

@humitos I wonder if this is actually the proper fix after all? Have it match the logic in get_absolute_url?

Copy link
Member

Choose a reason for hiding this comment

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

Hrm, I'm not 100% sure, but I don't think so. .built and .uploaded are not updated to False when a new build is triggered for the same version; so we will be reading an old value here.

IMO, we need this logic:

  • Successful build: link to documentation
  • Failed build: link to build details' page

As you may noted, the link to send does not depends on the "Commit build status" we sent to GitHub (state == BUILD_STATUS_SUCCESS, in that code), but it depends on the "status" of the build itself.

Actually, I'd completely remove link_to_build and just use the build's status inside this method. That way, we manage the logic just in one place and we don't have to worry about where and why we are passing link_to_build=False/True in different places of the code.

- remove `link_to_build` since it's not required
- base the decition on `Build.state` and `Build.success`
@humitos
Copy link
Member

humitos commented Jan 31, 2023

@ericholscher I found this PR while surfing 🏄🏼 . I updated with my proposal that removes link_to_build argument completely and decides linking to docs or build bases on Build.success and Build.state only. I pushed my changes directly to this PR, but we can revert them if you think they are not correct.

Copy link
Member Author

@ericholscher ericholscher left a comment

Choose a reason for hiding this comment

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

This is much cleaner and more obvious. I'm 👍 on shipping this!

@@ -483,7 +483,7 @@ def on_failure(self, exc, task_id, args, kwargs, einfo):
)

# NOTE: why we wouldn't have `self.data.build_commit` here?
# This attribute is set when we get it after clonning the repository
# This attribute is set when we get it after cloning the repository
Copy link
Member Author

Choose a reason for hiding this comment

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

😆

@humitos humitos enabled auto-merge (squash) February 2, 2023 12:20
@humitos humitos merged commit 2b33b0f into main Feb 2, 2023
@humitos humitos deleted the fix-status-report branch February 2, 2023 12:20
@humitos humitos mentioned this pull request Feb 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Conditionally skipped builds are "pending" instead of "passed"
2 participants