SHA256
docs: add an agent skill for gt (#29)
Agents get a skill in skills/gt that teaches them to drive gt, from reading CI failures to opening and reviewing pull requests. It replaces gitea-tea-skill, and a test keeps its commands, flags and JSON fields in sync with gt. Closes #17 Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: GyeongHo Kim <[email protected]> Co-authored-by: bircni <[email protected]> Reviewed-on: https://gitea.com/gitea/cli/pulls/29 Reviewed-by: Lunny Xiao <[email protected]> Reviewed-by: bircni <[email protected]> Co-authored-by: GyeongHo Kim <[email protected]>
This commit is contained in:
committed by
bircni
co-authored by
bircni
parent
1d138a626d
commit
a45db01ae6
@@ -0,0 +1 @@
|
||||
skills/** text eol=lf
|
||||
@@ -116,6 +116,24 @@ man (gt man | psub)
|
||||
gt man --output-file ./gt.man
|
||||
```
|
||||
|
||||
### Agent skill
|
||||
|
||||
An [agent skill](https://agentskills.io) teaches coding agents to drive `gt`: checking CI and
|
||||
reading the logs of failed jobs, turning an issue into a pull request, commenting and reviewing.
|
||||
It replaces [gitea-tea-skill](https://gitea.com/gitea/gitea-tea-skill). Install it with
|
||||
[skills](https://github.com/vercel-labs/skills):
|
||||
|
||||
```shell
|
||||
# for the current project
|
||||
npx skills add https://gitea.com/gitea/cli.git --skill gt
|
||||
|
||||
# for all your projects
|
||||
npx skills add https://gitea.com/gitea/cli.git --skill gt -g
|
||||
|
||||
# after upgrading gt
|
||||
npx skills update gt
|
||||
```
|
||||
|
||||
## Compilation
|
||||
|
||||
Make sure you have a current Go version installed (1.27 or newer).
|
||||
|
||||
@@ -0,0 +1,312 @@
|
||||
// Copyright 2026 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package app
|
||||
|
||||
import (
|
||||
"cmp"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"slices"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/pflag"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
// TestSkillMatchesCommands checks the agent skill in skills/gt: frontmatter as the Agent Skills
|
||||
// specification requires, links that resolve, and only gt commands and flags that exist.
|
||||
func TestSkillMatchesCommands(t *testing.T) {
|
||||
dir := filepath.Join("..", "..", "skills", "gt")
|
||||
data, err := os.ReadFile(filepath.Join(dir, "SKILL.md"))
|
||||
require.NoError(t, err)
|
||||
text := strings.ReplaceAll(string(data), "\r\n", "\n") // a Windows checkout may convert line endings
|
||||
front, body, ok := strings.Cut(strings.TrimPrefix(text, "---\n"), "\n---\n")
|
||||
require.True(t, ok && strings.HasPrefix(text, "---\n"), "SKILL.md needs YAML frontmatter")
|
||||
var meta struct{ Name, Description string }
|
||||
require.NoError(t, yaml.Unmarshal([]byte(front), &meta))
|
||||
assert.Regexp(t, `^[a-z0-9]+(-[a-z0-9]+)*$`, meta.Name)
|
||||
assert.Equal(t, filepath.Base(dir), meta.Name)
|
||||
assert.NotEmpty(t, meta.Description)
|
||||
assert.LessOrEqual(t, len(meta.Description), 1024)
|
||||
|
||||
files := map[string]string{"SKILL.md": body}
|
||||
references, err := filepath.Glob(filepath.Join(dir, "references", "*.md"))
|
||||
require.NoError(t, err)
|
||||
for _, path := range references {
|
||||
data, err := os.ReadFile(path)
|
||||
require.NoError(t, err)
|
||||
name := "references/" + filepath.Base(path)
|
||||
files[name] = strings.ReplaceAll(string(data), "\r\n", "\n")
|
||||
assert.Contains(t, body, "]("+name+")", "SKILL.md needs to link %s", name)
|
||||
}
|
||||
|
||||
deps, _, _ := testDeps(t)
|
||||
root := NewRoot(deps)
|
||||
checked := 0
|
||||
for name, text := range files {
|
||||
for _, match := range markdownLink.FindAllStringSubmatch(text, -1) {
|
||||
path, anchor := match[1], match[2]
|
||||
if strings.Contains(path, "://") {
|
||||
continue
|
||||
}
|
||||
target := name
|
||||
if path != "" {
|
||||
target = filepath.ToSlash(filepath.Join(filepath.Dir(name), path))
|
||||
_, err := os.Stat(filepath.Join(dir, target))
|
||||
assert.NoError(t, err, "%s links to %s", name, path)
|
||||
}
|
||||
if anchor != "" {
|
||||
assert.Contains(t, headingAnchors(files[target]), anchor, "%s links to %s#%s", name, path, anchor)
|
||||
}
|
||||
}
|
||||
for _, words := range gtInvocations(text) {
|
||||
checked++
|
||||
if err := checkInvocation(root, words); err != nil {
|
||||
t.Errorf("%s: gt %s: %v", name, strings.Join(words, " "), err)
|
||||
}
|
||||
}
|
||||
}
|
||||
assert.Positive(t, checked, "the skill's gt commands were not found")
|
||||
}
|
||||
|
||||
var (
|
||||
markdownLink = regexp.MustCompile(`\]\(([^)#\s]*)(?:#([^)\s]*))?\)`)
|
||||
inlineCode = regexp.MustCompile("`([^`]+)`")
|
||||
heredoc = regexp.MustCompile(`<<-?\s*['"]?(\w+)['"]?`)
|
||||
yamlRun = regexp.MustCompile(`^(\s*)(?:- )?run:\s*(.*)$`)
|
||||
notInAnchor = regexp.MustCompile(`[^\p{L}\p{N} _-]`)
|
||||
placeholder = regexp.MustCompile(`^[A-Z][A-Z0-9_]*$`)
|
||||
commandWord = regexp.MustCompile(`^[a-z]+(-[a-z]+)*$`) // a name, as opposed to a number, URL or path
|
||||
)
|
||||
|
||||
// headingAnchors returns the anchors that Gitea and GitHub give the headings of a Markdown text.
|
||||
func headingAnchors(text string) []string {
|
||||
var anchors []string
|
||||
fenced := false
|
||||
for line := range strings.Lines(text) {
|
||||
if strings.HasPrefix(strings.TrimSpace(line), "```") {
|
||||
fenced = !fenced
|
||||
}
|
||||
if heading := strings.TrimLeft(line, "#"); !fenced && len(heading) < len(line) && strings.HasPrefix(heading, " ") {
|
||||
anchor := notInAnchor.ReplaceAllString(strings.ToLower(strings.TrimSpace(heading)), "")
|
||||
anchors = append(anchors, strings.ReplaceAll(anchor, " ", "-"))
|
||||
}
|
||||
}
|
||||
return anchors
|
||||
}
|
||||
|
||||
// gtInvocations returns the arguments of each gt command in the inline code, the shell code
|
||||
// blocks and the run steps of YAML workflows in a Markdown text, skipping heredoc bodies.
|
||||
func gtInvocations(text string) [][]string {
|
||||
var invocations [][]string
|
||||
fenced, shell, workflow := false, false, false
|
||||
var delimiter, runIndent string
|
||||
for line := range strings.Lines(text) {
|
||||
if delimiter != "" {
|
||||
if strings.TrimSpace(line) == delimiter {
|
||||
delimiter = ""
|
||||
}
|
||||
continue
|
||||
}
|
||||
if lang, ok := strings.CutPrefix(strings.TrimSpace(line), "```"); ok {
|
||||
fenced, shell = !fenced, slices.Contains([]string{"", "sh", "bash", "shell"}, lang)
|
||||
workflow, runIndent = fenced && lang == "yaml", ""
|
||||
continue
|
||||
}
|
||||
if match := heredoc.FindStringSubmatch(line); fenced && shell && match != nil {
|
||||
delimiter = match[1]
|
||||
}
|
||||
var snippets []string
|
||||
switch {
|
||||
case !fenced:
|
||||
for _, match := range inlineCode.FindAllStringSubmatch(line, -1) {
|
||||
snippets = append(snippets, match[1])
|
||||
}
|
||||
case shell:
|
||||
snippets = []string{line}
|
||||
case workflow:
|
||||
indent := line[:len(line)-len(strings.TrimLeft(line, " "))]
|
||||
if runIndent != "" && len(indent) > len(runIndent) {
|
||||
snippets = []string{line}
|
||||
} else if match := yamlRun.FindStringSubmatch(strings.TrimRight(line, "\n")); match != nil {
|
||||
runIndent = ""
|
||||
if script := strings.TrimSpace(match[2]); script == "|" || script == ">" {
|
||||
runIndent = match[1] + " "
|
||||
} else {
|
||||
snippets = []string{script}
|
||||
}
|
||||
} else {
|
||||
runIndent = ""
|
||||
}
|
||||
}
|
||||
for _, snippet := range snippets {
|
||||
for _, words := range shellCommands(snippet) {
|
||||
if words[0] == "gt" && len(words) > 1 {
|
||||
invocations = append(invocations, words[1:])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return invocations
|
||||
}
|
||||
|
||||
// shellCommands splits a line of shell into the words of its simple commands, which pipes,
|
||||
// lists, redirections, subshells and comments end.
|
||||
func shellCommands(line string) [][]string {
|
||||
var commands [][]string
|
||||
var words []string
|
||||
var word strings.Builder
|
||||
var quote rune
|
||||
inWord := false
|
||||
endWord := func() {
|
||||
if inWord {
|
||||
words, inWord = append(words, word.String()), false
|
||||
word.Reset()
|
||||
}
|
||||
}
|
||||
endCommand := func() {
|
||||
endWord()
|
||||
if len(words) > 0 {
|
||||
commands, words = append(commands, words), nil
|
||||
}
|
||||
}
|
||||
for _, r := range line {
|
||||
switch {
|
||||
case quote != 0 && r == quote:
|
||||
quote = 0
|
||||
case quote != 0:
|
||||
word.WriteRune(r)
|
||||
case r == '\'' || r == '"':
|
||||
quote, inWord = r, true
|
||||
case r == ' ' || r == '\t' || r == '\n':
|
||||
endWord()
|
||||
case r == '#' && !inWord:
|
||||
endCommand()
|
||||
return commands
|
||||
case strings.ContainsRune("|&;<>()", r):
|
||||
endCommand()
|
||||
default:
|
||||
word.WriteRune(r)
|
||||
inWord = true
|
||||
}
|
||||
}
|
||||
endCommand()
|
||||
return commands
|
||||
}
|
||||
|
||||
// checkInvocation resolves the command that words name below root and checks its flags, the
|
||||
// values of enum flags, the fields that --json selects, and the topics that gt help names.
|
||||
func checkInvocation(root *cobra.Command, words []string) error {
|
||||
cmd, rest := root, words
|
||||
for len(rest) > 0 && !strings.HasPrefix(rest[0], "-") {
|
||||
child := subcommand(cmd, rest[0])
|
||||
if child == nil {
|
||||
break
|
||||
}
|
||||
cmd, rest = child, rest[1:]
|
||||
}
|
||||
if cmd.Name() == "help" && cmd.Parent() == root && len(rest) > 0 {
|
||||
if _, extra, err := root.Find(rest); err != nil || len(extra) > 0 {
|
||||
return fmt.Errorf("gt help has no topic %q", strings.Join(rest, " "))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
cmd.InitDefaultHelpFlag() // cobra adds --help and --version only when it executes
|
||||
cmd.InitDefaultVersionFlag()
|
||||
lookup := func(name string, short bool) *pflag.Flag {
|
||||
if short {
|
||||
return cmp.Or(cmd.Flags().ShorthandLookup(name), cmd.InheritedFlags().ShorthandLookup(name))
|
||||
}
|
||||
return cmp.Or(cmd.Flags().Lookup(name), cmd.InheritedFlags().Lookup(name))
|
||||
}
|
||||
var pending *pflag.Flag // a flag whose value is the next word
|
||||
for _, word := range rest {
|
||||
if pending != nil {
|
||||
if err := checkFlagValue(cmd, pending, word); err != nil {
|
||||
return err
|
||||
}
|
||||
pending = nil
|
||||
continue
|
||||
}
|
||||
switch {
|
||||
case word == "-" || !strings.HasPrefix(word, "-"):
|
||||
if cmd == root || cmd.Annotations["gt.group"] != "" || (cmd.HasSubCommands() && commandWord.MatchString(word)) {
|
||||
return fmt.Errorf("%s has no command %q", cmd.CommandPath(), word)
|
||||
}
|
||||
case strings.HasPrefix(word, "--"):
|
||||
name, value, hasValue := strings.Cut(word[2:], "=")
|
||||
flag := lookup(name, false)
|
||||
if flag == nil {
|
||||
return fmt.Errorf("%s has no flag --%s", cmd.CommandPath(), name)
|
||||
}
|
||||
if hasValue {
|
||||
if err := checkFlagValue(cmd, flag, value); err != nil {
|
||||
return err
|
||||
}
|
||||
} else if flag.NoOptDefVal == "" {
|
||||
pending = flag
|
||||
}
|
||||
case len(word) == 2:
|
||||
flag := lookup(word[1:], true)
|
||||
if flag == nil {
|
||||
return fmt.Errorf("%s has no flag %s", cmd.CommandPath(), word)
|
||||
}
|
||||
if flag.NoOptDefVal == "" {
|
||||
pending = flag
|
||||
}
|
||||
default:
|
||||
return fmt.Errorf("write %s as separate short flags or a long flag", word)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// checkFlagValue checks the fields that --json selects and the values of enum flags; values
|
||||
// that the shell expands and placeholders such as OWNER are not known.
|
||||
func checkFlagValue(cmd *cobra.Command, flag *pflag.Flag, value string) error {
|
||||
if strings.Contains(value, "$") || (placeholder.MatchString(value) && flag.Annotations[enumAnnotation] == nil) {
|
||||
return nil
|
||||
}
|
||||
if flag.Name == "json" {
|
||||
return checkFields(cmd, value)
|
||||
}
|
||||
allowed := flag.Annotations[enumAnnotation]
|
||||
if allowed == nil {
|
||||
return nil
|
||||
}
|
||||
values := []string{value}
|
||||
if _, ok := flag.Value.(pflag.SliceValue); ok {
|
||||
values = strings.Split(value, ",")
|
||||
}
|
||||
for _, value := range values {
|
||||
if !slices.ContainsFunc(allowed, func(v string) bool { return strings.EqualFold(v, value) }) {
|
||||
return fmt.Errorf("%s --%s has no value %q", cmd.CommandPath(), flag.Name, value)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func checkFields(cmd *cobra.Command, fields string) error {
|
||||
for field := range strings.SplitSeq(fields, ",") {
|
||||
if !slices.Contains(commandOutputFields(cmd), field) {
|
||||
return fmt.Errorf("%s has no JSON field %q", cmd.CommandPath(), field)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func subcommand(cmd *cobra.Command, name string) *cobra.Command {
|
||||
for _, child := range cmd.Commands() {
|
||||
if child.Name() == name || child.HasAlias(name) {
|
||||
return child
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,171 @@
|
||||
---
|
||||
name: gt
|
||||
description: >-
|
||||
Drives Gitea (gitea.com or self-hosted) through gt, the official Gitea CLI: checks whether a
|
||||
pull request's CI passed and reads the logs of the jobs that failed, reruns Actions jobs,
|
||||
reads an issue and opens a pull request for it, comments on issues and pull requests,
|
||||
reviews with inline comments, merges, searches issues and pull requests, manages releases
|
||||
and wiki pages, dispatches workflows, scripts gt in CI with GITEA_TOKEN, and makes raw Gitea
|
||||
API calls with gt api. Use for any Gitea task, or when the user mentions Gitea Actions,
|
||||
.gitea/workflows, or the older tea CLI.
|
||||
license: MIT
|
||||
---
|
||||
|
||||
# gt: the Gitea CLI for agents
|
||||
|
||||
`gt` drives a Gitea instance from the shell. Its commands follow `gh`, but flags,
|
||||
JSON fields and defaults differ: check a command's `--help` (it lists `JSON FIELDS`)
|
||||
instead of assuming `gh` behaviour.
|
||||
|
||||
## Contents
|
||||
|
||||
- [Rules for agents](#rules-for-agents)
|
||||
- [Quick start](#quick-start): CI failures, issue to pull request, comments and reviews
|
||||
- [Task reference](#task-reference)
|
||||
- [Authentication and targeting](#authentication-and-targeting)
|
||||
- [Exit codes](#exit-codes)
|
||||
- [Validation checklist](#validation-checklist)
|
||||
- [When not to use](#when-not-to-use)
|
||||
|
||||
## Rules for agents
|
||||
|
||||
- Pass `--no-input` on every command so gt never waits for a prompt or opens an editor.
|
||||
- Read with `--json` and filter with `--jq`; the text output is for people and may change.
|
||||
`--jq` runs inside gt, so `jq` need not be installed, and strings print without quotes.
|
||||
- An unknown `--json` field fails and names the available ones; `gt help formatting`
|
||||
explains fields that cost extra requests.
|
||||
- Without a terminal, confirmations fail with exit code 2. Pass `--yes` only after the user
|
||||
agreed to that action: deletes, merges, branch cleanup, pushing a new branch from
|
||||
`gt pr create`. Closing an issue or pull request asks no confirmation, so ask the user first.
|
||||
- Pass multi-line bodies on stdin with `-F -` (`--body-file -`) and a quoted heredoc rather
|
||||
than `\n` inside `--body`.
|
||||
- Lists stop at `-L 30` by default; raise `-L` (up to 1000) or page with `--page` before
|
||||
concluding something is missing.
|
||||
- Pull request commands without a number act on the current branch's pull request.
|
||||
- Unlike `gh`, the `comments` JSON field of issues and pull requests is a count. Read the
|
||||
comment text with `gt issue comment list` or `gt pr comment list`.
|
||||
|
||||
## Quick start
|
||||
|
||||
### Did CI pass, and why did it fail?
|
||||
|
||||
```sh
|
||||
gt pr checks 12 --no-input # exit 0 passed, 1 failed, 8 still pending
|
||||
gt pr checks 12 --no-input --json name,state,url --jq '.[] | select(.state != "success" and .state != "skipped" and .state != "pending")'
|
||||
gt run logs https://gitea.example.com/OWNER/REPO/actions/runs/34/jobs/71 --no-input
|
||||
```
|
||||
|
||||
An Actions check's `url` is its job URL, and `gt run logs` accepts that URL to print just
|
||||
that job. From a run ID instead, print the logs of every failed job:
|
||||
|
||||
```sh
|
||||
gt run list --branch feature/login --status failure -L 5 --no-input --json id,workflow,title,conclusion
|
||||
gt run view 34 --no-input --json jobs --jq '.jobs[] | {name, conclusion}'
|
||||
gt run logs 34 --failed --no-input
|
||||
```
|
||||
|
||||
Wait for checks instead of polling: `gt pr checks 12 --watch --no-input`, or
|
||||
`gt run watch 34 --no-input`. To retry a flaky job without a new commit,
|
||||
`gt run rerun 34 --failed --no-input`.
|
||||
More in [monitoring.md](references/monitoring.md).
|
||||
|
||||
### From an issue to a pull request
|
||||
|
||||
```sh
|
||||
gt issue view 17 --no-input --json number,title,body,labels,state
|
||||
gt issue comment list 17 -L 100 --no-input --json author,body,created_at
|
||||
git switch -c fix/issue-17
|
||||
# edit, test and commit
|
||||
gt pr create --no-input --yes --title "fix: describe the change" --body-file - <<'EOF'
|
||||
Explain what changed and why.
|
||||
|
||||
Closes #17
|
||||
EOF
|
||||
gt pr checks --watch --no-input
|
||||
```
|
||||
|
||||
`gt pr create` pushes a branch that is not on the remote yet, after a confirmation that
|
||||
`--yes` gives; ask the user before pushing. Details, forks and AGit in
|
||||
[resources.md](references/resources.md).
|
||||
|
||||
### Comment and review
|
||||
|
||||
```sh
|
||||
gt issue comment 17 --no-input --body-file - <<'EOF'
|
||||
Reproduced on main; the fix is in #18.
|
||||
EOF
|
||||
gt pr comment 18 --edit-last --no-input --body "Updated after review."
|
||||
gt pr review 18 --approve --no-input --body "Looks good."
|
||||
gt pr review 18 --request-changes --no-input --comments-file inline.json --body "See the inline comments."
|
||||
```
|
||||
|
||||
`inline.json` is an array of `{"path", "body", "new_position"}` (or `old_position`) on a line
|
||||
of the diff; gt refuses lines outside the diff. See [resources.md](references/resources.md).
|
||||
|
||||
## Task reference
|
||||
|
||||
| Task | Command | Reference |
|
||||
| --- | --- | --- |
|
||||
| Checks of a pull request | `gt pr checks 12` | [monitoring.md](references/monitoring.md) |
|
||||
| Wait for checks | `gt pr checks 12 --watch` | [monitoring.md](references/monitoring.md) |
|
||||
| Logs of failed jobs | `gt run logs 34 --failed` | [monitoring.md](references/monitoring.md) |
|
||||
| Follow a running job | `gt run logs 34 --job build --follow` | [monitoring.md](references/monitoring.md) |
|
||||
| Rerun failed jobs | `gt run rerun 34 --failed` | [monitoring.md](references/monitoring.md) |
|
||||
| Download artifacts | `gt run download 34 --name build` | [monitoring.md](references/monitoring.md) |
|
||||
| Read an issue with comments | `gt issue view 17 --comments` | [resources.md](references/resources.md) |
|
||||
| Open an issue | `gt issue create --title T --body-file -` | [resources.md](references/resources.md) |
|
||||
| Close or reopen an issue | `gt issue close 17 --comment C` | [resources.md](references/resources.md) |
|
||||
| Open a pull request | `gt pr create --title T --body-file -` | [resources.md](references/resources.md) |
|
||||
| Read a pull request's diff | `gt pr diff 18` | [resources.md](references/resources.md) |
|
||||
| Comment | `gt pr comment 18 --body-file -` | [resources.md](references/resources.md) |
|
||||
| Review with inline comments | `gt pr review 18 --comment --comments-file inline.json` | [resources.md](references/resources.md) |
|
||||
| Reply to an inline comment | `gt pr review reply 18 1234 --body-file -` | [resources.md](references/resources.md) |
|
||||
| Merge | `gt pr merge 18 --squash --delete-branch` | [resources.md](references/resources.md) |
|
||||
| Edit or delete a wiki page | `gt wiki edit Home --body-file -` | [resources.md](references/resources.md) |
|
||||
| View or change a repository | `gt repo view --json full_name` | [resources.md](references/resources.md) |
|
||||
| Find issues or pull requests | `gt search issue crash --owner OWNER` | [search.md](references/search.md) |
|
||||
| My open work | `gt status` | [search.md](references/search.md) |
|
||||
| Run gt in CI or a script | `GITEA_TOKEN` and `GITEA_CLI_HOST` | [automation.md](references/automation.md) |
|
||||
| Dispatch a workflow | `gt workflow run ci.yml --ref main` | [automation.md](references/automation.md) |
|
||||
| Anything without a command | `gt api 'repos/{owner}/{repo}/...'` | [api.md](references/api.md) |
|
||||
| Write a Gitea Actions workflow | `.gitea/workflows/*.yaml` | [workflow-authoring.md](references/workflow-authoring.md) |
|
||||
|
||||
## Authentication and targeting
|
||||
|
||||
- `gt auth status --no-input --json` reports each account; read `credential_available` and
|
||||
`verified` (add `--verify` to check against the server). With `--json` it exits 0 even when
|
||||
something is wrong; without it, missing or rejected credentials exit 4.
|
||||
- In CI, set `GITEA_TOKEN` with `GITEA_CLI_HOST` (or `GITEA_INSTANCE_URL`); environment
|
||||
credentials are never saved. Logging in interactively (`gt auth login`) is for the user to
|
||||
run, not the agent.
|
||||
- gt infers the repository from Git remotes and prefers `upstream` over `origin`, so a fork
|
||||
checkout targets the parent repository. Pass `-R OWNER/REPO` when that is not what you want.
|
||||
- `gt help environment` lists the global flags and the selection order of repository and
|
||||
instance.
|
||||
|
||||
## Exit codes
|
||||
|
||||
| Code | Meaning |
|
||||
| --- | --- |
|
||||
| 0 | Success, including an empty list |
|
||||
| 1 | The command failed, or `gt pr checks` found a failed check |
|
||||
| 2 | Usage error, or a confirmation that needs `--yes` |
|
||||
| 3 | Canceled: declined confirmation or timeout |
|
||||
| 4 | Authentication missing or rejected |
|
||||
| 8 | `gt pr checks`: checks still pending |
|
||||
|
||||
`gt help exit-codes` has the full list. Branch on the code instead of parsing messages.
|
||||
|
||||
## Validation checklist
|
||||
|
||||
1. `gt --version` works and `gt auth status --no-input --json` shows a credential.
|
||||
2. `gt repo view --no-input --json full_name` names the intended repository.
|
||||
3. Reads use `--json`; every write was approved by the user.
|
||||
4. After `gt pr create`, `gt pr view --no-input --json url` gives the link to report.
|
||||
|
||||
## When not to use
|
||||
|
||||
- Local Git work (commits, rebases, branches) needs `git`, not gt.
|
||||
- GitHub, GitLab or other forges: gt only talks to Gitea instances.
|
||||
- Administering the Gitea server itself (`app.ini`, runners) is outside gt, except the API
|
||||
that `gt admin` and `gt api` expose.
|
||||
@@ -0,0 +1,50 @@
|
||||
# gt api: the fallback
|
||||
|
||||
Use a typed command when one exists; it validates input and maps fields. Reach for `gt api`
|
||||
when no command covers the request. It authenticates like every other command and sends
|
||||
requests to `/api/v1` of the selected instance.
|
||||
|
||||
```sh
|
||||
gt api user --jq .login
|
||||
gt api 'repos/{owner}/{repo}' --jq .default_branch
|
||||
gt api 'repos/{owner}/{repo}/issues' -f title="Crash on start" -F labels='[3]'
|
||||
gt api -X PATCH 'repos/{owner}/{repo}/issues/17' -f state=closed
|
||||
gt api 'repos/{owner}/{repo}/issues/17/reactions' -f content=+1
|
||||
```
|
||||
|
||||
- `{owner}` and `{repo}` come from the current repository or `-R`, `{branch}` from the
|
||||
checked-out branch. Write them literally when the target must not depend on the directory.
|
||||
- GET is the default, POST once fields or `--input` supply a body; `-X` picks another method.
|
||||
- `-f key=value` sends a string, `-F key=value` a typed value (`true`, numbers, JSON arrays and
|
||||
objects), and `-F key=@file` or `@-` reads a file or stdin. For GET, fields become query
|
||||
parameters.
|
||||
- `--input body.json` (or `-`) sends a prepared JSON body.
|
||||
- `--paginate` follows the pages of a list and prints each page on its own line; add `--jq`
|
||||
to flatten (`--jq '.[]'`). `--max-pages` limits it.
|
||||
- A response outside 2xx prints its body and fails; read the message before retrying.
|
||||
- `--include` prints the status and headers to stderr, `--silent` drops the body.
|
||||
|
||||
## Useful endpoints without a dedicated command
|
||||
|
||||
Gitea's API reference is at `/api/swagger` on the instance.
|
||||
|
||||
```sh
|
||||
# A file of the default branch, or of a ref
|
||||
gt api 'repos/{owner}/{repo}/raw/README.md'
|
||||
gt api 'repos/{owner}/{repo}/contents/go.mod?ref=main' --jq .content
|
||||
# Files changed by a pull request, with additions and deletions
|
||||
gt api 'repos/{owner}/{repo}/pulls/18/files' --paginate --jq '.[] | "\(.filename)\t\(.additions)\t\(.deletions)"'
|
||||
# Combined commit status of a branch, including external CI
|
||||
gt api 'repos/{owner}/{repo}/commits/{branch}/status' --jq '.state'
|
||||
# Logs of one Actions job by ID
|
||||
gt api 'repos/{owner}/{repo}/actions/jobs/71/logs'
|
||||
```
|
||||
|
||||
`contents` returns the file base64-encoded in `content`; `raw` returns it as is.
|
||||
|
||||
## Safety
|
||||
|
||||
- Writes through `gt api` skip gt's confirmations and checks. Show the user the request and
|
||||
get approval before any POST, PATCH, PUT or DELETE.
|
||||
- `--sudo USER` acts as another user and needs an administrator token; do not use it unless
|
||||
the user asks.
|
||||
@@ -0,0 +1,84 @@
|
||||
# Scripts and CI
|
||||
|
||||
## Non-interactive defaults
|
||||
|
||||
- `--no-input` disables prompts, the editor and the browser. Without a terminal gt already
|
||||
does not prompt, but `--no-input` makes the intent explicit and fails fast.
|
||||
- A confirmation that cannot be asked fails with exit code 2 and
|
||||
`confirmation required…; rerun with --yes`. Add `--yes` only for actions that were approved.
|
||||
- `--json` and `--jq` give stable output; text output may change between releases.
|
||||
- Branch on exit codes ([SKILL.md](../SKILL.md#exit-codes)), not on messages.
|
||||
|
||||
## Credentials without a login
|
||||
|
||||
```sh
|
||||
export GITEA_CLI_HOST=https://gitea.example.org # or GITEA_INSTANCE_URL
|
||||
export GITEA_TOKEN=... # from the CI secret store
|
||||
export GITEA_CLI_REPO=OWNER/REPO # optional, like --repo
|
||||
gt auth status --no-input --json host,user,method,credential_available
|
||||
```
|
||||
|
||||
- Environment credentials are never written to `config.yml` or `hosts.yml`. Never put a token
|
||||
in a file, a command line that gets logged, or a comment body.
|
||||
- `GITEA_INSTANCE_INSECURE=true` skips TLS verification for that token's instance; use it
|
||||
only for test instances the user names.
|
||||
- `gt help environment` lists every variable and the order in which gt picks the instance
|
||||
and repository.
|
||||
|
||||
## In a Gitea Actions workflow
|
||||
|
||||
Every job gets a token as `${{ secrets.GITEA_TOKEN }}`; its permissions follow the
|
||||
workflow's `permissions:` and the repository settings, and pull requests from forks get
|
||||
read-only access, so the job below skips them.
|
||||
|
||||
```yaml
|
||||
jobs:
|
||||
report:
|
||||
if: gitea.event.pull_request.head.repo.full_name == gitea.repository
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
pull-requests: write
|
||||
env:
|
||||
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||
GITEA_CLI_HOST: ${{ gitea.server_url }}
|
||||
GITEA_CLI_REPO: ${{ gitea.repository }}
|
||||
steps:
|
||||
- run: gt pr comment ${{ gitea.event.pull_request.number }} --no-input --body "Build passed."
|
||||
```
|
||||
|
||||
Install gt in the job first (see the README's installation section); the runner image does
|
||||
not include it.
|
||||
|
||||
## Dispatching workflows
|
||||
|
||||
```sh
|
||||
gt workflow list --no-input --json id,name,path,state
|
||||
gt workflow run ci.yml --ref main -f target=staging -f dry_run=true --no-input --json id,url
|
||||
gt workflow run nightly --follow --no-input # dispatch, then follow the job logs
|
||||
gt run watch 34 --timeout 30m --no-input
|
||||
```
|
||||
|
||||
The workflow needs a `workflow_dispatch` trigger. `--ref` defaults to the current or the
|
||||
default branch; inputs are `-f key=value`, repeated.
|
||||
|
||||
## Aliases
|
||||
|
||||
```sh
|
||||
gt alias set failing 'run list --status failure -L 10'
|
||||
gt alias list --no-input
|
||||
```
|
||||
|
||||
Aliases are the user's configuration; create one only when asked.
|
||||
|
||||
## Patterns
|
||||
|
||||
```sh
|
||||
# Wait for CI, then merge. --yes makes the merge final: run this only on the user's explicit request
|
||||
gt pr checks 18 --watch --no-input && gt pr merge 18 --squash --yes --no-input
|
||||
|
||||
# Open pull requests waiting for review, one per line
|
||||
gt pr list --no-input --json number,title,review_decision --jq '.[] | select(.review_decision == "review_required") | "\(.number)\t\(.title)"'
|
||||
|
||||
# Fail a script when the last run on main failed
|
||||
gt run list --branch main -L 1 --no-input --json conclusion --jq '.[0].conclusion' | grep -qx success
|
||||
```
|
||||
@@ -0,0 +1,90 @@
|
||||
# CI: checks, runs and logs
|
||||
|
||||
Gitea reports CI on a pull request as commit statuses ("checks") of its head commit. Gitea
|
||||
Actions runs post one check per job, linked to the job.
|
||||
|
||||
## Is CI green?
|
||||
|
||||
```sh
|
||||
gt pr checks 12 --no-input
|
||||
echo $? # 0 passed, 1 a check failed, 8 checks still pending
|
||||
gt pr checks 12 --no-input --json name,state,description,url
|
||||
```
|
||||
|
||||
- Without a number, `gt pr checks` takes the pull request of the current branch.
|
||||
- `state` is `success`, `skipped` or `pending`, and anything else is a failure, such as
|
||||
`failure` or `error`.
|
||||
- Checks belong to the head commit. After a push, re-read them; old results do not carry over.
|
||||
- `gt pr view 12 --no-input --json head_sha,mergeable,review_decision` tells whether the pull
|
||||
request is mergeable once checks pass.
|
||||
- `gt status --no-input --json failing_runs` lists failing runs of the current repository
|
||||
alongside your pull requests and assigned issues.
|
||||
|
||||
## Waiting
|
||||
|
||||
```sh
|
||||
gt pr checks 12 --watch --no-input # stops at the first failure
|
||||
gt pr checks 12 --watch --timeout 20m --no-input
|
||||
gt run watch 34 --timeout 10m --no-input # fails when the run does not succeed
|
||||
```
|
||||
|
||||
Both poll through an outage of the instance of up to 5 minutes. Prefer waiting over a loop
|
||||
of repeated calls. A run whose jobs never start is waiting for a runner, or, with status
|
||||
`waiting`, for approval in the web interface (a first-time contributor's fork); report that to
|
||||
the user instead of waiting longer.
|
||||
|
||||
## Finding the run
|
||||
|
||||
```sh
|
||||
gt run list --branch feature/login -L 5 --no-input --json id,workflow,status,conclusion,commit
|
||||
gt run list --commit "$(git rev-parse HEAD)" --no-input --json id,workflow,conclusion
|
||||
gt run list --workflow ci.yml --status failure --since 24h --no-input --json id,title,branch
|
||||
gt run view 34 --no-input --json status,conclusion,jobs --jq '.jobs[] | {id, name, status, conclusion}'
|
||||
gt run jobs 34 --no-input --json id,name,conclusion,steps
|
||||
```
|
||||
|
||||
- `--status` takes a status or a conclusion: `queued`, `in_progress`, `waiting`, `completed`,
|
||||
`success`, `failure`, `cancelled`, `skipped`, `timed_out` and others.
|
||||
- `--commit` takes a full SHA or a revision of the local clone.
|
||||
- A run is given by its ID (`34`, `#34`) or its URL; a job URL selects one job.
|
||||
|
||||
## Reading logs
|
||||
|
||||
```sh
|
||||
gt run logs 34 --failed --no-input # every failed job
|
||||
gt run logs 34 --job build --no-input # one job, by name or ID
|
||||
gt run logs https://gitea.example.com/OWNER/REPO/actions/runs/34/jobs/71 --no-input
|
||||
gt run logs 34 --job build --follow --no-input # stream until the job completes
|
||||
gt run logs 34 --output logs.zip --no-input # whole run as a ZIP archive
|
||||
```
|
||||
|
||||
- The log goes to stdout and each job's name to stderr, so `2>/dev/null` leaves pure log.
|
||||
- Logs can be long. Search them (`| grep -n -i -E 'error|fail|panic'`) or read the end
|
||||
(`| tail -n 200`) before loading everything.
|
||||
- `gt run view 34 --log --no-input` prints the logs of every job after the run summary.
|
||||
- Steps are in `gt run jobs 34 --json steps`: a failed step's name narrows where to look.
|
||||
|
||||
From a failing check straight to its log:
|
||||
|
||||
```sh
|
||||
gt pr checks 12 --no-input --json state,url --jq '.[] | select(.state != "success" and .state != "skipped" and .state != "pending") | .url'
|
||||
gt run logs https://gitea.example.com/OWNER/REPO/actions/runs/34/jobs/71 --no-input
|
||||
```
|
||||
|
||||
A check whose `url` points elsewhere comes from an external CI; gt cannot read its logs.
|
||||
|
||||
## Fixing and retrying
|
||||
|
||||
- A real failure: reproduce locally when possible, fix, commit and push, then wait on the new
|
||||
checks with `gt pr checks --watch`.
|
||||
- A flaky failure: `gt run rerun 34 --failed --no-input`, or one job with `--job build`.
|
||||
Rerun only completed runs; cancel a stuck one first with `gt run cancel 34 --no-input`.
|
||||
- Ask the user before rerunning repeatedly or cancelling someone else's run.
|
||||
|
||||
## Artifacts
|
||||
|
||||
```sh
|
||||
gt run artifact list 34 --no-input --json name,size_in_bytes,expired
|
||||
gt run download 34 --name build --dir dist --no-input
|
||||
gt run download 34 --zip --no-input
|
||||
```
|
||||
@@ -0,0 +1,214 @@
|
||||
# Issues, pull requests, comments and reviews
|
||||
|
||||
Issues and pull requests share one number sequence per repository. Commands take a number
|
||||
(`17`, `#17`) or a URL; pull request commands also take a head branch name and default to the
|
||||
current branch's pull request.
|
||||
|
||||
## Contents
|
||||
|
||||
- [Reading an issue](#reading-an-issue)
|
||||
- [Opening and closing issues](#opening-and-closing-issues)
|
||||
- [Working on an issue](#working-on-an-issue)
|
||||
- [Opening the pull request](#opening-the-pull-request)
|
||||
- [Updating the pull request](#updating-the-pull-request)
|
||||
- [Reading a pull request](#reading-a-pull-request)
|
||||
- [Comments](#comments)
|
||||
- [Reviews](#reviews)
|
||||
- [Merging and cleaning up](#merging-and-cleaning-up)
|
||||
- [Repositories](#repositories)
|
||||
- [Releases and wiki](#releases-and-wiki)
|
||||
|
||||
## Reading an issue
|
||||
|
||||
```sh
|
||||
gt issue view 17 --no-input --json number,title,body,state,labels,assignees
|
||||
gt issue comment list 17 -L 100 --no-input --json id,author,body,created_at
|
||||
gt issue view 17 --comments --no-input # text: body, then the conversation
|
||||
gt issue timeline 17 --no-input --json type,author,body,created_at
|
||||
gt issue list --label bug --state open -L 50 --no-input --json number,title,labels
|
||||
gt issue list --assignee @me --no-input --json number,title,updated_at
|
||||
```
|
||||
|
||||
- The `comments` JSON field is the number of comments, not their text; read the text with
|
||||
`gt issue comment list`.
|
||||
- `blocked_by` and `blocks` cost extra requests; request them only when needed.
|
||||
- `gt issue list --kind all` includes pull requests; their `kind` reads `pull`.
|
||||
|
||||
## Opening and closing issues
|
||||
|
||||
```sh
|
||||
gt issue create --no-input --title "Crash on empty config" --label bug --json number,url --body-file - <<'EOF'
|
||||
Steps to reproduce, expected and actual behaviour.
|
||||
EOF
|
||||
gt issue create --template bug --title "Crash on empty config" --no-input --json number,url
|
||||
gt issue close 17 --comment "Fixed in #18." --no-input
|
||||
gt issue reopen 17 --comment "Still happens on main." --no-input
|
||||
```
|
||||
|
||||
- Labels, a milestone, assignees and a due date need write access to the repository's issues.
|
||||
Without it Gitea creates the issue without them, and gt names what it left out and fails.
|
||||
- `--template` starts from a repository issue template; without a terminal it requires
|
||||
`--title`.
|
||||
- Closing and reopening ask no confirmation and are visible to everyone: only when the user
|
||||
asks.
|
||||
|
||||
## Working on an issue
|
||||
|
||||
```sh
|
||||
gt issue edit 17 --add-assignee @me --no-input
|
||||
git switch -c fix/issue-17
|
||||
# change, test, commit with git
|
||||
```
|
||||
|
||||
Assign yourself only when the user asks; it is visible to everyone.
|
||||
|
||||
## Opening the pull request
|
||||
|
||||
```sh
|
||||
gt pr create --no-input --yes --base main --title "fix: crash on empty config" --body-file - <<'EOF'
|
||||
Explain what changed and why.
|
||||
|
||||
Closes #17
|
||||
EOF
|
||||
gt pr create --fill --draft --no-input --yes # title and body from the commits, as a draft
|
||||
gt pr view --no-input --json number,url,state,draft
|
||||
```
|
||||
|
||||
- Any flag of `gt pr create` skips its questions. The title defaults to the commit message of
|
||||
a single-commit branch, else the branch name, so pass `--title`.
|
||||
- A branch not on the remote yet is pushed first, which needs `--yes` without a terminal.
|
||||
Ask the user before that push.
|
||||
- Without push access, the branch goes to the user's fork when one is a remote. Otherwise ask
|
||||
the user to run `gt repo fork --remote` first; gt does not fork without a terminal.
|
||||
- `Closes #17` (or `fixes`, `resolves`) in the body closes the issue when the pull request is
|
||||
merged.
|
||||
- Follow the repository's own contribution rules (title style, sign-off, templates) when they
|
||||
exist; read `CONTRIBUTING.md` before writing the title.
|
||||
- Useful flags: `--reviewer`, `--label`, `--milestone`, `--assignee @me`, `--head OWNER:BRANCH`
|
||||
for a fork branch, `--agit` for AGit flow without a fork.
|
||||
|
||||
## Updating the pull request
|
||||
|
||||
```sh
|
||||
gt pr edit 18 --title "fix: crash on empty config" --no-input
|
||||
gt pr edit 18 --body-file - --no-input <<'EOF'
|
||||
New description.
|
||||
EOF
|
||||
gt pr edit 18 --add-reviewer carol --add-label bug --no-input
|
||||
gt pr ready 18 --no-input # draft to ready; --undo reverses it
|
||||
```
|
||||
|
||||
Pushing new commits with `git push` updates the pull request; then re-check CI
|
||||
([monitoring.md](monitoring.md)).
|
||||
|
||||
## Reading a pull request
|
||||
|
||||
```sh
|
||||
gt pr view 18 --no-input --json title,body,state,base,head,mergeable,review_decision,reviews
|
||||
gt pr comment list 18 -L 100 --no-input --json id,author,body,created_at
|
||||
gt pr view 18 --comments --no-input # text: comments and reviews
|
||||
gt pr diff 18 --name-only --no-input
|
||||
gt pr diff 18 --no-input # unified diff, uncolored when piped
|
||||
gt pr checkout 18 --no-input # switches branches; ask first
|
||||
gt pr status --no-input --json current_branch,review_requested
|
||||
```
|
||||
|
||||
Use `gt pr diff` or `gt pr view` to read; `gt pr checkout` changes the working tree.
|
||||
|
||||
## Comments
|
||||
|
||||
```sh
|
||||
gt issue comment 17 --no-input --body-file - <<'EOF'
|
||||
Comment text in Markdown.
|
||||
EOF
|
||||
gt pr comment 18 --no-input --body "Rebased on main."
|
||||
gt pr comment 18 --edit-last --no-input --body "Rebased on main; CI is green."
|
||||
gt pr comment list 18 --no-input --json id,author,body,created_at
|
||||
gt issue comment edit 2001 --no-input --body "Corrected text."
|
||||
```
|
||||
|
||||
- `--edit-last` and `--delete-last` act on your own latest comment.
|
||||
- `--attachment FILE` (repeatable) uploads screenshots or logs with the comment.
|
||||
- Comments on a pull request's conversation tab use `gt pr comment`; comments on lines of the
|
||||
diff are review comments, below.
|
||||
|
||||
## Reviews
|
||||
|
||||
```sh
|
||||
gt pr review 18 --approve --no-input --body "Looks good."
|
||||
gt pr review 18 --request-changes --no-input --body-file - <<'EOF'
|
||||
Please handle the empty case.
|
||||
EOF
|
||||
gt pr review 18 --comment --comments-file inline.json --no-input
|
||||
```
|
||||
|
||||
`inline.json` holds one JSON array:
|
||||
|
||||
```json
|
||||
[
|
||||
{"path": "internal/config/load.go", "body": "This returns nil on an empty file.", "new_position": 42},
|
||||
{"path": "README.md", "body": "This line was removed but is still referenced.", "old_position": 10}
|
||||
]
|
||||
```
|
||||
|
||||
- `new_position` is a line number in the new file, `old_position` in the old one; exactly
|
||||
one per comment, on a line that is part of the diff. gt checks this before sending.
|
||||
- `--comments-file` needs a real file, not `-`.
|
||||
- `--request-changes` requires a body; `--comment` requires a body or inline comments.
|
||||
- To collect comments first: `gt pr review 18 --pending --comments-file inline.json --no-input`,
|
||||
then `gt pr review submit 18 --approve --no-input`. A later review publishes a pending one,
|
||||
which needs `--yes` without a terminal.
|
||||
|
||||
Following up on reviews:
|
||||
|
||||
```sh
|
||||
gt pr review list 18 --no-input --json id,author,state,body
|
||||
gt pr review comments 18 --no-input --json id,path,line,body,author,resolver
|
||||
gt pr review reply 18 1234 --no-input --body "Fixed in the latest commit."
|
||||
gt pr review resolve 1234 --no-input
|
||||
```
|
||||
|
||||
## Merging and cleaning up
|
||||
|
||||
```sh
|
||||
gt pr merge 18 --squash --delete-branch --no-input --yes
|
||||
gt pr merge 18 --auto --no-input --yes # merge once required checks succeed
|
||||
gt pr clean 18 --no-input --yes # delete the branches of a merged pull request
|
||||
```
|
||||
|
||||
Merging is irreversible and visible: only on the user's explicit request. Without a method gt
|
||||
uses the repository's default merge style.
|
||||
|
||||
## Repositories
|
||||
|
||||
```sh
|
||||
gt repo view --no-input --json full_name,default_branch,private,actions_enabled
|
||||
gt repo list OWNER -L 100 --no-input --json full_name,description,archived
|
||||
gt repo fork --remote --no-input
|
||||
gt repo edit --description "A short description" --add-topic cli --no-input
|
||||
gt repo edit --enable-wiki=false --no-input
|
||||
```
|
||||
|
||||
- `gt repo edit` changes only the flags passed; on/off settings take `=false` to turn off.
|
||||
- Changing settings, renaming, transferring, archiving and deleting affect everyone; run them
|
||||
only on the user's request. `gt repo archive`, `rename`, `transfer` and `delete` need
|
||||
`--yes` without a terminal.
|
||||
|
||||
## Releases and wiki
|
||||
|
||||
```sh
|
||||
gt release list -L 5 --no-input --json tag,title,draft,published_at
|
||||
gt release create v1.2.0 dist/app.tar.gz --notes-file CHANGELOG.md --draft --no-input
|
||||
gt wiki list --no-input --json title
|
||||
gt wiki view Home --no-input --json body
|
||||
gt wiki create "Release process" --body-file docs/release.md --no-input
|
||||
gt wiki edit Home --message "Document the release steps" --no-input --body-file - <<'EOF'
|
||||
New page content.
|
||||
EOF
|
||||
gt wiki edit "Old title" --title "New title" --no-input # renames, keeping the content
|
||||
gt wiki revisions Home --no-input --json sha,author,message,created_at
|
||||
gt wiki delete "Old Notes" --no-input --yes
|
||||
```
|
||||
|
||||
`gt release create` creates the tag at `--target` (the default branch) when it does not exist;
|
||||
pass `--verify-tag` to require an existing tag.
|
||||
@@ -0,0 +1,44 @@
|
||||
# Finding issues, pull requests and your work
|
||||
|
||||
## Search or list?
|
||||
|
||||
- `gt issue list` and `gt pr list` read one repository and filter by state, labels, people and
|
||||
milestone. `-S` searches titles and bodies in that repository.
|
||||
- `gt search issue`, `gt search pr` and `gt search repo` search the whole selected instance,
|
||||
or one owner with `--owner`, or one repository with `-R`.
|
||||
- gt has no code search; to find code, clone or read files with `gt api` ([api.md](api.md)).
|
||||
|
||||
```sh
|
||||
gt issue list --label bug --milestone v1.0 --state all -L 100 --no-input --json number,title,state
|
||||
gt issue list -S "panic on start" --no-input --json number,title,url
|
||||
gt pr list --author @me --state open --no-input --json number,title,head,review_decision
|
||||
gt pr list --head feature/login --no-input --json number,url
|
||||
gt search issue "login error" --owner OWNER --no-input --json repository,number,title,url
|
||||
gt search pr --review-requested --no-input --json repository,number,title,url
|
||||
gt search repo cli --owner gitea --no-input --json full_name,description
|
||||
```
|
||||
|
||||
- The query is a plain search string. Filter with flags (`--label`, `--author`, `--state`)
|
||||
rather than GitHub-style qualifiers such as `is:open`; Gitea's search API takes these
|
||||
filters as separate parameters.
|
||||
- `@me` stands for the signed-in user in `--author`, `--assignee` and, on issues only,
|
||||
`gt issue list --mentions @me`. `gt search issue` and `gt search pr` have switches
|
||||
instead: `gt search issue --assigned --mentioned --no-input`.
|
||||
- Results stop at `-L` (default 30). An empty result exits 0; check the count, not the exit
|
||||
code, before saying nothing exists.
|
||||
- `--since` and `--until` take a date, an RFC3339 timestamp or a duration ago (`24h`).
|
||||
|
||||
## Your work
|
||||
|
||||
```sh
|
||||
gt status --no-input --json pull_requests,assigned_issues,mentions,failing_runs
|
||||
gt pr status --no-input --json current_branch,authored,review_requested
|
||||
gt notification list --no-input --json id,repository,type,number,title,unread
|
||||
gt notification list --type pull --this-repo --no-input --json id,number,title
|
||||
```
|
||||
|
||||
- `gt status` gathers your open pull requests, assigned issues, mentions and the failing
|
||||
Actions runs of the current repository.
|
||||
- Notification IDs are thread IDs, not issue numbers; `number` and `repository` name the issue
|
||||
or pull request. `gt notification view` marks a notification as read, so prefer
|
||||
`gt notification list` for reading.
|
||||
@@ -0,0 +1,48 @@
|
||||
# Writing Gitea Actions workflows
|
||||
|
||||
Gitea Actions aims to be compatible with GitHub Actions, so most workflow syntax carries over.
|
||||
This page lists what differs. Sources: Gitea's
|
||||
[quick start](https://docs.gitea.com/usage/actions/quickstart),
|
||||
[comparison with GitHub Actions](https://docs.gitea.com/usage/actions/comparison) and
|
||||
[job token permissions](https://docs.gitea.com/usage/actions/token-permissions/); check them
|
||||
when a detail matters, as they change with Gitea releases.
|
||||
|
||||
## Before the first workflow
|
||||
|
||||
- Workflows are `.yaml` files in `.gitea/workflows/`.
|
||||
- Repositories have Actions disabled by default: enable it in the repository settings
|
||||
("Enable Repository Actions"); `gt repo view --no-input --json actions_enabled` tells.
|
||||
- Jobs run on a registered Gitea Runner; `runs-on` labels must match the labels of a runner
|
||||
of the instance. A run that waits forever usually lacks a matching runner
|
||||
([monitoring.md](monitoring.md#waiting)).
|
||||
|
||||
## Differences from GitHub Actions
|
||||
|
||||
- Gitea's examples use the `gitea.*` context (`gitea.repository`, `gitea.ref`,
|
||||
`gitea.server_url`, …) where GitHub uses `github.*`.
|
||||
- `uses:` accepts an absolute URL to any Git host, such as
|
||||
`uses: https://gitea.com/actions/checkout@v4`. Without a host, actions come from
|
||||
`https://github.com`, or from the instance itself when the administrator set
|
||||
`[actions].DEFAULT_ACTIONS_URL` to `self`.
|
||||
- `uses: self:owner/repo@v1` refers to an action on the same instance, and `$/path` to an
|
||||
action next to the workflow without a checkout.
|
||||
- `schedule` also accepts `@yearly`, `@monthly`, `@weekly`, `@daily` and `@hourly`.
|
||||
- Ignored: `jobs.<job_id>.environment`, problem matchers and error annotations.
|
||||
- The job token is `${{ secrets.GITEA_TOKEN }}`. `permissions:` takes `contents`, `code`,
|
||||
`releases`, `issues`, `pull-requests`, `actions`, `wiki`, `projects` and `packages`, with
|
||||
`read`, `write` or `none`; GitHub-only scopes such as `statuses`, `checks` and `id-token`
|
||||
are not supported. Pull requests from forks always get read-only contents.
|
||||
- `GITEA_TOKEN` cannot publish to the package registry of its repository, such as pushing
|
||||
OCI images; use a personal access token in a secret for that.
|
||||
|
||||
## Trying a workflow
|
||||
|
||||
```sh
|
||||
gt workflow list --no-input --json name,path,state
|
||||
gt workflow view ci.yml --no-input --json name,path,state
|
||||
gt workflow run ci.yml --ref feature/ci --follow --no-input # needs a workflow_dispatch trigger
|
||||
gt run list --workflow ci.yml -L 5 --no-input --json id,status,conclusion,branch
|
||||
```
|
||||
|
||||
Push the workflow on a branch and open a pull request to see it run on the pull request event;
|
||||
then read failures as in [monitoring.md](monitoring.md).
|
||||
Reference in New Issue
Block a user