Files
gitea-ci-library/docs/tickets/0001-report-status-sh.md
niko 8f1bf7e347
CI — gitea-ci-library / feature (push) Failing after 1s
CI — gitea-ci-library / master (push) Has been skipped
feat(dispatch): implement dispatch-workflow.sh with dispatch, poll, and timeout (#4)
Add dispatch-workflow.sh script that dispatches a Gitea workflow
in another repository and polls synchronously for completion.
Refactor mock-api.sh to use Python3 HTTP server with sequence
support, enabling stateful poll-response simulation in tests.

---------

Co-authored-by: moilanik <niko.moilanen@tietoevry.com>
Reviewed-on: #4
2026-06-08 16:08:55 +03:00

3.1 KiB

Ticket 0001: report-status.sh

Vaihe: 1/12 Status: done Feature branch: feature/0001-report-status-sh TDD required: Yes Feature file required: Yes

Required context:

  • docs/test-plan/tdd-guide.md
  • tests/features/0001-report-status.feature
  • Skills: tdd, implementation, clean-code, bash-script

TDD — Red-Green-Refactor

Red

Kirjoita tests/report-status.bats ennen implementaatiota. Testi käyttää tests/helpers/mock-api.sh mock-Gitea API:a. Varmista:

  • pending-status POSTautuu oikein
  • success-status + url + key
  • failure-status
  • Cross-repo: root_commit + root_repo → status menee root-committiin
  • Virhetilanne: API palauttaa 500 → exit 1
  • Puuttuva GITEA_API_URL → exit 1 + virheviesti
bats tests/report-status.bats
# Kaikki testit FAIL: skriptiä ei ole vielä

Green

Toteuta scripts/report-status.sh. Minimiversio: vain curl POST + virheenkäsittely.

bats tests/report-status.bats
# Kaikki testit PASS

Refactor

Poista duplikaatio, paranna virheviestejä. Testit pysyvät vihreänä.

DoD (Definition of Done)

  • Cucumber: @ticket-0001 and @mock → kaikki skenaariot GREEN
  • tests/report-status.bats kaikki testit menevät läpi
  • tests/helpers/mock-api.sh palvelee mock-vastaukset
  • scripts/report-status.sh toteuttaa kaikki parametrit
  • Cross-repo-statusraportointi toimii

Toiminto

POSTaa build-statuksen Gitea REST APIin. Jokainen workflow-steppi kutsuu tätä skriptiä raportoidakseen tilansa Git-committiin.

Rajapinta

report-status.sh <state> <description> <url> [key] [root_commit] [root_repo]
Parametri Pakollinen Kuvaus
state Kyllä pending, success, failure, error
description Kyllä Ihmisluettava kuvaus
url Kyllä Linkki buildiin tai raporttiin
key Ei Uniikki avain. Oletus: commit-{sha_short}
root_commit Ei Root-buildin commit (cross-repo-raportointi)
root_repo Ei Root-buildin repo (cross-repo-raportointi)

Gitea API -kutsu

POST /api/v1/repos/{owner}/{repo}/statuses/{sha}
Authorization: token {GITEA_TOKEN}

{
  "state": "{state}",
  "target_url": "{url}",
  "description": "{description}",
  "context": "{key}"
}

Ympäristömuuttujat

  • GITEA_API_URL — Org variable
  • GITEA_TOKEN — Org secret
  • GITHUB_REPOSITORY — Automaattinen
  • GITHUB_SHA — Automaattinen
  • GITHUB_SERVER_URL — Automaattinen
  • GITHUB_RUN_ID — Automaattinen

Verifiointi

bash scripts/report-status.sh success "Test OK" "https://example.com" → mock-API palauttaa 201

Kutsu cross-repo-parametreilla:

report-status.sh success "Deployed to staging" "https://gitea.example.com/helm-repo/commit/def456" "deploy-staging" "abc123" "services/temperature-store"

→ statusviesti ilmestyy root-committiin abc123

Viitteet

  • docs/shared-scripts.md — Rajapinnan määrittely
  • docs/architecture.md — Tietovuo 1: Commit-statusraportointi
  • docs/design-rationale.md — Periaate 1: Git-commit on universaali statusnäkymä