3.5 KiB
3.5 KiB
description, agent
| description | agent |
|---|---|
| Create a new Git repository on Gitea | build |
create-gitea-repo
Create a new Git repository on Gitea.
Features
- Create new repository under specified organization or user via Gitea API
- Support creating private or public repositories
- Automatically add remote repository address after successful creation
User Input Format
User can specify parameters in the following format:
<owner>/<repo> [private|public]
owner: Organization name or username (required)repo: Repository name (required)private|public: Visibility (optional, defaultprivate)
Examples:
ai/my-project- Create private repository my-project under ai organizationai/my-project public- Create public repository my-project under ai organizationvoson/test private- Create private repository test under voson user
Configuration
Use the following configuration when executing command:
| Config Item | Value |
|---|---|
| Gitea Server URL | https://git.digitevents.com/ |
| API Token | {env:GITEA_API_TOKEN} |
Steps
1. Parse User Input
Parse from user input:
owner: Organization name or usernamerepo: Repository namevisibility:private(default) orpublic
Input validation:
- If user didn't provide
owner/repoformat input, prompt user for correct format and terminate execution - Repository name can only contain letters, numbers, underscores, hyphens and dots
2. Call Gitea API to Create Repository
Use curl to call Gitea API:
curl -s -X POST "https://git.digitevents.com/api/v1/orgs/<owner>/repos" \
-H "Authorization: token $GITEA_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "<repo>",
"private": <true|false>
}'
Note: If owner is personal user instead of organization, API path should be
/api/v1/user/repos, but usually try organization API first.
3. Handle Response
Success (HTTP 201):
- Extract repository info from response:
html_url: Repository web URLclone_url: HTTPS clone URLssh_url: SSH clone URL
- Output creation success message
Failure:
- If 404 error, owner may not exist or no permission
- If 409 error, repository already exists
- Output error message and terminate
4. Ask Whether to Add Remote Repository
Ask user whether to add the newly created repository as current project's remote repository.
If user confirms:
-
Check if current directory is a Git repository:
git rev-parse --is-inside-work-tree -
If not a Git repository, ask whether to initialize:
git init -
Check if origin remote already exists:
git remote get-url origin -
Add or update remote repository:
- If no origin:
git remote add origin <clone_url> - If origin exists: Ask whether to overwrite, after confirmation execute
git remote set-url origin <clone_url>
- If no origin:
5. Output Result Summary
Output creation result summary table:
Repository created successfully!
| Property | Value |
|----------|-------|
| Repository Name | owner/repo |
| Web URL | https://git.digitevents.com/owner/repo |
| Clone URL (HTTPS) | https://git.digitevents.com/owner/repo.git |
| Clone URL (SSH) | git@git.digitevents.com:owner/repo.git |
| Private | Yes/No |
Notes
- Permission check: Ensure Token has permission to create repository
- Organization vs User: Creating organization repository and user repository use different API endpoints
- Repository naming: Follow Gitea naming rules, avoid special characters