|
| 1 | +# ghapi Module Documentation |
| 2 | + |
| 3 | +## ghapi.actions |
| 4 | + |
| 5 | +> Functionality for helping to create GitHub Actions workflows in Python |
| 6 | + |
| 7 | +- `def user_repo()` |
| 8 | + List of `user,repo` from `env_github.repository |
| 9 | + |
| 10 | +- `def create_workflow_files(fname, workflow, build_script, prebuild)` |
| 11 | + Create workflow and script files in suitable places in `github` folder |
| 12 | + |
| 13 | +- `def fill_workflow_templates(name, event, run, context, script, opersys, prebuild)` |
| 14 | + Function to create a simple Ubuntu workflow that calls a Python `ghapi` script |
| 15 | + |
| 16 | +- `def env_contexts(contexts)` |
| 17 | + Create a suitable `env:` line for a workflow to make a context available in the environment |
| 18 | + |
| 19 | +- `def create_workflow(name, event, contexts, opersys, prebuild)` |
| 20 | + Function to create a simple Ubuntu workflow that calls a Python `ghapi` script |
| 21 | + |
| 22 | +- `@call_parse def gh_create_workflow(name, event, contexts)` |
| 23 | + Supports `gh-create-workflow`, a CLI wrapper for `create_workflow`. |
| 24 | + |
| 25 | +- `def example_payload(event)` |
| 26 | + Get an example of a JSON payload for `event` |
| 27 | + |
| 28 | +- `def github_token()` |
| 29 | + Get GitHub token from `GITHUB_TOKEN` env var if available, or from `github` context |
| 30 | + |
| 31 | +- `def actions_output(name, value)` |
| 32 | + Print the special GitHub Actions `::set-output` line for `name::value` |
| 33 | + |
| 34 | +- `def actions_debug(message)` |
| 35 | + Print the special `::debug` line for `message` |
| 36 | + |
| 37 | +- `def actions_warn(message, details)` |
| 38 | + Print the special `::warning` line for `message` |
| 39 | + |
| 40 | +- `def actions_error(message, details)` |
| 41 | + Print the special `::error` line for `message` |
| 42 | + |
| 43 | +- `@contextmanager def actions_group(title)` |
| 44 | + Context manager to print the special `::group`/`::endgroup` lines for `title` |
| 45 | + |
| 46 | +- `def actions_mask(value)` |
| 47 | + Print the special `::add-mask` line for `value` |
| 48 | + |
| 49 | +- `def set_git_user(api)` |
| 50 | + Set git user name/email to authenticated user (if `api`) or GitHub Actions bot (otherwise) |
| 51 | + |
| 52 | +## ghapi.auth |
| 53 | + |
| 54 | +> Helpers for creating GitHub API tokens |
| 55 | + |
| 56 | +- `def scope_str(*scopes)` |
| 57 | + Convert `scopes` into a comma-separated string |
| 58 | + |
| 59 | +- `class GhDeviceAuth` |
| 60 | + Get an oauth token using the GitHub API device flow |
| 61 | + |
| 62 | + - `def __init__(self, client_id, *scopes)` |
| 63 | + |
| 64 | +- `@patch def url_docs(self)` |
| 65 | + Default instructions on how to authenticate |
| 66 | + |
| 67 | +- `@patch def open_browser(self)` |
| 68 | + Open a web browser with the verification URL |
| 69 | + |
| 70 | +- `@patch def auth(self)` |
| 71 | + Return token if authentication complete, or `None` otherwise |
| 72 | + |
| 73 | +- `@patch def wait(self, cb, n_polls)` |
| 74 | + Wait up to `n_polls` times for authentication to complete, calling `cb` after each poll, if passed |
| 75 | + |
| 76 | +- `def github_auth_device(wb, n_polls)` |
| 77 | + Authenticate with GitHub, polling up to `n_polls` times to wait for completion |
| 78 | + |
| 79 | +## ghapi.build_lib |
| 80 | + |
| 81 | +- `def build_funcs(nm, url, docurl)` |
| 82 | + Build module metadata.py from an Open API spec and optionally filter by a path `pre` |
| 83 | + |
| 84 | +## ghapi.cli |
| 85 | + |
| 86 | +> Access to the GitHub API from the command line |
| 87 | + |
| 88 | +- `def ghapi()` |
| 89 | + Python backend for the `ghapi` command, which calls an endpoint by operation name |
| 90 | + |
| 91 | +- `def ghpath()` |
| 92 | + Python backend for the `ghpath` command, which calls an endpoint by path |
| 93 | + |
| 94 | +- `def ghraw()` |
| 95 | + Python backend for the `ghraw` command, which calls a fully-specified endpoint |
| 96 | + |
| 97 | +- `def completion_ghapi()` |
| 98 | + Python backend for `completion-ghapi` command |
| 99 | + |
| 100 | +## ghapi.core |
| 101 | + |
| 102 | +> Detailed information on the GhApi API |
| 103 | + |
| 104 | +- `def print_summary(req)` |
| 105 | + Print `Request.summary` with the token (if any) removed |
| 106 | + |
| 107 | +- `class GhApi` |
| 108 | + - `def __init__(self, owner, repo, token, jwt_token, debug, limit_cb, gh_host, authenticate, **kwargs)` |
| 109 | + - `def __call__(self, path, verb, headers, route, query, data, timeout, decode)` |
| 110 | + Call a fully specified `path` using HTTP `verb`, passing arguments to `fastcore.core.urlsend` |
| 111 | + |
| 112 | + - `def __dir__(self)` |
| 113 | + - `def __getattr__(self, k)` |
| 114 | + - `def __getitem__(self, k)` |
| 115 | + Lookup and call an endpoint by path and verb (which defaults to 'GET') |
| 116 | + |
| 117 | + - `def full_docs(self)` |
| 118 | + |
| 119 | +- `def date2gh(dt)` |
| 120 | + Convert `dt` (which is assumed to be in UTC time zone) to a format suitable for GitHub API operations |
| 121 | + |
| 122 | +- `def gh2date(dtstr)` |
| 123 | + Convert date string `dtstr` received from a GitHub API operation to a UTC `datetime` |
| 124 | + |
| 125 | +- `@patch def create_gist(self, description, content, filename, public)` |
| 126 | + Create a gist containing a single file |
| 127 | + |
| 128 | +- `@patch def delete_release(self, release)` |
| 129 | + Delete a release and its associated tag |
| 130 | + |
| 131 | +- `@patch def upload_file(self, rel, fn)` |
| 132 | + Upload `fn` to endpoint for release `rel` |
| 133 | + |
| 134 | +- `@patch def create_release(self, tag_name, branch, name, body, draft, prerelease, files)` |
| 135 | + Wrapper for `GhApi.repos.create_release` which also uploads `files` |
| 136 | + |
| 137 | +- `@patch def list_tags(self, prefix)` |
| 138 | + List all tags, optionally filtered to those starting with `prefix` |
| 139 | + |
| 140 | +- `@patch def list_branches(self, prefix)` |
| 141 | + List all branches, optionally filtered to those starting with `prefix` |
| 142 | + |
| 143 | +- `@patch def delete_tag(self, tag)` |
| 144 | + Delete a tag |
| 145 | + |
| 146 | +- `@patch def delete_branch(self, branch)` |
| 147 | + Delete a branch |
| 148 | + |
| 149 | +- `@patch def enable_pages(self, branch, path)` |
| 150 | + Enable or update pages for a repo to point to a `branch` and `path`. |
| 151 | + |
| 152 | +## ghapi.event |
| 153 | + |
| 154 | +> Helpers for getting GitHub API events |
| 155 | + |
| 156 | +- `@patch @delegates(_list_events) def list_events(self, per_page, page, **kwargs)` |
| 157 | + Fetch public events for repo network, org, user, or all |
| 158 | + |
| 159 | +- `@patch @delegates(_list_events) def list_events_parallel(self, per_page, n_pages, **kwargs)` |
| 160 | + Fetch as many events from `list_events` in parallel as available |
| 161 | + |
| 162 | +- `class GhEvent` |
| 163 | + Class for events returned from `fetch_events |
| 164 | + |
| 165 | + |
| 166 | +- `@patch @delegates(_list_events) def fetch_events(self, n_pages, pause, per_page, types, incl_bot, **kwargs)` |
| 167 | + Generate an infinite stream of events, optionally filtered to `types, with `pause` seconds between requests |
| 168 | + |
| 169 | +- `def load_sample_events()` |
| 170 | + Load sample events, downloading if needed |
| 171 | + |
| 172 | +- `def save_sample_events(n)` |
| 173 | + Save the most recent `n` events as compressed JSON |
| 174 | + |
| 175 | +- `@patch(as_prop=True) def full_type(self)` |
| 176 | + Concatenation of `type` and `payload.action` (if available) |
| 177 | + |
| 178 | +- `@patch(as_prop=True) def description(self)` |
| 179 | + Description of event |
| 180 | + |
| 181 | +- `@patch(as_prop=True) def emoji(self)` |
| 182 | + Emoji for event from `evt_emojis` |
| 183 | + |
| 184 | +- `@patch(as_prop=True) def text(self)` |
| 185 | + Text (e.g. body or title) of event, if exists |
| 186 | + |
| 187 | +## ghapi.page |
| 188 | + |
| 189 | +> Parallel and serial pagination |
| 190 | + |
| 191 | +- `def paged(oper, *args, **kwargs)` |
| 192 | + Convert operation `oper(*args,**kwargs)` into an iterator |
| 193 | + |
| 194 | +- `def parse_link_hdr(header)` |
| 195 | + Parse an RFC 5988 link header, returning a `dict` from rels to a `tuple` of URL and attrs `dict` |
| 196 | + |
| 197 | +- `@patch def last_page(self)` |
| 198 | + Parse RFC 5988 link header from most recent operation, and extract the last page |
| 199 | + |
| 200 | +- `def pages(oper, n_pages, *args, **kwargs)` |
| 201 | + Get `n_pages` pages from `oper(*args,**kwargs)` |
| 202 | + |
0 commit comments