Skip to content

Commit d7f392b

Browse files
Testing: git push auto fixed files (#4176)
* git add commit push * git try if apply_fixes * check for GitHub and APPLY_FIXES * git error log format
1 parent 1d2680f commit d7f392b

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

megalinter/reporters/UpdatedSourcesReporter.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import logging
77
import os
88
import shutil
9+
import git
910

1011
from megalinter import Reporter, config, utils
1112

@@ -63,6 +64,19 @@ def produce_report(self):
6364
f" in folder {updated_sources_dir}.\n"
6465
"Download it from artifacts then copy-paste it in your local repo to apply linters updates"
6566
)
67+
68+
if not config.exists(self.master.request_id, "GITHUB_REPOSITORY"):
69+
apply_fixes = config.get_list(self.master.request_id, "APPLY_FIXES", "none")
70+
if apply_fixes.lower() != "none":
71+
try:
72+
repo = git.Repo(os.path.realpath(self.master.github_workspace))
73+
repo.git.add(update=True)
74+
repo.git.commit("megalinter auto fixes")
75+
repo.git.push
76+
except Exception as exp:
77+
logging.error(
78+
"[Updated Sources Reporter] Failed to git push auto fixes: " + str(exp.message)
79+
)
6680
else:
6781
logging.info(
6882
"[Updated Sources Reporter] No source file has been formatted or fixed"

0 commit comments

Comments
 (0)