Skip to content

Commit

Permalink
Merge pull request #351 from clickthisnick/main
Browse files Browse the repository at this point in the history
Support creating draft PRs for Github Pull Requests
  • Loading branch information
asottile authored Nov 25, 2024
2 parents 15fb8f0 + 8fc85ff commit bc7df90
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 2 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -477,11 +477,12 @@ branch.

#### Optional `push_settings`

- `base_url` (default: `https://api.github.com`) is the base URL to the Github
API to use (for Github Enterprise support set this to `https://{your_domain}/api/v3`).
- `draft` (default: `false`) if true will open the pull request as a draft.
- `fork` (default: `false`): (if applicable) a fork will be created and pushed
to instead of the upstream repository. The pull request will then be made
to the upstream repository.
- `base_url` (default: `https://api.github.com`) is the base URL to the Github
API to use (for Github Enterprise support set this to `https://{your_domain}/api/v3`).

### `all_repos.push.bitbucket_server_pull_request`

Expand Down
2 changes: 2 additions & 0 deletions all_repos/push/github_pull_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Settings(NamedTuple):
base_url: str = 'https://api.github.com'
api_key: str | None = None
api_key_env: str | None = None
draft: bool = False

# TODO: https://github.com/python/mypy/issues/8543
def __repr__(self) -> str:
Expand Down Expand Up @@ -56,6 +57,7 @@ def make_pull_request(
'body': body.decode().strip(),
'base': autofix_lib.target_branch(),
'head': head,
'draft': settings.draft,
}).encode()

return github_api.req(
Expand Down
2 changes: 2 additions & 0 deletions tests/push/github_pull_request_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def test_github_pull_request(mock_urlopen, fake_github_repo):
assert data['title'] == 'This is a commit message'
assert data['body'] == 'Here is some more information!'
assert data['head'] == 'feature'
assert data['draft'] is False


@pytest.fixture
Expand Down Expand Up @@ -96,5 +97,6 @@ def test_settings_repr():
" base_url='https://api.github.com',\n"
' api_key=...,\n'
' api_key_env=None,\n'
' draft=False,\n'
')'
)
1 change: 1 addition & 0 deletions tests/util_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def test_hide_api_key_repr():
" base_url='https://api.github.com',\n"
' api_key=...,\n'
' api_key_env=None,\n'
' draft=False,\n'
')'
)

Expand Down

0 comments on commit bc7df90

Please sign in to comment.