mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
github_repo: support GitHub on premise installations (#3039)
* added possibility to manage on prem github * added changelog * fixed module tests * Update changelogs/fragments/3038-enhance_github_repo_api_url.yml Co-authored-by: Felix Fontein <felix@fontein.de> * Update plugins/modules/source_control/github/github_repo.py Co-authored-by: Felix Fontein <felix@fontein.de> Co-authored-by: Max Bidlingmaier <Max-Florian.Bidlingmaier@sap.com> Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
parent
11cdb1b661
commit
38e70ae0e4
3 changed files with 29 additions and 10 deletions
|
@ -0,0 +1,2 @@
|
|||
minor_changes:
|
||||
- github_repo - add new option ``api_url`` to allow working with on premises installations (https://github.com/ansible-collections/community.general/pull/3038).
|
|
@ -66,6 +66,12 @@ options:
|
|||
- When I(state) is C(present), the repository will be created in the current user profile.
|
||||
type: str
|
||||
required: false
|
||||
api_url:
|
||||
description:
|
||||
- URL to the GitHub API if not using github.com but you own instance.
|
||||
type: str
|
||||
default: 'https://api.github.com'
|
||||
version_added: "3.5.0"
|
||||
requirements:
|
||||
- PyGithub>=1.54
|
||||
notes:
|
||||
|
@ -119,11 +125,14 @@ except Exception:
|
|||
HAS_GITHUB_PACKAGE = False
|
||||
|
||||
|
||||
def authenticate(username=None, password=None, access_token=None):
|
||||
def authenticate(username=None, password=None, access_token=None, api_url=None):
|
||||
if not api_url:
|
||||
return None
|
||||
|
||||
if access_token:
|
||||
return Github(base_url="https://api.github.com", login_or_token=access_token)
|
||||
return Github(base_url=api_url, login_or_token=access_token)
|
||||
else:
|
||||
return Github(base_url="https://api.github.com", login_or_token=username, password=password)
|
||||
return Github(base_url=api_url, login_or_token=username, password=password)
|
||||
|
||||
|
||||
def create_repo(gh, name, organization=None, private=False, description='', check_mode=False):
|
||||
|
@ -185,7 +194,8 @@ def delete_repo(gh, name, organization=None, check_mode=False):
|
|||
|
||||
def run_module(params, check_mode=False):
|
||||
gh = authenticate(
|
||||
username=params['username'], password=params['password'], access_token=params['access_token'])
|
||||
username=params['username'], password=params['password'], access_token=params['access_token'],
|
||||
api_url=params['api_url'])
|
||||
if params['state'] == "absent":
|
||||
return delete_repo(
|
||||
gh=gh,
|
||||
|
@ -216,6 +226,7 @@ def main():
|
|||
organization=dict(type='str', required=False, default=None),
|
||||
private=dict(type='bool', required=False, default=False),
|
||||
description=dict(type='str', required=False, default=''),
|
||||
api_url=dict(type='str', required=False, default='https://api.github.com'),
|
||||
)
|
||||
module = AnsibleModule(
|
||||
argument_spec=module_args,
|
||||
|
|
|
@ -159,7 +159,8 @@ class TestGithubRepo(unittest.TestCase):
|
|||
"name": "myrepo",
|
||||
"description": "Just for fun",
|
||||
"private": False,
|
||||
"state": "present"
|
||||
"state": "present",
|
||||
"api_url": "https://api.github.com"
|
||||
})
|
||||
|
||||
self.assertEqual(result['changed'], True)
|
||||
|
@ -177,7 +178,8 @@ class TestGithubRepo(unittest.TestCase):
|
|||
"name": "myrepo",
|
||||
"description": "Just for fun",
|
||||
"private": True,
|
||||
"state": "present"
|
||||
"state": "present",
|
||||
"api_url": "https://api.github.com"
|
||||
})
|
||||
self.assertEqual(result['changed'], True)
|
||||
self.assertEqual(result['repo']['private'], True)
|
||||
|
@ -194,7 +196,8 @@ class TestGithubRepo(unittest.TestCase):
|
|||
"name": "myrepo",
|
||||
"description": "Just for fun",
|
||||
"private": True,
|
||||
"state": "present"
|
||||
"state": "present",
|
||||
"api_url": "https://api.github.com"
|
||||
})
|
||||
self.assertEqual(result['changed'], True)
|
||||
self.assertEqual(result['repo']['private'], True)
|
||||
|
@ -211,7 +214,8 @@ class TestGithubRepo(unittest.TestCase):
|
|||
"name": "myrepo",
|
||||
"description": "Just for fun",
|
||||
"private": False,
|
||||
"state": "absent"
|
||||
"state": "absent",
|
||||
"api_url": "https://api.github.com"
|
||||
})
|
||||
self.assertEqual(result['changed'], True)
|
||||
|
||||
|
@ -227,7 +231,8 @@ class TestGithubRepo(unittest.TestCase):
|
|||
"name": "myrepo",
|
||||
"description": "Just for fun",
|
||||
"private": False,
|
||||
"state": "absent"
|
||||
"state": "absent",
|
||||
"api_url": "https://api.github.com"
|
||||
})
|
||||
self.assertEqual(result['changed'], True)
|
||||
|
||||
|
@ -243,7 +248,8 @@ class TestGithubRepo(unittest.TestCase):
|
|||
"name": "myrepo",
|
||||
"description": "Just for fun",
|
||||
"private": True,
|
||||
"state": "absent"
|
||||
"state": "absent",
|
||||
"api_url": "https://api.github.com"
|
||||
})
|
||||
self.assertEqual(result['changed'], False)
|
||||
|
||||
|
|
Loading…
Reference in a new issue