Metadata-Version: 2.4
Name: treepos
Version: 0.0.1
Summary: Declarative, delegated management of GitHub organizations as a tree of repos.
Author: Will Meagher
License-Expression: Apache-2.0
License-File: LICENSE
License-File: NOTICE
Classifier: Development Status :: 2 - Pre-Alpha
Classifier: Environment :: Console
Classifier: Programming Language :: Python :: 3.14
Classifier: Programming Language :: Python :: 3.15
Classifier: Typing :: Typed
Requires-Dist: githubkit[auth-app]>=0.17.1
Requires-Dist: pydantic>=2.12
Requires-Dist: ruamel-yaml>=0.18
Requires-Python: >=3.14
Project-URL: Repository, https://github.com/treepos/treepos
Project-URL: Documentation, https://github.com/treepos/treepos#readme
Project-URL: Issues, https://github.com/treepos/treepos/issues
Description-Content-Type: text/markdown

# treepos

**treepos manages a GitHub organization declaratively, as a tree.** Each object holds the ones
below it: an organization holds repos, and a repo's config can declare more repos and teams. Any
branch of the tree can be handed to the team that owns it, who can hand part of theirs on in
turn. A **runner** repo reads the tree from files in GitHub and makes GitHub match it.

> **Status: pre-alpha.** This repository is the `treepos` command-line tool. So far it plans an
> org's teams, members and team members, its repos, and the custom properties that mark them,
> against live GitHub or a live-state file, and applies a plan to either. Its files are read from
> the runner file's folder, and refs into other repos from GitHub, once a run signs in to it, a
> pinned commit only where it's on a branch of its repo. Who can read and write what those refs
> bring in isn't checked yet.

> **Warning: config is the whole org.** A plan archives every repo the tree doesn't declare and
> marks it removed, never deleting it. The one repo it spares is the runner repo, and only when
> `--runner-repo-id` gives its ID, as the action always does. Try it on a live-state file or a
> test org before a real one.

## Install

```sh
uv tool install treepos  # or: pipx install treepos
```

It needs Python 3.14 or later, which `uv` fetches if it's missing.

## Try it

From a runner repo, whose runner file, `.treepos/runner.yaml` by convention, declares the tree's
ID, `tree`, and holds the org or refs its file:

```sh
treepos plan --runner .treepos/runner.yaml --live-state github.yaml
treepos apply --runner .treepos/runner.yaml --live-state github.yaml
treepos plan --runner .treepos/runner.yaml --live-state github.yaml --out -  # nothing left
```

`github.yaml` is the state of an in-memory GitHub, in the form
[live_state.py](https://github.com/treepos/treepos/blob/main/src/treepos/adapters/memory_github/live_state.py)
reads. `plan` writes the plan to `treepos-plan.json`, and `apply` applies it to the same file,
rewriting it to the state it leaves; any comments in it are lost. Results go to `--out`, and
findings to stderr. Without `--runner-repo-id`, a warning says no repo is spared. The marks name
the tree by its declared `tree`.

To plan against live GitHub instead, leave out `--live-state`: the run signs in with the runner
object's `credential`, a `credential/fine_grained_pat` or a `credential/app_installation`, whose
keys it reads from the secrets they name: in Actions from `TREEPOS_SECRETS`, the job's secrets as
JSON, and otherwise from environment variables of those names. Or name where a raw token that
can read the org is, never the token itself: `--credential env:GITHUB_TOKEN`, `file:<path>`,
`stdin` or `gh`, for `gh auth token`. A plan read with a raw token is a preview, so it's never applied.

To apply to live GitHub, leave out `--live-state` there too: `apply` signs in with the runner
object's `credential`, never a raw token. It applies only a plan that isn't a preview: one planned
with the runner's credential. The runner file and the files beside it are read from disk.

To run it as a runner, in a runner repo's GitHub Actions:
[docs/actions.md](https://github.com/treepos/treepos/blob/main/docs/actions.md).

## Why

GitHub can't limit a permission to a name prefix, and creating a repo needs a permission that
reaches every repo in the org. treepos makes delegation real: a parent wraps the part it hands
over in a **policy** that says what may be written below and what values must satisfy. treepos
checks every write against every policy above it before anything changes.

## Contributing

[CONTRIBUTING.md](https://github.com/treepos/treepos/blob/main/CONTRIBUTING.md) has the setup, the
rules and the checks.

## License

[Apache-2.0](https://github.com/treepos/treepos/blob/main/LICENSE).
