Skip to content

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

Merged
humitos merged 8 commits intomainfrom
fix-status-report
Feb 2, 2023
Merged

Fix status reporting on PRs with the magic exit code#9807
humitos merged 8 commits intomainfrom
fix-status-report

Conversation

@ericholscher
Copy link
Copy Markdown
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
Copy Markdown
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

Comment thread readthedocs/projects/tasks/builds.py Outdated
Comment thread readthedocs/projects/tasks/builds.py Outdated
@ericholscher
Copy link
Copy Markdown
Member Author

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

Comment thread readthedocs/oauth/services/github.py Outdated
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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!


# 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
Copy Markdown
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