-
-
Notifications
You must be signed in to change notification settings - Fork 237
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated sources automatically committed (#4226)
* updated sources modifications tested on alpha * SOURCEBRANCH ignore added to cspell * updated CHANGELOG * logging message on git success * fixed pylint possibly-used-before-assignment * Update UpdatedSourcesReporter.py --------- Co-authored-by: Nicolas Vuillamy <[email protected]>
- Loading branch information
1 parent
ba879fe
commit efacd1e
Showing
3 changed files
with
51 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,8 @@ | |
import logging | ||
import os | ||
import shutil | ||
import chalk as c | ||
import git | ||
|
||
from megalinter import Reporter, config, utils | ||
|
||
|
@@ -60,9 +62,54 @@ def produce_report(self): | |
if len(updated_files) > 0: | ||
logging.info( | ||
f"[Updated Sources Reporter] copied {str(len(updated_files))} fixed source files" | ||
f" in folder {updated_sources_dir}.\n" | ||
"Download it from artifacts then copy-paste it in your local repo to apply linters updates" | ||
f" in folder {updated_sources_dir}." | ||
) | ||
|
||
if not config.exists(self.master.request_id, "GITHUB_REPOSITORY"): | ||
apply_fixes = config.get(self.master.request_id, "APPLY_FIXES", "none") | ||
if apply_fixes.lower() != "none": | ||
remote_branch = "" | ||
SYSTEM_PULLREQUEST_SOURCEBRANCH = config.get( | ||
self.master.request_id, "SYSTEM_PULLREQUEST_SOURCEBRANCH", "" | ||
) | ||
if SYSTEM_PULLREQUEST_SOURCEBRANCH != "": | ||
remote_branch = SYSTEM_PULLREQUEST_SOURCEBRANCH | ||
BITBUCKET_BRANCH = config.get( | ||
self.master.request_id, "BITBUCKET_BRANCH", "" | ||
) | ||
if BITBUCKET_BRANCH != "": | ||
remote_branch = BITBUCKET_BRANCH | ||
if remote_branch == "": | ||
logging.error( | ||
c.red( | ||
"❌ [Updated Sources Reporter] Failed to retrieve git source branch" | ||
) | ||
) | ||
else: | ||
try: | ||
repo = git.Repo(os.path.realpath(self.master.github_workspace)) | ||
repo.config_writer().set_value("user", "name", "MegaLinter").release() | ||
repo.config_writer().set_value("user", "email", "[email protected]").release() | ||
repo.git.add(update=True) | ||
repo.git.commit('-m', '[MegaLinter] Apply linters fixes') | ||
repo.git.push('origin', f'HEAD:{remote_branch}') | ||
except git.GitCommandError as git_err: | ||
logging.error( | ||
c.red( | ||
"❌ [Updated Sources Reporter] Failed to git push auto fixes: " + str(git_err.stderr) | ||
) | ||
) | ||
logging.warning( | ||
c.yellow( | ||
"⚠️ [Updated Sources Reporter] Download fixed source files from artifacts " | ||
"then copy-paste into your repo to apply linters updates" | ||
) | ||
) | ||
else: | ||
logging.info( | ||
"[Updated Sources Reporter] Fixed source files have automatically " | ||
"been pushed to the source branch" | ||
) | ||
else: | ||
logging.info( | ||
"[Updated Sources Reporter] No source file has been formatted or fixed" | ||
|