Skip to content

PR previews: Warn users when enabling the feature on incompatible projects #9291

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 5 commits into from
Jun 28, 2022

Conversation

stsewd
Copy link
Member

@stsewd stsewd commented Jun 2, 2022

Closes #9176

@stsewd stsewd requested review from a team as code owners June 2, 2022 17:50
@stsewd stsewd requested a review from ericholscher June 2, 2022 17:50
for integration in integrations:
provider_data = integration.provider_data
if integration.integration_type == Integration.GITHUB_WEBHOOK and (
not provider_data or "pull_request" in provider_data.get("events", [])
Copy link
Member Author

@stsewd stsewd Jun 2, 2022

Choose a reason for hiding this comment

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

We could resync the webhook for the user if we don't see they have the pull request event, this is probably the case of old webhooks only, new webhooks are created with the full events.

Copy link
Member

Choose a reason for hiding this comment

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

If it's safe to re-sync the webhook on behalf of the user, I'd say we should do it automatically. Otherwise, we could send the user a notification that we recommend them to re-sync the webhook to enable the feature.

@stsewd stsewd force-pushed the alert-users-invalid-setup-pr-builds branch from 47546f5 to 0083640 Compare June 2, 2022 18:21
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.

Looks good. I left some comments in case we can simplify the logic a little bit because the double negated if was hard to read and follow to me.

Besides, I think we should make the "Manual webhook created" case not allow pull request builds because we are not 100% sure that it will work.

if msg:
field = self.fields["external_builds_enabled"]
field.disabled = True
field.help_text = msg + " " + field.help_text
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
field.help_text = msg + " " + field.help_text
field.help_text = f"{msg} {field.help_text}"

if not self.has_supported_integration(integrations):
msg = _(
"To build from pull requests you need a "
'GitHub or GitLab <a href="{url}">integration</a>.'
Copy link
Member

Choose a reason for hiding this comment

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

Where are we populating this {url} in the string? I didn't find it.

Maybe it's missing an f at the beginning?

Suggested change
'GitHub or GitLab <a href="{url}">integration</a>.'
f'GitHub or GitLab <a href="{url}">integration</a>.'

"""Disable the external builds option if the project doesn't meet the requirements."""
msg = None
url = reverse("projects_integrations", args=[self.instance.slug])
integrations = list(self.instance.integrations.all())
Copy link
Member

Choose a reason for hiding this comment

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

Why are you converting this to a list here?

Copy link
Member Author

Choose a reason for hiding this comment

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

this saves one query later where we use len(integations) instead of .count()

)
elif not self.can_build_external_versions(integrations):
# If there is only one integration, link directly to it.
if len(integrations) == 1:
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if len(integrations) == 1:
if integrations.count() == 1:

Comment on lines +322 to +325
If the integration's provider data isn't set,
it could mean that the user created the integration manually,
and doesn't have an account connected.
So we don't know for sure if the webhook is sending pull request events.
Copy link
Member

Choose a reason for hiding this comment

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

We should mark this case as "can't build external versions". Otherwise, some people will enable it and it won't work. It's better to let people enable the feature if we are 100% sure it will work.

Besides, these cases will be hard to track and debug when receiving a support request like "My PRs are not building".

Copy link
Member Author

Choose a reason for hiding this comment

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

We should still support those cases, these are users using an enterprise instance of GitHub or users that don't want to give full permissions to RTD by connecting their accounts.

Copy link
Member Author

Choose a reason for hiding this comment

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

They won't receive the commit status, but at least the PR will build.

Copy link
Member

Choose a reason for hiding this comment

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

They won't receive the commit status, but at least the PR will build.

Seems we should at least mention this in the UI as help text, then.

for integration in integrations:
provider_data = integration.provider_data
if integration.integration_type == Integration.GITHUB_WEBHOOK and (
not provider_data or "pull_request" in provider_data.get("events", [])
Copy link
Member

Choose a reason for hiding this comment

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

If it's safe to re-sync the webhook on behalf of the user, I'd say we should do it automatically. Otherwise, we could send the user a notification that we recommend them to re-sync the webhook to enable the feature.

from readthedocs.projects.models import Project


class TestExternalBuildOption(TestCase):
Copy link
Member

Choose a reason for hiding this comment

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

Why are we testing this under test_views.py? Shouldn't we test this under test_forms.py since the logic change was on the form itself and does not depends on a view?

Copy link
Member Author

Choose a reason for hiding this comment

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

I like testing most things at the view level, it covers more code instead of just the form.

Copy link
Member

@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.

I think this is a good change, and we should ship it. There's some ideas for improvement, but overall having this PR is better than not.

@stsewd stsewd enabled auto-merge (squash) June 28, 2022 19:54
@stsewd stsewd merged commit f87e99f into main Jun 28, 2022
@stsewd stsewd deleted the alert-users-invalid-setup-pr-builds branch June 28, 2022 19:59
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.

Warn user when pull request events are not enabled
3 participants