Added mode command.
This commit is contained in:
parent
6b04b192d6
commit
35593bd728
53
gitea_cli.py
53
gitea_cli.py
|
@ -32,6 +32,19 @@ class GiteaAPI:
|
|||
else:
|
||||
response.raise_for_status()
|
||||
|
||||
def update_repository_visibility(self, name, visibility):
|
||||
"""Update repository visibility."""
|
||||
endpoint = f"{self.base_url}/api/v1/repos/{name}"
|
||||
data = {
|
||||
"visibility": visibility
|
||||
}
|
||||
|
||||
response = self.session.patch(endpoint, json=data)
|
||||
if response.status_code == 200:
|
||||
return response.json()
|
||||
else:
|
||||
response.raise_for_status()
|
||||
|
||||
def get_gitea_config(url=None, token=None):
|
||||
"""Get Gitea configuration from environment or command line arguments."""
|
||||
config = {
|
||||
|
@ -100,8 +113,21 @@ def cli():
|
|||
- GITEA_TOKEN: Your Gitea API token
|
||||
|
||||
2. Command line arguments:
|
||||
--gitea-url and --gitea-token
|
||||
(These override environment variables if both are present)
|
||||
--gitea-url: Your Gitea server URL (overrides GITEA_URL)
|
||||
--gitea-token: Your Gitea API token (overrides GITEA_TOKEN)
|
||||
|
||||
Commands:
|
||||
create-repo: Create a new repository on Gitea
|
||||
Flags:
|
||||
--name: Repository name (required)
|
||||
--description: Repository description
|
||||
--private: Create repository as private
|
||||
--set-remote: Set git remote 'origin' to new repository
|
||||
mode: Toggle repository visibility between public and private
|
||||
Flags:
|
||||
--name: Repository name (required)
|
||||
--public: Set repository to public
|
||||
--private: Set repository to private
|
||||
"""
|
||||
pass
|
||||
|
||||
|
@ -154,5 +180,28 @@ def create_repo(name, description, private, set_remote, gitea_url, gitea_token):
|
|||
click.echo(f"Error creating repository: {str(e)}")
|
||||
sys.exit(1)
|
||||
|
||||
@cli.command()
|
||||
@click.option('--name', required=True, help='Name of the repository')
|
||||
@click.option('--public', is_flag=True, default=False, help='Set repository to public')
|
||||
@click.option('--private', is_flag=True, default=False, help='Set repository to private')
|
||||
def mode(name, public, private):
|
||||
"""Toggle repository visibility between public and private"""
|
||||
if public and private:
|
||||
click.echo("Error: Cannot specify both --public and --private")
|
||||
return
|
||||
|
||||
if not public and not private:
|
||||
click.echo("Error: Must specify either --public or --private")
|
||||
return
|
||||
|
||||
config = get_gitea_config()
|
||||
try:
|
||||
gitea = GiteaAPI(config['url'], config['token'])
|
||||
visibility = 'public' if public else 'private'
|
||||
gitea.update_repository_visibility(name, visibility)
|
||||
click.echo(f"Successfully set repository {name} to {visibility}")
|
||||
except Exception as e:
|
||||
click.echo(f"Error: {str(e)}")
|
||||
|
||||
if __name__ == '__main__':
|
||||
cli()
|
Loading…
Reference in New Issue