2025-08-20 14:32:52 +03:00

81 lines
2.2 KiB
Markdown

# Gitea Issue → Branch Action
**Create a Git branch automatically from a Gitea issue, then attach that branch back to the issue via the Gitea REST API.**
---
## What it does
1. **Reads issue data** from the workflow event.
2. **Maps issue labels → Git Flow prefix** (`feature`, `bugfix`, `hotfix`).
3. **Creates a branch** named `<prefix>/us-<ISSUE_NUMBER>` from `origin/develop` (configurable).
4. **Pushes the branch** to the remote repository.
5. **Updates the issue** so its “linked branch” points to the one it just created.
---
## Environment variables
Only the following environment variables need to be set manually:
| Variable name | Required | Example value | Purpose |
|---------------|-----------|------------------------------|------------------------------------------------|
| `GITEA_URL` | * | `https://gitea.example.com` | Base URL of the Gitea instance |
| `GITEA_TOKEN` | * | `xxxx…` | Personal access token with **repo** scope |
> **Label → prefix mapping**
| Label | Prefix |
|----------------|----------|
| `enhancement` | `feature`|
| `bug` | `hotfix` |
| `invalid` | `bugfix` |
| _anything else_| `feature`|
---
## Quick start (Gitea Actions)
Example workflow YAML—`act_runner` builds the Dockerfile automatically:
```yaml
- uses: gitea.ethumada.com/gitea/new-issue-branch@v1
env:
GITEA_URL: https://git.example.com
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
```
---
## Branch-naming rules
```
<prefix>/ticket-<ISSUE_NUMBER>
```
* `prefix` = **feature**, **bugfix**, or **hotfix** (based on label table above)
* Example: `feature/ticket-123`, `hotfix/ticket-7`
---
## Local development
```bash
# build and run the container locally
docker build -t gitea-issue-branch-action .
docker run --rm \
-e GITEA_URL=https://gitea.example.com \
-e GITEA_TOKEN=xxx \
gitea-issue-branch-action
```
Or use [`act`](https://github.com/nektos/act) to execute the full workflow.
---
## 📄 License
Distributed under the MIT License—see [`LICENSE`](./LICENSE) for details.