Skip to content

Commit

Permalink
added pushing untracked and modified
Browse files Browse the repository at this point in the history
  • Loading branch information
marwin1991 committed Nov 23, 2023
1 parent 4d13670 commit 2d55082
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 6 deletions.
17 changes: 17 additions & 0 deletions .run/Python tests in valhalla.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Python tests in valhalla" type="tests" factoryName="Autodetect" nameIsGenerated="true">
<module name="valhalla" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
<option name="SDK_HOME" value="" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
<option name="IS_MODULE_SDK" value="true" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" />
<option name="_new_additionalArguments" value="&quot;discover -s test -t test -p \u0027*_test.py\u0027&quot;" />
<option name="_new_target" value="&quot;$PROJECT_DIR$&quot;" />
<option name="_new_targetType" value="&quot;PATH&quot;" />
<method v="2" />
</configuration>
</component>
13 changes: 11 additions & 2 deletions valhalla/commit/commit.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from git import Repo

from valhalla.common.logger import info
from valhalla.common.logger import info, warn


class GitRepository:
Expand Down Expand Up @@ -32,25 +32,34 @@ def status(self):

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

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

new_changes_in_stage = False

if add:
untracked = self.repository.untracked_files
for f in untracked:
self.repository.git.add(f)
info(f"Untracked file: {f} added to stage")
new_changes_in_stage = True
else:
info(f"add={add}, skipping adding untracked files")

modified = self.repository.index.diff(None)
for f in modified:
self.repository.git.add(f.a_path)
info(f"Modified file: {f.a_path} added to stage")
new_changes_in_stage = True

if not new_changes_in_stage:
warn("There is noting to commit!")
return False

commit = self.repository.index.commit(msg)
info(f"Created commit: {commit}")
self.status()
return True

def push(self, token):
info("Preparing to push")
Expand Down
12 changes: 8 additions & 4 deletions valhalla/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@ def start():
info("Commit enabled is True so scripts, commit, push will be performed")
before.execute(config.commit.before_commands)
git = GitRepository(config.commit.git_username, config.commit.git_email)
git.commit(f"Releasing version {project.version}")
token = get_token()
git.push(token)
info("Pushed successful!")
commit_success = git.commit(f"Releasing version {project.version}")

if commit_success:
info("Commit successful, preparing to push")
token = get_token()
git.push(token)
info("Pushed successful!")

else:
info("Commit disabled(enabled: False), skipping scripts, commit, push")

Expand Down

0 comments on commit 2d55082

Please sign in to comment.