Skip to content
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

Auto Build Documentation on Pull Request (PR Builder) #5828

Merged
merged 9 commits into from
Jun 21, 2019

Conversation

saadmk11
Copy link
Member

This is the PR which will have all the initial code for the PR Builder.
There are lots of stuff that need to be done.
ref: #1340 #5684

ericholscher and others added 6 commits June 20, 2019 00:30
This is just an initial proof of concept.
We still need to update the External type properly,
and do lots of other work.
This is just a start to show how we can sync and build them.
@saadmk11 saadmk11 added the PR: work in progress Pull request is not ready for full review label Jun 19, 2019
@saadmk11 saadmk11 requested review from ericholscher and a team June 19, 2019 18:35
@saadmk11 saadmk11 changed the title Auto Create Documentation on Pull Request (PR Builder) Auto Build Documentation on Pull Request (PR Builder) Jun 19, 2019
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.

This looks like a good start. Thinking more about this, we probably need to figure out a better flow for syncing an incoming PR version. If we could create the Version then, and trigger a build for it, that seems like a better approach. We still likely want to sync it via VCS as well though, but I'm not 100% sure :/

verbose_name=version_name,
)
added.add(created_version.slug)

Copy link
Member

Choose a reason for hiding this comment

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

Isn't this line the same as the line below it? Why do we need this extra logic?

version.active = True
version.save()

trigger_build(project=project, version=version)
Copy link
Member

Choose a reason for hiding this comment

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

We definitely don't want to trigger all builds for external versions. This will create hundreds of builds on first import. We need a better mechanism for this I think.

@@ -271,6 +274,10 @@ def handle_webhook(self):
raise ParseError('Parameter "ref" is required')
if event in (GITHUB_CREATE, GITHUB_DELETE):
return self.sync_versions(self.project)

if event == GITHUB_PULL_REQUEST:
return self.sync_versions(self.project)
Copy link
Member

Choose a reason for hiding this comment

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

This might be the place where we want to trigger a build after syncing. I'm not 100% sure though.

Copy link
Member

Choose a reason for hiding this comment

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

We might need to think a bit more about how we're doing version syncing actually. I think maybe in this case we can just create the version via the incoming PR and trigger the build. That way we don't need to clone the repo 2x.

Copy link
Member Author

@saadmk11 saadmk11 left a comment

Choose a reason for hiding this comment

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

I left some comments to explain why I did those. It would be great to have review

def get_external_version_data(self):
"""Get Commit Sha and pull request number from payload"""
identifier = self.data['pull_request']['head']['sha']
verbose_name = str(self.data['number'])
Copy link
Member Author

Choose a reason for hiding this comment

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

here I'm considering PR_Number as verbose name.

external_version = get_or_create_external_version(
self.project, identifier, verbose_name
)
return self.get_response_push(self.project, external_version.verbose_name)
Copy link
Member Author

Choose a reason for hiding this comment

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

To use the pre-written self.get_response_push() we can not pass a version instance so here I passed the verbose name but I think it will be much better if we pass the instance. to do this we need to create another function and not use self.get_response_push() we might use that function to send triggered status on the PR using the Github Status API. I would like to get you thought on this :)

Copy link
Member

Choose a reason for hiding this comment

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

Yea, we can use whatever makes sense. If it's doing something different than existing code, don't feel bad coming up with a new method.

return self.get_response_push(self.project, external_version.verbose_name)

except KeyError:
raise ParseError('Parameters "sha" and "number" are required')
Copy link
Member Author

Choose a reason for hiding this comment

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

The Error message can be changed

def get_or_create_external_version(project, identifier, verbose_name):
external_version = project.versions(manager=EXTERNAL).filter(verbose_name=verbose_name).first()
if external_version:
if external_version.identifier != identifier:
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 will be updated when there is a new commit in the PR

Copy link
Member

Choose a reason for hiding this comment

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

This is probably better in a code comment, not a PR comment that will be lost :)

@@ -138,7 +138,7 @@ def sync_repo(self):
}
)
version_repo = self.get_vcs_repo()
version_repo.update()
version_repo.update(version=self.version)
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 need to pass the version here so that we can determine which PR should be fetched. there previous implementation fetched all the PR's all together regardless it was open or closed

Copy link
Member

Choose a reason for hiding this comment

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

Seems like a good and small change 👍

@saadmk11 saadmk11 requested a review from ericholscher June 21, 2019 12:30

if (
event == GITHUB_PULL_REQUEST and
self.data['action'] in [GITHUB_PULL_REQUEST_OPEN, GITHUB_PULL_REQUEST_SYNC]
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 will handle both PR opened and synchronized (new commit in the PR) events.

Copy link
Member

Choose a reason for hiding this comment

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

Tested it locally and it worked great 👍

@ericholscher
Copy link
Member

This approach looks good to me, so far!

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.

Good to merge into the feature branch 👍

@ericholscher ericholscher merged commit 12f6658 into readthedocs:gsoc-19-pr-builder Jun 21, 2019
@saadmk11 saadmk11 deleted the pr-builder branch June 21, 2019 19:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: work in progress Pull request is not ready for full review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants