Skip to content

Commit

Permalink
fix: Check out branch automatically on GitLab
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengrice committed Aug 19, 2024
1 parent b6a78cc commit 84c9bfd
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion docs/config/create_release.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ integrations:
gitlab:
create_release:
project: "60867298"
token_variable: "GITLAB_TOKEN"
token_variable: "SEMVER_TOKEN"
title_format: "v%M.%m.%p"
body: "Auto-generated release."
```
Expand Down
10 changes: 10 additions & 0 deletions src/pagekey_semver/git/effector.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ def push(self, remote: str, ref: str) -> None:
ref: Which commit, branch, or tag to push.
"""

def checkout(self, ref: str) -> None:
"""Check out a ref.
Args:
ref: Which commit, branch, or tag to checkout.
"""


class CommandGitEffector(GitEffector):
"""Use the Git CLI to make changes to Git."""
Expand All @@ -67,3 +74,6 @@ def create_tag(self, name: str) -> None:

def push(self, remote: str, ref: str) -> None:
self._runner.run(f"git push {remote} {ref}")

def checkout(self, ref: str) -> None:
self._runner.run(f"git checkout {ref}")
7 changes: 7 additions & 0 deletions src/pagekey_semver/git/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,15 @@ def apply_tag(self, existing_tags: List[Tag], new_tag: Tag) -> None:
new_tag: Tag to be added, if it does not already exist.
"""
if new_tag not in existing_tags:
# Check out branch on GitLab
gitlab_branch = os.getenv("CI_COMMIT_BRANCH", "")
if len(gitlab_branch) > 0:
print(f"Checking out CI_COMMIT_BRANCH={gitlab_branch}")
self._effector.checkout(gitlab_branch)

print(f"Tagging/pushing new tag: {new_tag}", flush=True)
original_git_config = self.get_existing_git_info()

self.set_git_remote()
self._effector.set_config_item("user.email", self._config.git.email)
self._effector.set_config_item("user.name", self._config.git.name)
Expand Down

0 comments on commit 84c9bfd

Please sign in to comment.