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

[ADD] Pull request review script #346

Closed
wants to merge 7 commits into from
Closed

[ADD] Pull request review script #346

wants to merge 7 commits into from

Conversation

madman-bob
Copy link

Add a script to automatically review pull requests in the manner described in #203.

@jgrandguillaume
Copy link
Member

Hi @madman-bob

Thanks for your proposal ! On my side it looks good. I have one request for testing/fixing purpose:

Can you add a --dry-run option that will print the results instead of making them ?

Other than that, I've asked my colleague to review it as well.

Regards,

Joël

@madman-bob
Copy link
Author

Seems reasonable

Copy link
Member

@pedrobaeza pedrobaeza left a comment

Choose a reason for hiding this comment

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

Wow, excellent work! Thanks for this. Little comments, but very good

@@ -0,0 +1,167 @@
#!/usr/bin/env python
Copy link
Member

Choose a reason for hiding this comment

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

Is this working both on 2.7/3.x?

Copy link
Author

Choose a reason for hiding this comment

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

Tested in 2.7. Works in 3.6 with a minor change to config.py. Not using any particularly exciting language features, so should work in all 3.x.

pr_is_old = now - pull_request.created_at > timedelta(days=31 * 6)

if pr_is_old and full_pull_request.comments_count == 0:
pull_request.create_comment("Please re-open if necessary")
Copy link
Member

Choose a reason for hiding this comment

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

We can put here a longer text for not being rude, like:

This is an automatic message for telling you that this PR is going to be closed due to a long inactivity period.

Please ask for reopening if needed.
"""

Copy link

@LoisRForgeFlow LoisRForgeFlow Jun 12, 2018

Choose a reason for hiding this comment

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

Just a nitpicking comment here: isn't better to use the last update date? If some big PR is having a long discussion it will be auto-closed after 6 months even if there is recent conversations/reviews.

EDIT: Pedro already said that in the next review comment 😅 #346 (comment)

Copy link

@LoisRForgeFlow LoisRForgeFlow Jun 12, 2018

Choose a reason for hiding this comment

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

Then the comments_count could be removed (there are inactive PRs with comments)

now = datetime.now(pull_request.created_at.tzinfo)
pr_is_old = now - pull_request.created_at > timedelta(days=31 * 6)

if pr_is_old and full_pull_request.comments_count == 0:
Copy link
Member

Choose a reason for hiding this comment

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

We can have PRs with comments, but also abandoned. I think a better metric that the number of comments is the date of the PR < 6 months if no comment, but the date of the last comment < 6 months in case that you have comments.

Copy link
Author

Choose a reason for hiding this comment

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

I was just following the requirements as lain out in the original issue. You may well be right, but I don't really want to get into discussing what the best metrics are. It should be easy enough to change, and feel free to do so, if you want to.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, thanks, but as you know the API, please do it you. I give you my approval on behalf the @OCA/board

full_pull_request = repository.pull_request(pull_request.number)

now = datetime.now(pull_request.created_at.tzinfo)
pr_is_old = now - pull_request.created_at > timedelta(days=31 * 6)
Copy link
Member

Choose a reason for hiding this comment

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

Put directly 365 / 2 ~= 183

@pedrobaeza
Copy link
Member

I'm thinking right now about the GitHub rate limits, that can be a problem making this process. Look how I handled these limits when pulling Transifex translations. I wrap any GitHub call this way:

def wrap_gh_call(func, args=None, kwargs=None):
"""Intercept all GH calls to wait when the API rate limit is reached."""
retry = 0
while True:
try:
if args is None:
args = []
if kwargs is None:
kwargs = {}
return func(*args, **kwargs)
except (KeyboardInterrupt, SystemExit):
raise
except GitHubError as e:
if e.code == 403:
print("WARNING: %s. Sleeping 300 seconds" % e.message)
time.sleep(300)
elif e.code == 405:
retry += 1
if retry < 4:
print("WARNING: Temporary error: %s. Retrying..." % (
e.message
))
time.sleep(5)
else:
print("WARNING: GitHub error: %s. Aborting..." % (
e.message
))
break
else:
raise

and call it this way:

gh_branch = wrap_gh_call(gh_repo.branch, [oca_branch])

contributions = get_contribution_counts()

for pull_request in wrap_github_call(repository.pull_requests):
if contributions[pull_request.user.id] < 3:
Copy link
Member

Choose a reason for hiding this comment

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

I think this (and all other hardcoded values further down) should be arguments with the curernt value as default value

)

now = datetime.now(pull_request.created_at.tzinfo)
pr_is_old = now - pull_request.created_at > timedelta(days=31 * 6)
Copy link
Member

Choose a reason for hiding this comment

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

same thing as above

tag_new_pull_requests(repository_name, dry_run=args.dry_run)

if args.tag_all_new_pull_requests:
tag_all_new_pull_requests(dry_run=args.dry_run)
Copy link
Member

Choose a reason for hiding this comment

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

if you pass args to the functions, it's much simpler to implement my proposals above

Copy link
Member

Choose a reason for hiding this comment

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

@hbrunn OTOH passing args as arguments would make these functions harder to compose when we will want to run them behind a webhook.

github.repository,
[OCA_USERNAME, repository_name]
)
contributions = get_contribution_counts()
Copy link
Member

Choose a reason for hiding this comment

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

I have concerns about the performance of this.

Copy link
Author

Choose a reason for hiding this comment

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

In what way?

@madman-bob
Copy link
Author

Have rebased onto master, to resolve merge conflicts.

@max3903
Copy link
Member

max3903 commented Jul 3, 2018

@madman-bob Thank you for your contribution. The @OCA/board will be testing your script in the next few months so the merge may only happen at the OCA code sprint in Belgium in October. If you want to claim the bounty earlier, please start the process (I think you have to initiate the process).

@madman-bob
Copy link
Author

@max3903 Thanks, but I'm only allowed to start the bounty claim once the original issue has been closed.

@max3903
Copy link
Member

max3903 commented Jul 3, 2018

@madman-bob Done

@madman-bob
Copy link
Author

@max3903 Thank you very much. Claim submitted.

@pedrobaeza
Copy link
Member

@sbidoul can this be closed as it has been moved to specialized repo?

@sbidoul
Copy link
Member

sbidoul commented Nov 13, 2018

Yes!

@sbidoul sbidoul closed this Nov 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants