UNCLASSIFIED

Commit 1ccd857f authored by Joshua Eason's avatar Joshua Eason
Browse files

Adding project settings

parent ccbf8b96
......@@ -26,7 +26,7 @@ def __getProject(url, token, id):
return project
def __setDefaultBranch(url, token, id, branch):
def __setParameter(url, token, id, key, value):
url = url + "/api/v4/projects/" + str(id)
HEADER = {
......@@ -34,12 +34,12 @@ def __setDefaultBranch(url, token, id, branch):
}
PARAMS = {
'default_branch': branch,
key: value,
}
response = requests.put(url, params = PARAMS, headers = HEADER)
if response.status_code != 200:
logging.critical("Failed to set default branch: " + str(response.status_code) + " " + response.reason)
logging.critical("Failed to set " + key + ": " + str(response.status_code) + " " + response.reason)
##### Check methods
......@@ -48,31 +48,92 @@ def check(url, token, tid, pid):
tsettings = __getProject(url, token, str(tid))
psettings = __getProject(url, token, str(pid))
default_branch = checkDefaultBranch(tsettings, psettings)
# default_branch = checkParameter(tsettings, psettings, 'default_branch')
# ci_config_path = checkParameter(tsettings, psettings, 'ci_config_path')
# visibility = checkParameter(tsettings, psettings, 'visibility')
parameters = {
'allow_merge_on_skipped_pipeline': '',
'approvals_before_merge': '',
'auto_cancel_pending_pipelines': '',
'auto_devops_deploy_strategy': '',
'auto_devops_enabled': '',
'autoclose_referenced_issues': '',
'build_coverage_regex': '',
'build_git_strategy': '',
'build_timeout': '',
'builds_access_level': '',
'ci_config_path': '',
'ci_default_git_depth': '',
'ci_forward_deployment_enabled': '',
'container_expiration_policy_attributes': '',
'container_registry_enabled': '',
'default_branch': '',
'emails_disabled': '',
'external_authorization_classification_label': '',
'forking_access_level': '',
'issues_access_level': '',
'lfs_enabled': '',
'merge_method': '',
'merge_requests_access_level': '',
'merge_requests_enabled': '',
'mirror_overwrites_diverged_branches': '',
'mirror_trigger_builds': '',
'mirror': '',
'only_allow_merge_if_all_discussions_are_resolved': '',
'only_allow_merge_if_pipeline_succeeds': '',
'only_mirror_protected_branches': '',
'packages_enabled': '',
'pages_access_level': '',
'requirements_access_level': '',
'path': '',
'public_builds': '',
'remove_source_branch_after_merge': '',
'repository_access_level': '',
'repository_storage': '',
'request_access_enabled': '',
'resolve_outdated_diff_discussions': '',
'service_desk_enabled': '',
'shared_runners_enabled': '',
'show_default_award_emojis': '',
'snippets_access_level': '',
'snippets_enabled': '',
'suggestion_commit_message': '',
'tag_list': '',
'visibility': '',
'wiki_access_level': '',
'wiki_enabled': ''
}
if default_branch != '':
logging.warning("Default branch incorrect!")
for i in parameters.keys():
parameters[i] = checkParameter(tsettings, psettings, i)
if parameters[i] != '':
logging.warning(i + " incorrect!")
return {
'default_branch': default_branch
}
return parameters
def checkDefaultBranch(tsettings, psettings):
if tsettings['default_branch'] != psettings['default_branch']:
return tsettings['default_branch']
def checkParameter(tsettings, psettings, param):
if tsettings[param] != psettings[param]:
return tsettings[param]
else:
return ''
##### Fix methods
def fix(url, token, tid, pid):
fixes = check(url, token, tid, pid)
for i in fixes.keys():
if fixes[i] != '':
fixParameter(url, token, pid, i, fixes[i])
# if fixes['default_branch'] != '':
# fixParameter(url, token, pid, 'default_branch', fixes['default_branch'])
if fixes['default_branch'] != '':
fixDefaultBranch(url, token, pid, fixes['default_branch'])
# if fixes['ci_config_path'] != '':
# fixParameter(url, token, pid, 'ci_config_path', fixes['ci_config_path'])
def fixDefaultBranch(url, token, id, branch):
logging.debug("Setting default branch: " + branch)
__setDefaultBranch(url, token, id, branch)
\ No newline at end of file
def fixParameter(url, token, id, key, value):
logging.debug("Setting " + str(key) + ": " + str(value))
__setParameter(url, token, id, key, value)
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment