Shared Atlassian clients: atlassian/jira and atlassian/confluence
New library module yetano.dev/yetano/yetano-clients (owner decision 2026-11-01) replacing the three own Jira clients in yareco, yabaratla and yamcp: - atlassian: Options, Auth (api_token, basic, bearer/pat, cookie), Deployment (Cloud/Data Center), TLS, APIError and sentinel errors. - atlassian/internal/transport: retry with backoff on 5xx/connection errors, shared adaptive 429 throttle honouring Retry-After (from yabaratla/yareco), CA file, proxy, cross-host redirect hardening, response cap (from yamcp), startAt pagination, file downloads. - atlassian/jira: typed reads (projects, versions, fields, issues, comments, changelog, editmeta, transitions), JQL search on Cloud (/search/jql) and Data Center, classic search pages, issue writes, ADF/plain-text bodies per deployment, custom-field helpers. - atlassian/confluence: small content API client (CQL search, pages, spaces, current user, create/update page with version check, comment, label), taken over from yamcp. Standard library only; tests against httptest servers. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
6a97dbd4c6
24 files changed
+3524
No files matched your search
@@ -0,0 +1,118 @@
|
||||
# yetano-clients
|
||||
|
||||
Shared Go clients for the external services Yetano programs talk to.
|
||||
This is a library module (`yetano.dev/yetano/yetano-clients`), imported
|
||||
like `core` -- nothing here is built or published as a program.
|
||||
|
||||
Today it holds the Atlassian clients that `yareco`, `yabaratla` and
|
||||
`yamcp` used to carry as three separate copies (owner decision
|
||||
2026-11-01):
|
||||
|
||||
| Package | What |
|
||||
|---|---|
|
||||
| `atlassian` | `Options`, `Auth`, `Deployment`, `TLS`, the error types (`APIError`, `StatusOf`, `ErrNotJSON`, `ErrResponseTooLarge`, `ErrInvalidArgument`) |
|
||||
| `atlassian/jira` | Jira REST API client (Cloud v3 and Server/Data Center v2) |
|
||||
| `atlassian/confluence` | small Confluence REST API client (classic content API) |
|
||||
| `atlassian/internal/transport` | the HTTP machinery both share; not importable from outside |
|
||||
|
||||
Standard library only, no third-party dependencies.
|
||||
|
||||
## Usage
|
||||
|
||||
```go
|
||||
c, err := jira.New(atlassian.Options{
|
||||
BaseURL: "https://example.atlassian.net",
|
||||
Deployment: atlassian.Cloud, // or atlassian.DataCenter
|
||||
Auth: atlassian.Auth{Type: atlassian.AuthAPIToken, Username: email, Password: token},
|
||||
Timeout: 60 * time.Second,
|
||||
MaxRetries: 3,
|
||||
})
|
||||
issues, err := c.SearchAll(ctx, jira.SearchQuery{JQL: "project = DEV", Fields: []string{"summary"}})
|
||||
```
|
||||
|
||||
`New` never sends a request. Every call takes a context; cancelling it
|
||||
also ends a backoff or rate-limit wait.
|
||||
|
||||
## Transport behaviour
|
||||
|
||||
One `Options` drives both clients:
|
||||
|
||||
- **Auth**: `api_token` (e-mail + API token as basic auth, Cloud),
|
||||
`basic`, `bearer`/`pat` (Data Center personal access token), `cookie`
|
||||
(a raw Cookie header). The zero `Type` picks from the fields that are
|
||||
set. A type whose fields are empty sends no header at all.
|
||||
- **TLS/proxy**: optional CA bundle, explicit `InsecureSkipVerify`,
|
||||
`ProxyURL` or the environment's `HTTPS_PROXY`.
|
||||
- **Redirects** to another host drop `Authorization` and `Cookie`
|
||||
(also for downloads, e.g. a signed media URL).
|
||||
- **Retries**: 5xx and connection errors are retried `MaxRetries`
|
||||
attempts in total with backoff 2s, 4s, ... (cap 30s). 4xx is never
|
||||
retried.
|
||||
- **429**: pauses every request of the client until `Retry-After` and
|
||||
widens a shared minimum gap between requests, which narrows again on
|
||||
success; up to 10 such retries that do not count against `MaxRetries`.
|
||||
`DisableRateLimitRetry` returns the 429 at once instead.
|
||||
- **APIDelay**: fixed pause after every response.
|
||||
- **Bodies**: an empty 2xx body reads as `{}`; a non-JSON 2xx body
|
||||
(e.g. an SSO login page) is `ErrNotJSON`, never an empty result.
|
||||
`MaxResponseBytes` caps what is read into memory.
|
||||
- **Errors**: a non-2xx answer is an `*atlassian.APIError` (method,
|
||||
path, status, body; `Message()` extracts Atlassian's error text).
|
||||
Credentials never appear in an error or a log line; a download URL's
|
||||
query is dropped from errors and logs.
|
||||
- **Pagination**: `Paginate` walks `startAt`/`maxResults` listings and
|
||||
advances by the number of items actually returned (Jira may cap
|
||||
`maxResults`).
|
||||
|
||||
## Jira
|
||||
|
||||
Typed calls: `Myself`, `ServerInfo`, `ListProjects`, `Project`,
|
||||
`ProjectVersions`, `Version`, `UpdateVersion`, `Fields`, `Issue`,
|
||||
`Search`/`SearchAll` (Cloud: `/search/jql` with `nextPageToken`; Data
|
||||
Center: `/search` with offsets), `SearchPage` (one classic offset page),
|
||||
`CommentPage`, `Comments`, `Changelog`, `EditMeta`, `Transitions`,
|
||||
`EditIssue`/`UpdateIssue`, `CreateIssue`, `AddComment`, `DoTransition`,
|
||||
`AssignIssue`, `LinkIssues`; `TextBody` encodes plain text as ADF on
|
||||
Cloud and as a string on Data Center. Field helpers for custom fields:
|
||||
`OptionValues`, `SprintValues`, `CustomFieldNumber`, `Names`.
|
||||
Everything else goes through the raw `Get`/`Post`/`Put`/`Delete`/
|
||||
`Paginate`/`DownloadFile` (paths are absolute, e.g.
|
||||
`/rest/agile/1.0/board`).
|
||||
|
||||
## Confluence
|
||||
|
||||
`Search` (CQL), `Page`, `PageChildren`, `Space`, `ListSpaces`,
|
||||
`CurrentUser`, `Ping`, `CreatePage`, `UpdatePage` (re-reads the page and
|
||||
returns `*VersionConflictError` instead of overwriting a newer version),
|
||||
`AddComment`, `AddLabel`; `StorageFromText` turns plain text into an
|
||||
escaped storage-format body. Kept small on purpose -- see `TODO.md` for
|
||||
what is not covered.
|
||||
|
||||
## Where the code came from
|
||||
|
||||
| Part | Origin |
|
||||
|---|---|
|
||||
| retry/backoff, 429 throttle, `APIDelay`, `Paginate`, `DownloadFile`, cookie auth | `yabaratla/internal/jira` (via `yareco`, which added contexts and `log/slog`) |
|
||||
| typed Jira reads, `Search` with `nextPageToken`, field helpers | `yareco/internal/jira` |
|
||||
| bearer/PAT/basic auth, CA file, proxy, redirect hardening, response cap, Atlassian error messages, Cloud/Data Center split, Jira writes, the Confluence client | `yamcp/internal/provider/atlassian` |
|
||||
|
||||
Program-specific parts stayed in the programs: yareco's German operator
|
||||
messages and field resolution, yamcp's error taxonomy and MCP output
|
||||
types, yabaratla's Confluence site-backup client.
|
||||
|
||||
## Checks
|
||||
|
||||
```sh
|
||||
make # fmt + vet + test (-race) + vulncheck
|
||||
make test
|
||||
```
|
||||
|
||||
## Versioning
|
||||
|
||||
A release is a plain semver git tag (`v0.1.0`, ...) on this repository;
|
||||
consumers require that tag. Never force-move a tag -- always cut a new
|
||||
one, even for a one-line fix (see the meta-repository's `AGENTS.md`).
|
||||
|
||||
## License
|
||||
|
||||
Proprietary, see [LICENSE](LICENSE).
|
||||
Reference in new issue
Block a user