|
5 | 5 | A good issue includes a [short, self contained, correct example](http://sscce.org/) of the problem, something like: |
6 | 6 |
|
7 | 7 | ```python |
8 | | -assert github.Github().get_user("jacquev6").name == "Vincent Jacques" |
| 8 | +from github import Github |
| 9 | +from github import Auth |
| 10 | + |
| 11 | +g = Github(auth=Auth.Token("****")) |
| 12 | +assert g.get_user("jacquev6").name == "Vincent Jacques" |
9 | 13 | ``` |
10 | 14 |
|
11 | 15 | It is even better if you provide the debug logs associated with your issue. |
12 | 16 | Enable them with `github.enable_console_debug_logging` and copy them in the body of the issue. |
13 | | -**Warning:** you may want to remove some private information (authentication information is removed, but there may be private stuff in the messages) |
| 17 | +**Warning:** you may want to remove private information from the log. |
14 | 18 |
|
15 | | -If for any reason you are not able to do that, open your issue anyway and a maintainer will see what is needed to solve your problem. |
| 19 | +If for any reason you are not able to do that, open your issue anyway and a maintainer or community member may be able to help. |
16 | 20 |
|
17 | 21 | ## Pull Requests |
18 | 22 |
|
19 | | -Pull Requests should clearly describe two things: |
| 23 | +Pull Requests should contain the following things: |
20 | 24 |
|
21 | | -1. The problem they attempt to solve |
22 | | -2. How the author went about solving the problem |
| 25 | +1. Describe the problem the Pull Request attempts to solve |
| 26 | +2. Explain how the you went about solving the problem |
| 27 | +3. Provide a test that exemplifies the expected behaviour |
23 | 28 |
|
24 | 29 | Ideally, changes should be made in logical commits and tests added to improve the project's coverage of the GitHub API. |
25 | 30 |
|
26 | | -## Coding style |
27 | | - |
28 | | -PyGithub adopts the black coding style. |
29 | | - |
30 | | -To manually format the code: |
31 | | -```bash |
32 | | -tox -e lint |
33 | | -``` |
34 | | - |
35 | | -## Pre-commit plugin |
36 | | - |
37 | | -To forget about coding style and let [pre-commit](https://pre-commit.com/#installation) fix your flake8/isort/black issue. |
38 | | - |
39 | | -``` |
40 | | -pre-commit install |
41 | | -``` |
42 | | - |
43 | | -That's it! |
44 | | - |
45 | | -## Adding missing attributes for a GithubObject |
46 | | - |
47 | | -```bash |
48 | | -$ python scripts/add_attribute.py [class_name] [attribute_name] [attribute_type] |
49 | | - |
50 | | -# For example, if you want to add a `url` attribute of string type to the Commit class |
51 | | -# Note: adding multiple attributes you have to run the script multiple times |
52 | | - |
53 | | -$ python scripts/add_attribute.py Commit url string |
54 | | -``` |
55 | | - |
56 | | -## Deprecation warning |
57 | | - |
58 | | -Before removing attributes/methods, consider adding deprecation warnings instead. The [typing_extensions](https://pypi.org/project/typing-extensions/) package provides a handy decorator to add deprecation warnings. |
59 | | - |
60 | | -```python |
61 | | -from typing_extensions import deprecated |
62 | | - |
63 | | -@property |
64 | | -@deprecated("Use core instead") |
65 | | -def rate(self): |
66 | | - pass |
67 | | - |
68 | | -@deprecated("Deprecated in favor of the new branch protection") |
69 | | -def get_protected_branch(self): |
70 | | - pass |
71 | | -``` |
72 | | - |
73 | | -## Automated tests |
74 | | - |
75 | | -First you need to install the test dependencies: |
76 | | -```bash |
77 | | -pip install -r requirements/test.txt |
78 | | -``` |
79 | | - |
80 | | -Then you can run the tests through `pytest`. |
81 | | -Run a specific test with `pytest tests/tests_filename.py` or `pytest tests/tests_filename.py -k testMethod` or `pytest -k TestClass.testMethod`. |
| 31 | +## Development |
82 | 32 |
|
83 | | -If you add or modify a test, for example `Repository.testCompare`, you have to run `pytest -k Repository.testCompare --record` to create or update the `tests/ReplayData/*.txt` files needed for your new test. |
84 | | -Check them in to git and commit them as well. |
85 | | - |
86 | | -You will need a `GithubCredentials.py` file at the root of the project with the following contents: |
87 | | - |
88 | | -```python |
89 | | -oauth_token = "my_token" |
90 | | -jwt = "my_json_web_token" # Can be left empty if not used |
91 | | -app_id = "my_app_id" # Can be left empty if not used |
92 | | -app_private_key = "my_app_private_key" # Can be left empty if not used |
93 | | -``` |
94 | | - |
95 | | -The `oauth_token` field in `GithubCredentials.py` is used by default to record test data. |
96 | | -Tests that require JWT (`jwt` field) or App authentication (`app_id` and `app_private_key` field) |
97 | | -have to enable `"jwt"` or `"app"` auth mode in their `setUp` method: |
98 | | - |
99 | | -```python |
100 | | -def setUp(self): |
101 | | - self.authMode = "jwt" |
102 | | - super().setUp() |
103 | | - ... |
104 | | -``` |
105 | | - |
106 | | -A test method that needs a different authentication than configured in `setUp` can simply |
107 | | -create a new `Github` object with the respective authentication: |
108 | | - |
109 | | -```python |
110 | | -def testGetUserWithOAuth(self): |
111 | | - # this test needs OAuth authentication |
112 | | - g = self.get_github("oauth_token") |
113 | | - self.assertEqual(g.get_user("jacquev6").name, "Vincent Jacques") |
114 | | - |
115 | | -def testGetUserWithJwt(self): |
116 | | - # this test needs JWT authentication |
117 | | - g = self.get_github("jwt") |
118 | | - self.assertEqual(g.get_user("jacquev6").name, "Vincent Jacques") |
119 | | - |
120 | | -def testGetUserWithAppAuth(self): |
121 | | - # this test needs App authentication |
122 | | - g = self.get_github("app") |
123 | | - self.assertEqual(g.get_user("jacquev6").name, "App name") |
124 | | -``` |
125 | | - |
126 | | -To run manual tests with external scripts that use the PyGithub package, you can install your development version with: |
127 | | - |
128 | | -```bash |
129 | | -pip install --editable path/to/project |
130 | | -``` |
131 | | - |
132 | | -You may also want to investigate `tox` to run tests: |
133 | | - |
134 | | -```bash |
135 | | -pip install tox |
136 | | -tox -epy310 |
137 | | -``` |
138 | | - |
139 | | -## Build documentation locally |
140 | | - |
141 | | -```bash |
142 | | -pip install -r requirements/docs.txt |
143 | | -sphinx-build doc build |
144 | | -``` |
145 | | - |
146 | | -If you use tox: |
147 | | - |
148 | | -```bash |
149 | | -tox -edocs |
150 | | -``` |
| 33 | +See our [Development guide](https://pygithub.readthedocs.io/en/stable/development.html) for details. |
0 commit comments