Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manage before_exit() & clean git repo for Azure Pipelines #1232

Merged
merged 1 commit into from
Jan 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@
"columnsep",
"columnseprule",
"commandline",
"commmands",
"compat",
"compojure",
"cond",
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ Note: Can be used with `megalinter/megalinter@beta` in your GitHub Action mega-l
- standard
- stylelint

- Fixes
- Remove extraheader in git repo when using Azure Pipelines ([#1125](https://github.com/megalinter/megalinter/issues/1125))

- Linter versions upgrades
- [markdown-table-formatter](https://www.npmjs.com/package/markdown-table-formatter) from 1.2.0 to **1.3.0** on 2022-01-31
- [checkov](https://www.checkov.io/) from 2.0.775 to **2.0.777** on 2022-01-31
Expand Down
19 changes: 17 additions & 2 deletions megalinter/MegaLinter.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ def __init__(self, params=None):
self.file_names_regex = []
self.status = "success"
self.return_code = 0
self.has_git_extraheader = False
self.has_updated_sources = 0
self.flavor_suggestions = None
# Initialize plugins
Expand Down Expand Up @@ -169,10 +170,10 @@ def run(self):
# Generate reports
for reporter in self.reporters:
reporter.produce_report()
# Process commmands before closing MegaLinter
self.before_exit()
# Manage return code
self.check_results()
# Display upgrade recommendation if necessary
self.manage_upgrade_message()

# noinspection PyMethodMayBeStatic
def process_linters_serial(self, active_linters, _linters_do_fixes):
Expand Down Expand Up @@ -504,6 +505,7 @@ def list_files_git_diff(self):
"GIT_AUTHORIZATION_BEARER"
)
repo.config_writer().set_value("http", "extraheader", auth_bearer).release()
self.has_git_extraheader = True
# Fetch base branch content
default_branch = config.get("DEFAULT_BRANCH", "HEAD")
default_branch_remote = f"origin/{default_branch}"
Expand Down Expand Up @@ -648,6 +650,19 @@ def check_results(self):
sys.exit(self.return_code)
config.delete()

def before_exit(self):
# Clean git repository
self.manage_clean_git_repo()
# Display upgrade recommendation if necessary
self.manage_upgrade_message()

def manage_clean_git_repo(self):
# Add auth header if necessary
if self.has_git_extraheader is True:
repo = git.Repo(os.path.realpath(self.github_workspace))
repo.config_writer().set_value("http", "extraheader", "").release()

# Propose legacy versions users to upgrade
def manage_upgrade_message(self):
mega_linter_version = config.get("BUILD_VERSION", "No docker image")
if "insiders" in mega_linter_version or "v4" in mega_linter_version:
Expand Down