-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Conversation
There was a problem hiding this 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=
:
readthedocs.org/readthedocs/builds/tasks.py
Line 453 in 90d611d
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
readthedocs.org/readthedocs/oauth/services/github.py
Lines 459 to 460 in 90d611d
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:
readthedocs.org/readthedocs/builds/models.py
Lines 352 to 355 in f86b537
return self.project.get_docs_url( | |
version_slug=self.slug, | |
external=external, | |
) |
Footnotes
-
in that case we link directly to the built documentation from the PR ↩
This was because we were using this logic to return a relative URL, and then sending it to GitHub: * https://github.com/readthedocs/readthedocs.org/blob/f86b5376ffc70242bdd677cb02f016429ff6bd4b/readthedocs/oauth/services/github.py#L459-L460 * https://github.com/readthedocs/readthedocs.org/blob/f86b5376ffc70242bdd677cb02f016429ff6bd4b/readthedocs/builds/models.py#L343-L349 Fixes #9791
2142b62
to
0e2f770
Compare
I think I misunderstood this code, so I made it a bit more explicit. |
readthedocs/oauth/services/github.py
Outdated
@@ -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: |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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`
@ericholscher I found this PR while surfing 🏄🏼 . I updated with my proposal that removes |
There was a problem hiding this 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😆
This was because we were using this logic to return a relative URL,
and then sending it to GitHub:
readthedocs.org/readthedocs/oauth/services/github.py
Lines 459 to 460 in f86b537
readthedocs.org/readthedocs/builds/models.py
Lines 343 to 349 in f86b537
Fixes #9791