Automatically switch to branch after merge request creation#149
Open
subhajitlucky wants to merge 1 commit into
Open
Automatically switch to branch after merge request creation#149subhajitlucky wants to merge 1 commit into
subhajitlucky wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR addresses issue #51 by automatically switching the local git workspace to the newly created merge request’s source branch as part of the issue/MR creation flow, and adds a regression test to ensure the branch switch is triggered.
Changes:
- Update
startIssueCreationto automatically fetch and checkout the created MR source branch. - Add a new
checkoutBranchhelper that fetchesoriginand checks out/creates the branch locally. - Add a unit test covering the issue creation flow to verify the branch switch call occurs.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
gitHappens.py |
Automatically checks out the MR source branch after MR creation and adds checkoutBranch. |
tests/test_start_issue_creation.py |
Adds a regression test ensuring the issue/MR creation flow triggers a branch checkout. |
tests/__init__.py |
Adds a tests package marker file. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+339
to
+340
| checkoutBranch(createdMergeRequest['source_branch']) | ||
| print(f"Switched to branch {createdMergeRequest['source_branch']}.") |
Comment on lines
+344
to
+349
| def checkoutBranch(branchName): | ||
| subprocess.check_call(['git', 'fetch', 'origin']) | ||
| try: | ||
| subprocess.check_call(['git', 'checkout', branchName]) | ||
| except subprocess.CalledProcessError: | ||
| subprocess.check_call(['git', 'checkout', '-b', branchName, f'origin/{branchName}']) |
Comment on lines
+10
to
+26
| root = Path(__file__).resolve().parents[1] | ||
| config_dir = root / "configs" | ||
| config_dir.mkdir(exist_ok=True) | ||
| (config_dir / "config.ini").write_text( | ||
| "[DEFAULT]\n" | ||
| "base_url=https://gitlab.example\n" | ||
| "group_id=1\n" | ||
| "custom_template=Custom\n" | ||
| "GITLAB_TOKEN=test-token\n" | ||
| "squash_commits=true\n" | ||
| "delete_branch_after_merge=true\n", | ||
| encoding="utf-8", | ||
| ) | ||
| (config_dir / "templates.json").write_text( | ||
| '{"templates": [], "reviewers": []}', | ||
| encoding="utf-8", | ||
| ) |
Comment on lines
+34
to
+38
| sys.modules["inquirer"] = inquirer_stub | ||
|
|
||
| spec = importlib.util.spec_from_file_location("gitHappens_under_test", root / "gitHappens.py") | ||
| module = importlib.util.module_from_spec(spec) | ||
| spec.loader.exec_module(module) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #51.
Summary
Verification
python3 -m unittest tests.test_start_issue_creation -vpython3 -m unittest discover -vpython3 -m compileall gitHappens.py testsgit diff --check