|
6 | 6 | "metadata": {}, |
7 | 7 | "outputs": [], |
8 | 8 | "source": [ |
9 | | - "#|default_exp core" |
| 9 | + "#| default_exp core" |
10 | 10 | ] |
11 | 11 | }, |
12 | 12 | { |
|
24 | 24 | "metadata": {}, |
25 | 25 | "outputs": [], |
26 | 26 | "source": [ |
27 | | - "#|export\n", |
| 27 | + "#| export\n", |
28 | 28 | "from fastcore.all import *\n", |
29 | 29 | "from ghapi.metadata import funcs\n", |
30 | 30 | "\n", |
|
45 | 45 | "metadata": {}, |
46 | 46 | "outputs": [], |
47 | 47 | "source": [ |
48 | | - "#|hide\n", |
| 48 | + "#| hide\n", |
49 | 49 | "from nbdev import *" |
50 | 50 | ] |
51 | 51 | }, |
|
55 | 55 | "metadata": {}, |
56 | 56 | "outputs": [], |
57 | 57 | "source": [ |
58 | | - "#|export\n", |
| 58 | + "#| export\n", |
59 | 59 | "GH_HOST = os.getenv('GH_HOST', \"https://api.github.com\")\n", |
60 | 60 | "_DOC_URL = 'https://docs.github.com/'" |
61 | 61 | ] |
|
73 | 73 | "metadata": {}, |
74 | 74 | "outputs": [], |
75 | 75 | "source": [ |
76 | | - "#|export\n", |
| 76 | + "#| export\n", |
77 | 77 | "def _preview_hdr(preview): return {'Accept': f'application/vnd.github.{preview}-preview+json'} if preview else {}\n", |
78 | 78 | "\n", |
79 | 79 | "def _mk_param(nm, **kwargs): return Parameter(nm, kind=Parameter.POSITIONAL_OR_KEYWORD, **kwargs)\n", |
|
107 | 107 | "metadata": {}, |
108 | 108 | "outputs": [], |
109 | 109 | "source": [ |
110 | | - "#|export\n", |
| 110 | + "#| export\n", |
111 | 111 | "class _GhVerb(_GhObj):\n", |
112 | 112 | " __slots__ = 'path,verb,tag,name,summary,url,route_ps,params,data,preview,client,decode,__doc__'.split(',')\n", |
113 | 113 | " def __init__(self, path, verb, oper, summary, url, params, data, preview, client, kwargs):\n", |
|
149 | 149 | "metadata": {}, |
150 | 150 | "outputs": [], |
151 | 151 | "source": [ |
152 | | - "#|export\n", |
| 152 | + "#| export\n", |
153 | 153 | "class _GhVerbGroup(_GhObj):\n", |
154 | 154 | " def __init__(self, name, verbs):\n", |
155 | 155 | " self.name,self.verbs = name,verbs\n", |
|
164 | 164 | "metadata": {}, |
165 | 165 | "outputs": [], |
166 | 166 | "source": [ |
167 | | - "#|export\n", |
| 167 | + "#| export\n", |
168 | 168 | "_docroot = 'https://docs.github.com/rest/reference/'" |
169 | 169 | ] |
170 | 170 | }, |
|
174 | 174 | "metadata": {}, |
175 | 175 | "outputs": [], |
176 | 176 | "source": [ |
177 | | - "#|export\n", |
| 177 | + "#| export\n", |
178 | 178 | "def print_summary(req:Request):\n", |
179 | 179 | " \"Print `Request.summary` with the token (if any) removed\"\n", |
180 | 180 | " pprint(req.summary('Authorization'))" |
|
193 | 193 | "metadata": {}, |
194 | 194 | "outputs": [], |
195 | 195 | "source": [ |
196 | | - "#|export\n", |
| 196 | + "#| export\n", |
197 | 197 | "class GhApi(_GhObj):\n", |
198 | 198 | " def __init__(self, owner=None, repo=None, token=None, jwt_token=None, debug=None, limit_cb=None, gh_host=None,\n", |
199 | 199 | " authenticate=True, **kwargs):\n", |
|
251 | 251 | "metadata": {}, |
252 | 252 | "outputs": [], |
253 | 253 | "source": [ |
254 | | - "#|hide\n", |
| 254 | + "#| hide\n", |
255 | 255 | "token = os.environ['GITHUB_TOKEN']" |
256 | 256 | ] |
257 | 257 | }, |
|
837 | 837 | "metadata": {}, |
838 | 838 | "outputs": [], |
839 | 839 | "source": [ |
840 | | - "#|hide\n", |
| 840 | + "#| hide\n", |
841 | 841 | "for hook in api.repos.list_webhooks():\n", |
842 | 842 | " api.repos.delete_webhook(hook.id)" |
843 | 843 | ] |
|
934 | 934 | "metadata": {}, |
935 | 935 | "outputs": [], |
936 | 936 | "source": [ |
937 | | - "#|export\n", |
| 937 | + "#| export\n", |
938 | 938 | "def date2gh(dt:datetime)->str:\n", |
939 | 939 | " \"Convert `dt` (which is assumed to be in UTC time zone) to a format suitable for GitHub API operations\"\n", |
940 | 940 | " return f'{dt.replace(microsecond=0).isoformat()}Z'" |
|
975 | 975 | "metadata": {}, |
976 | 976 | "outputs": [], |
977 | 977 | "source": [ |
978 | | - "#|export\n", |
| 978 | + "#| export\n", |
979 | 979 | "def gh2date(dtstr:str)->datetime:\n", |
980 | 980 | " \"Convert date string `dtstr` received from a GitHub API operation to a UTC `datetime`\"\n", |
981 | 981 | " return datetime.fromisoformat(dtstr.replace('Z', ''))" |
|
1054 | 1054 | "metadata": {}, |
1055 | 1055 | "outputs": [], |
1056 | 1056 | "source": [ |
1057 | | - "#|export\n", |
| 1057 | + "#| export\n", |
1058 | 1058 | "img_md_pat = re.compile(r'!\\[(?P<alt>.*?)\\]\\((?P<url>[^\\s]+)\\)')\n", |
1059 | 1059 | "\n", |
1060 | 1060 | "def _run_subp(cmd): \n", |
|
1180 | 1180 | "metadata": {}, |
1181 | 1181 | "outputs": [], |
1182 | 1182 | "source": [ |
1183 | | - "#|export\n", |
| 1183 | + "#| export\n", |
1184 | 1184 | "@patch\n", |
1185 | 1185 | "def delete_release(self:GhApi, release):\n", |
1186 | 1186 | " \"Delete a release and its associated tag\"\n", |
|
1194 | 1194 | "metadata": {}, |
1195 | 1195 | "outputs": [], |
1196 | 1196 | "source": [ |
1197 | | - "#|hide\n", |
| 1197 | + "#| hide\n", |
1198 | 1198 | "for rel in api.repos.list_releases(): api.delete_release(rel)" |
1199 | 1199 | ] |
1200 | 1200 | }, |
|
1204 | 1204 | "metadata": {}, |
1205 | 1205 | "outputs": [], |
1206 | 1206 | "source": [ |
1207 | | - "#|export\n", |
| 1207 | + "#| export\n", |
1208 | 1208 | "@patch\n", |
1209 | 1209 | "def upload_file(self:GhApi, rel, fn):\n", |
1210 | 1210 | " \"Upload `fn` to endpoint for release `rel`\"\n", |
|
1220 | 1220 | "metadata": {}, |
1221 | 1221 | "outputs": [], |
1222 | 1222 | "source": [ |
1223 | | - "#|export\n", |
| 1223 | + "#| export\n", |
1224 | 1224 | "@patch\n", |
1225 | 1225 | "def create_release(self:GhApi, tag_name, branch='master', name=None, body='',\n", |
1226 | 1226 | " draft=False, prerelease=False, files=None):\n", |
|
1329 | 1329 | "metadata": {}, |
1330 | 1330 | "outputs": [], |
1331 | 1331 | "source": [ |
1332 | | - "#|export\n", |
| 1332 | + "#| export\n", |
1333 | 1333 | "@patch\n", |
1334 | 1334 | "def list_tags(self:GhApi, prefix:str=''):\n", |
1335 | 1335 | " \"List all tags, optionally filtered to those starting with `prefix`\"\n", |
|
1374 | 1374 | "metadata": {}, |
1375 | 1375 | "outputs": [], |
1376 | 1376 | "source": [ |
1377 | | - "#|export\n", |
| 1377 | + "#| export\n", |
1378 | 1378 | "@patch\n", |
1379 | 1379 | "def list_branches(self:GhApi, prefix:str=''):\n", |
1380 | 1380 | " \"List all branches, optionally filtered to those starting with `prefix`\"\n", |
|
1420 | 1420 | "metadata": {}, |
1421 | 1421 | "outputs": [], |
1422 | 1422 | "source": [ |
1423 | | - "#|export\n", |
| 1423 | + "#| export\n", |
1424 | 1424 | "# See https://stackoverflow.com/questions/9765453\n", |
1425 | 1425 | "EMPTY_TREE_SHA = '4b825dc642cb6eb9a060e54bf8d69288fbee4904'" |
1426 | 1426 | ] |
|
1446 | 1446 | "metadata": {}, |
1447 | 1447 | "outputs": [], |
1448 | 1448 | "source": [ |
1449 | | - "#|export\n", |
| 1449 | + "#| export\n", |
1450 | 1450 | "@patch\n", |
1451 | 1451 | "def create_branch_empty(self:GhApi, branch):\n", |
1452 | 1452 | " t = self.git.create_tree(base_tree=EMPTY_TREE_SHA, tree = [dict(\n", |
|
1471 | 1471 | "metadata": {}, |
1472 | 1472 | "outputs": [], |
1473 | 1473 | "source": [ |
1474 | | - "#|export\n", |
| 1474 | + "#| export\n", |
1475 | 1475 | "@patch\n", |
1476 | 1476 | "def delete_tag(self:GhApi, tag:str):\n", |
1477 | 1477 | " \"Delete a tag\"\n", |
|
1484 | 1484 | "metadata": {}, |
1485 | 1485 | "outputs": [], |
1486 | 1486 | "source": [ |
1487 | | - "#|export\n", |
| 1487 | + "#| export\n", |
1488 | 1488 | "@patch\n", |
1489 | 1489 | "def delete_branch(self:GhApi, branch:str):\n", |
1490 | 1490 | " \"Delete a branch\"\n", |
|
1507 | 1507 | "metadata": {}, |
1508 | 1508 | "outputs": [], |
1509 | 1509 | "source": [ |
1510 | | - "#|export\n", |
| 1510 | + "#| export\n", |
1511 | 1511 | "@patch\n", |
1512 | 1512 | "def get_branch(self:GhApi, branch=None):\n", |
1513 | 1513 | " branch = branch or self.repos.get().default_branch\n", |
|
1527 | 1527 | "metadata": {}, |
1528 | 1528 | "outputs": [], |
1529 | 1529 | "source": [ |
1530 | | - "#|export\n", |
| 1530 | + "#| export\n", |
1531 | 1531 | "@patch\n", |
1532 | 1532 | "def list_files(self:GhApi, branch=None):\n", |
1533 | 1533 | " ref = self.get_branch(branch)\n", |
|
1577 | 1577 | "metadata": {}, |
1578 | 1578 | "outputs": [], |
1579 | 1579 | "source": [ |
1580 | | - "#|export\n", |
| 1580 | + "#| export\n", |
1581 | 1581 | "@patch\n", |
1582 | 1582 | "def get_content(self:GhApi, path):\n", |
1583 | 1583 | " res = self.repos.get_content(path)\n", |
|
1600 | 1600 | "metadata": {}, |
1601 | 1601 | "outputs": [], |
1602 | 1602 | "source": [ |
1603 | | - "#|export\n", |
| 1603 | + "#| export\n", |
1604 | 1604 | "@patch\n", |
1605 | 1605 | "def create_or_update_file(self:GhApi, path, message, committer, author, content=None, sha=None, branch=''):\n", |
1606 | 1606 | " if not branch: branch = api.repos.get()['default_branch']\n", |
|
1617 | 1617 | "metadata": {}, |
1618 | 1618 | "outputs": [], |
1619 | 1619 | "source": [ |
1620 | | - "#|export\n", |
| 1620 | + "#| export\n", |
1621 | 1621 | "@patch\n", |
1622 | 1622 | "def create_file(self:GhApi, path, message, committer, author, content=None, branch=None):\n", |
1623 | 1623 | " if not branch: branch = api.repos.get()['default_branch']\n", |
|
1646 | 1646 | "metadata": {}, |
1647 | 1647 | "outputs": [], |
1648 | 1648 | "source": [ |
1649 | | - "#|export\n", |
| 1649 | + "#| export\n", |
1650 | 1650 | "@patch\n", |
1651 | 1651 | "def delete_file(self:GhApi, path, message, committer, author, sha=None, branch=None):\n", |
1652 | 1652 | " if not branch: branch = api.repos.get()['default_branch']\n", |
|
1671 | 1671 | "metadata": {}, |
1672 | 1672 | "outputs": [], |
1673 | 1673 | "source": [ |
1674 | | - "#|export\n", |
| 1674 | + "#| export\n", |
1675 | 1675 | "@patch\n", |
1676 | 1676 | "def update_contents(self:GhApi, path, message, committer, author, content, sha=None, branch=None):\n", |
1677 | 1677 | " if not branch: branch = api.repos.get()['default_branch']\n", |
|
1729 | 1729 | "metadata": {}, |
1730 | 1730 | "outputs": [], |
1731 | 1731 | "source": [ |
1732 | | - "#|export\n", |
| 1732 | + "#| export\n", |
1733 | 1733 | "@patch\n", |
1734 | 1734 | "def enable_pages(self:GhApi, branch=None, path=\"/\"):\n", |
1735 | 1735 | " \"Enable or update pages for a repo to point to a `branch` and `path`.\"\n", |
|
1793 | 1793 | "metadata": {}, |
1794 | 1794 | "outputs": [], |
1795 | 1795 | "source": [ |
1796 | | - "#|hide\n", |
| 1796 | + "#| hide\n", |
1797 | 1797 | "import nbdev; nbdev.nbdev_export()" |
1798 | 1798 | ] |
1799 | 1799 | }, |
|
0 commit comments