diff --git a/playbooks/roles/gitea-git-repos/library/gitea_create_repos.py b/playbooks/roles/gitea-git-repos/library/gitea_create_repos.py index c846ab9887..7f0492eb6b 100755 --- a/playbooks/roles/gitea-git-repos/library/gitea_create_repos.py +++ b/playbooks/roles/gitea-git-repos/library/gitea_create_repos.py @@ -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__':