Skip to content

Commit

Permalink
added commiting to repository
Browse files Browse the repository at this point in the history
  • Loading branch information
marwin1991 committed Nov 5, 2023
1 parent bd0d46f commit 662a6c8
Show file tree
Hide file tree
Showing 12 changed files with 82 additions and 10 deletions.
21 changes: 14 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,20 @@ RUN apk --update --no-cache add \
maven \
openjdk8

ADD requirements.txt /valhalla/
RUN pip3 install -r /valhalla/requirements.txt
ADD valhalla /valhalla/
ENV PYTHONPATH="${PYTHONPATH}:/valhalla"
ENV VALHALLA_SRC="/opt/valhalla/"
ADD requirements.txt $VALHALLA_SRC
RUN pip3 install -r ${VALHALLA_SRC}requirements.txt
ADD valhalla $VALHALLA_SRC/valhalla
ADD __main__.py $VALHALLA_SRC
ENV PYTHONPATH="${PYTHONPATH}:${VALHALLA_SRC}"

ARG WORKING_REPO_PATH="/repository"
RUN mkdir $WORKING_REPO_PATH
WORKDIR $WORKING_REPO_PATH

## TESTS
#ENV CI_COMMIT_BRANCH="release-1.2.3"
#ADD valhalla.yml /
ENV CI_COMMIT_BRANCH="release-1.2.3"
RUN git clone https://gitlab.com/peter.zmilczak/test-valhalla.git .
ADD valhalla.yml $WORKING_REPO_PATH

CMD ["python3", "./valhalla/main.py"]
CMD ["python3", "/opt/valhalla"]
4 changes: 4 additions & 0 deletions __main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from valhalla.main import start

if __name__ == '__main__':
start()
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
PyYAML~=6.0.1
PyYAML~=6.0.1
GitPython~=3.1.40
4 changes: 4 additions & 0 deletions valhalla/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from valhalla.main import start

if __name__ == '__main__':
start()
Empty file.
Empty file.
Empty file added valhalla/commit/__init__.py
Empty file.
File renamed without changes.
46 changes: 46 additions & 0 deletions valhalla/commit/commit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
from git import Repo

from valhalla.common.logger import info


class GitRepository:
def __init__(self):
self.repository = Repo.init(".")

def status(self):
info("----------------------")
info("Git status")

untracked = self.repository.untracked_files
for f in untracked:
info(f"{f} is untracked")

diffs = self.repository.index.diff(None)
for d in diffs:
info(f"{d.a_path} is modified")

info("----------------------")

def commit(self, msg: str, add=True):
self.status()

if add:
if self.repository.is_dirty():
untracked = self.repository.untracked_files
for f in untracked:
self.repository.index.add(f)
info(f"{f} added to stage")
else:
info(f"add={add}, skipping adding untracked files")

self.repository.index.commit(msg)
self.status()

def push(self):
origin = self.repository.remote('origin')
origin.push()


# if __name__ == '__main__':
# git_repo = GitRepository()
# git_repo.commit("testing commiting")
Empty file added valhalla/common/__init__.py
Empty file.
14 changes: 12 additions & 2 deletions valhalla/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from valhalla.before_commit import before_commit
from valhalla.commit import before
from valhalla.ci_provider.gitlab.get_version import get_version_number_to_release
from valhalla.commit.commit import GitRepository
from valhalla.common.get_config import get_config
from valhalla.common.logger import info
from valhalla.model.project import Project


Expand All @@ -9,7 +11,15 @@ def start():
version_to_release = get_version_number_to_release()
config = get_config("./valhalla.yml")
project = Project(config.project_name, version_to_release)
before_commit.execute(config.before_commit_commands)

if config.commit.enabled:
info("Commit enabled is True so scripts, commit, push will be performed")
before.execute(config.commit.before_commands)
git = GitRepository()
git.commit(f"Releasing version {project.version}")
git.push()
else:
info("Commit disabled(enabled: False), skipping scripts, commit, push")


if __name__ == '__main__':
Expand Down
Empty file added valhalla/model/__init__.py
Empty file.

0 comments on commit 662a6c8

Please sign in to comment.