Add some logging to repo creation

So that we can verify what was done, we should emit some things to
log and return them.

Change-Id: I9c48e94fe099002335113aed296bfc9a52d4c10e
This commit is contained in:
Monty Taylor 2019-07-11 10:40:34 -04:00
parent caebf387b4
commit f9358173a3

View File

@ -35,6 +35,13 @@ class Gitea(object):
self.always_update = always_update
self.projects = projects
self.orgs = { f['project'].split('/')[0] for f in self.projects }
self._log = []
def log(self, *args):
self._log.append(" ".join(args))
def get_log(self):
return "\n".join(self._log)
def request(self, method, endpoint, *args, **kwargs):
resp = requests.request(
@ -63,6 +70,7 @@ class Gitea(object):
self.post(
'/api/v1/admin/users/root/orgs',
json=dict(username=org))
self.log("Created org:", org)
def ensure_gitea_teams(self, org):
team_list = self.get('/api/v1/orgs/{org}/teams'.format(org=org)).json()
@ -73,6 +81,7 @@ class Gitea(object):
if 'gerrit' not in [f['username'] for f in org_owners.json()]:
self.put('/api/v1/teams/{owner_id}/members/gerrit'.format(
owner_id=owner_id))
self.log("Added gerrit to team:", org)
def get_org_repo_list(self, org):
return self.get('/api/v1/orgs/{org}/repos'.format(org=org)).json()
@ -91,6 +100,7 @@ class Gitea(object):
name=repo,
private=False,
readme='Default'))
self.log("Created repo:", project['project'])
if project.get('use-storyboard'):
external_tracker_url = SB_REPO.format(org=org, repo=repo)
tracker_url_format = SB_FORMAT
@ -117,10 +127,11 @@ class Gitea(object):
tracker_url_format=tracker_url_format,
tracker_issue_style='numeric',
))
self.log("Updated tracker url:", external_tracker_url)
for count in range(0, 5):
try:
return self.post(
self.post(
'/{org}/{repo}/settings/branches'.format(
org=org, repo=repo),
data=dict(
@ -128,6 +139,8 @@ class Gitea(object):
action='default_branch',
branch='master',
))
self.log("Set master branch:", project['project'])
return
except requests.exceptions.HTTPError as e:
time.sleep(3)
raise Exception("Could not update branch settings")
@ -170,7 +183,7 @@ def ansible_main():
except Exception as e:
module.fail_json(msg=str(e), changed=True)
module.exit_json(changed=True)
module.exit_json(changed=True, log=gitea.get_log())
if __name__ == '__main__':