question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow setting reviewers when using github_pull_request

See original GitHub issue

I would like to be able to set the reviewers for PRs created through all-repos.

all-repos-sed ... --reviewers mycolleague

I was going to implement this as a custom push module, but currently push modules can only receive Settings and branch_name.

One approach would be to implement push strategies as classes with a hook for adding additional parser arguments. Something like:

class GitHubPullRequest(BasePushStrategy):
    def add_arguments(self, parser: ParserType):
        parser.add_arguments("--reviewers", nargs="*")

   # or "def handle",  to match Django's management commands
    def __call__(self, settings: Settings, branch_name: str, parsed_args: Any) -> None:
        # ...
        resp = github_api.req(
            f"{settings.base_url}/repos/{repo_slug}/pulls",
            data=data,
            headers=headers,
            method="POST",
        )
        url = resp.json["url"]
        html_url = resp.json["html_url"]
        print(f"Pull request created at {html_url}")
        reviewers = parsed_args.reviewers
        if reviewers:
            resp = github_api.req(
                f"{url}/requested_reviewers",
                data=json.dumps({"reviewers": reviewers}).encode(),
                headers=headers,
                method="POST",
            )
            print(f"Requested review from {reviewers}")

The "push" config in all-repos.json would point to these classes instead of modules.

{
  "push": "all_repos.push.GitHubPullRequest"
}

Open questions:

  1. Is the above interface a good idea? 1a. If so, is it OK to implement it as a breaking change?
  2. Should the “reviewer” functionality be included in all-repos core?

I don’t have a strong feeling on 2. As long as there’s a way to do it, I’m fine keeping it as custom code outside of core to start. Up to you, @asottile

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:12 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
sloriacommented, May 8, 2020

Fair enough–I can see how allowing plugins to define their own arguments could open Pandora’s Box.

it may make more sense to configure these things in the particular plugins (config files, environment variables, etc. come to mind as alternative ways to accomplish this)

Sure, this seems workable. With https://github.com/asottile/all-repos/pull/132 , I’d be able to do something like

# github_pull_request_with_reviewers.py
from all_repos.push.github_pull_request import make_pull_request

def push(...):
    resp = make_pull_request(settings, branch_name)
    reviewers = os.environ.get('GH_REVIEWERS', '').split(',')
    if reviewers:
        url = resp.json['url']
        resp = github_api.req(
            f"{url}/requested_reviewers",
            data=json.dumps({"reviewers": reviewers}).encode(),
            headers=headers,
            method="POST",
        )
0reactions
sloriacommented, May 8, 2020

thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Managing code review settings for your team - GitHub Docs
In this article​​ Team maintainers and organization owners can configure code review settings. Code review settings are available in all public repositories ...
Read more >
Requesting a pull request review - GitHub Docs
Requesting a pull request review · Under your repository name, click Pull requests. · In the list of pull requests, click the pull...
Read more >
About pull request reviews - GitHub Docs
Reviews allow collaborators to comment on the changes proposed in pull requests, approve the changes, or request further changes before the pull request...
Read more >
Managing pull request reviews in your organization
In the top right corner of GitHub.com, click your profile photo, then click Your organizations. · Next to the organization, click Settings. ·...
Read more >
Approving a pull request with required reviews - GitHub Docs
Under your repository name, click Pull requests. · In the list of pull requests, click the pull request you'd like to review. ·...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found