|
28 | 28 | "from fastcore.utils import *\n", |
29 | 29 | "from fastcore.foundation import *\n", |
30 | 30 | "from fastcore.meta import *\n", |
| 31 | + "from ghapi.metadata import funcs\n", |
31 | 32 | "\n", |
32 | 33 | "import inspect,json,copy,urllib,mimetypes,base64\n", |
33 | 34 | "from inspect import signature,Parameter,Signature\n", |
34 | 35 | "from urllib.parse import urlencode\n", |
35 | | - "from ghapi.metadata import funcs\n", |
36 | 36 | "from urllib.request import Request,urlretrieve\n", |
37 | 37 | "from urllib.error import HTTPError\n", |
| 38 | + "from datetime import datetime,timedelta\n", |
38 | 39 | "from pprint import pprint" |
39 | 40 | ] |
40 | 41 | }, |
|
447 | 448 | "- [users](https://docs.github.com/en/free-pro-team@latest/rest/reference/users)" |
448 | 449 | ], |
449 | 450 | "text/plain": [ |
450 | | - "<__main__.GhApi at 0x7f496e622e10>" |
| 451 | + "<__main__.GhApi at 0x7ff9b02eb190>" |
451 | 452 | ] |
452 | 453 | }, |
453 | 454 | "execution_count": null, |
|
597 | 598 | "- [git.get_tree](https://docs.github.com/rest/reference/git#get-a-tree)(tree_sha, recursive): *Get a tree*" |
598 | 599 | ], |
599 | 600 | "text/plain": [ |
600 | | - "<__main__._GhVerbGroup at 0x7f496e3f2690>" |
| 601 | + "<__main__._GhVerbGroup at 0x7ff9b01b8d90>" |
601 | 602 | ] |
602 | 603 | }, |
603 | 604 | "execution_count": null, |
|
904 | 905 | "for page in repos: print(len(page), page[0].name)" |
905 | 906 | ] |
906 | 907 | }, |
| 908 | + { |
| 909 | + "cell_type": "markdown", |
| 910 | + "metadata": {}, |
| 911 | + "source": [ |
| 912 | + "### Convenience functions" |
| 913 | + ] |
| 914 | + }, |
| 915 | + { |
| 916 | + "cell_type": "code", |
| 917 | + "execution_count": null, |
| 918 | + "metadata": {}, |
| 919 | + "outputs": [], |
| 920 | + "source": [ |
| 921 | + "#exports\n", |
| 922 | + "def gh_date(dt:datetime):\n", |
| 923 | + " \"Convert `dt` (which is assumed to be in UTC time zone) to a format suitable for GitHub API operations\"\n", |
| 924 | + " return f'{dt.replace(microsecond=0).isoformat()}Z'" |
| 925 | + ] |
| 926 | + }, |
| 927 | + { |
| 928 | + "cell_type": "markdown", |
| 929 | + "metadata": {}, |
| 930 | + "source": [ |
| 931 | + "The GitHub API assumes that dates will be in a specific string format. `gh_date` converts Python standard `datetime` objects to that format. For instance, to find issues opened in the last week:" |
| 932 | + ] |
| 933 | + }, |
| 934 | + { |
| 935 | + "cell_type": "code", |
| 936 | + "execution_count": null, |
| 937 | + "metadata": {}, |
| 938 | + "outputs": [ |
| 939 | + { |
| 940 | + "data": { |
| 941 | + "text/plain": [ |
| 942 | + "1" |
| 943 | + ] |
| 944 | + }, |
| 945 | + "execution_count": null, |
| 946 | + "metadata": {}, |
| 947 | + "output_type": "execute_result" |
| 948 | + } |
| 949 | + ], |
| 950 | + "source": [ |
| 951 | + "dt = gh_date(datetime.utcnow() - timedelta(weeks=1))\n", |
| 952 | + "issues = api.issues.list_for_repo(since=dt)\n", |
| 953 | + "len(issues)" |
| 954 | + ] |
| 955 | + }, |
907 | 956 | { |
908 | 957 | "cell_type": "markdown", |
909 | 958 | "metadata": {}, |
|
0 commit comments