Skip to content

Commit 34c0790

Browse files
Merge pull request #3 from yousefsalhamoud/make-draft-prs-as-a-cli-option
draft pr as a user input
2 parents b1e4bec + 23356fb commit 34c0790

8 files changed

Lines changed: 27 additions & 8 deletions

File tree

.github/pull_request_template.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ Fixes # (issue)
2525
- [ ] I have made corresponding changes to the documentation
2626
- [ ] My changes generate no new warnings (I have run `ruff check .` and `ruff format .`)
2727
- [ ] I have added tests that prove my fix is effective or that my feature works
28-
- [ ] New and existing unit tests pass locally with my changes
28+
- [ ] New and existing unit tests pass locally with my changes

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@ jobs:
3737
python -m pip install --upgrade pip
3838
pip install .[all]
3939
- name: Run tests
40-
run: pytest
40+
run: pytest

.pre-commit-config.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ repos:
33
rev: v4.5.0
44
hooks:
55
- id: trailing-whitespace
6+
exclude: ^src/dwh2looker/lookml_generator/templates/
67
- id: end-of-file-fixer
8+
exclude: ^src/dwh2looker/lookml_generator/templates/
79
- id: check-yaml
810
- id: check-added-large-files
911

@@ -13,5 +15,7 @@ repos:
1315
# Run the linter.
1416
- id: ruff
1517
args: [ --fix ]
18+
exclude: ^src/dwh2looker/lookml_generator/templates/
1619
# Run the formatter.
1720
- id: ruff-format
21+
exclude: ^src/dwh2looker/lookml_generator/templates/

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,4 @@ Currently, we strongly support Google BigQuery. If you want to add support for S
7474
2. You will need to implement a new client class that inherits from the base class or implements the necessary interface to extract schema information.
7575
3. Ensure you add the necessary dependencies to `pyproject.toml` as optional dependencies.
7676

77-
Thank you for contributing!
77+
Thank you for contributing!

readme.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ Example `tables_env` configuration for Workload Identity in GitHub Actions:
110110
"env": "cprod",
111111
"dataset_id": "dataset_id",
112112
"project_id": "project_id",
113-
"credentials_path": "./gcp_creds_cprod.json"
113+
"credentials_path": "./gcp_creds_cprod.json"
114114
},
115115
{
116116
"env": "prod",
@@ -163,7 +163,7 @@ Example `tables_env` configuration for Workload Identity in GitHub Actions:
163163
"env": "cprod",
164164
"dataset_id": "dataset_id",
165165
"project_id": "project_id",
166-
"credentials_path": "./gcp_creds_cprod.json"
166+
"credentials_path": "./gcp_creds_cprod.json"
167167
},
168168
{
169169
"env": "prod",
@@ -238,6 +238,7 @@ This command created the LookML base views.
238238
- `--token` (type: str, required: False): GitHub Token.
239239
- `--github-app` (action: Boolean, default: False): Run as GitHub App (omit this flag if running with PAT).
240240
- `--push-lookml-to-looker` (action: Boolean, default: False): Push generated LookML to Looker via GitHub.
241+
- `--draft-pr` (action: Boolean, default: False): Create the Pull Request as a Draft.
241242
242243
243244
#### Examples
@@ -264,4 +265,4 @@ We welcome contributions to dwh2looker! Please see our [Contributing Guide](CONT
264265
265266
---
266267
267-
dwh2looker was inspired by Optician
268+
dwh2looker was inspired by Optician

src/dwh2looker/cli/commands.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ def cli():
7777
action="store_true",
7878
help="Push generated LookML to Looker via GitHub",
7979
)
80+
generate_lookml_parser.add_argument(
81+
"--draft-pr",
82+
action="store_true",
83+
help="Create the Pull Request as a Draft",
84+
)
8085

8186
args = parser.parse_args()
8287
if args.command == "diff_tracker":
@@ -124,6 +129,7 @@ def cli():
124129
push_lookml_to_looker=args.push_lookml_to_looker,
125130
github_token=args.token,
126131
github_app=args.github_app,
132+
draft_pr=args.draft_pr,
127133
)
128134
lookml.generate_batch_lookml_views(
129135
override_dataset_id=args.override_dataset_id,

src/dwh2looker/lookml_generator/lookml_generator.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,13 @@ def __init__(
3131
push_lookml_to_looker: bool = False,
3232
github_token: str = None,
3333
github_app: bool = False,
34+
draft_pr: bool = False,
3435
):
3536
self.db_type = db_type
3637
self.push_lookml_to_looker = push_lookml_to_looker
3738
self.github_token = github_token
3839
self.github_app = github_app
40+
self.draft_pr = draft_pr
3941
self.config = Config(os.getenv("dwh2looker_CONFIG_FILE"))
4042
self.primary_key_prefixes = self.config.get_property("primary_key_prefixes", [])
4143
self.foreign_key_prefixes = self.config.get_property(
@@ -392,6 +394,7 @@ def _push_lookml_to_repo(self):
392394
target_branch=branch_name,
393395
pr_title="dwh2looker ʕ•ᴥ•ʔ: Automated LookML Update",
394396
pr_body="This PR was automatically generated by dwh2looker the bear. Please review before merging, bears are bears after all.",
397+
draft=self.draft_pr,
395398
)
396399

397400
def generate_batch_lookml_views(self, override_dataset_id: str = None):

src/dwh2looker/vc_client/vc_client.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,12 @@ def update_files(
172172
return
173173

174174
def create_pull_request(
175-
self, base_branch: str, target_branch: str, pr_title: str, pr_body: str
175+
self,
176+
base_branch: str,
177+
target_branch: str,
178+
pr_title: str,
179+
pr_body: str,
180+
draft: bool = False,
176181
):
177182
# Create a pull request if it does not exist
178183
pulls = self.repo.get_pulls(state="open", sort="created", base=base_branch)
@@ -188,7 +193,7 @@ def create_pull_request(
188193
body=pr_body,
189194
base=base_branch,
190195
head=f"{target_branch}",
191-
draft=True,
196+
draft=draft,
192197
)
193198
CONSOLE_LOGGER.info(f"Pull request created: {pull_request.html_url}")
194199

0 commit comments

Comments
 (0)