Skip to content

Commit bf748f4

Browse files
committed
community/create_pr_quick_start.rst: update, improve. Assisted-by: Gemini
1 parent ec23cbc commit bf748f4

File tree

1 file changed

+81
-79
lines changed

1 file changed

+81
-79
lines changed
Lines changed: 81 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
11
.. _collection_quickstart:
22

3-
********************************************
3+
*******************************************
44
Creating your first collection pull request
5-
********************************************
5+
*******************************************
66

7-
This section describes all the steps needed to create your first patch and submit a pull request on a collection.
7+
This guide describes how to create a patch and submit a pull request for an Ansible collection.
88

99
.. _collection_prepare_local:
1010

1111
Prepare your environment
1212
========================
1313

14-
.. note::
15-
16-
These steps assume a Linux work environment with ``git`` installed.
17-
14+
These steps assume a Linux work environment with ``git`` installed.
1815

19-
1. Install and start ``docker`` or ``podman``. This ensures tests run properly isolated and in the same environment as in CI.
16+
1. Install ``podman``. Running tests in a container ensures proper isolation and a consistent environment.
2017

21-
2. :ref:`Install Ansible or ansible-core <installation_guide>`. You need the ``ansible-test`` utility which is provided by either of these packages.
18+
2. :ref:`Install ansible-core <installation_guide>`. You need the ``ansible-test`` utility, which this package provides.
2219

2320
3. Create the following directories in your home directory:
2421

@@ -36,45 +33,43 @@ Prepare your environment
3633
3734
4. Fork the collection repository through the GitHub web interface.
3835

39-
5. Clone the forked repository from your profile to the created path:
36+
5. Clone the forked repository from your profile to the path you created:
4037

4138
.. code-block:: bash
4239
4340
$ git clone https://github.com/YOURACC/COLLECTION_REPO.git ~/ansible_collections/NAMESPACE/COLLECTION_NAME
4441
45-
If you prefer to use the SSH protocol:
42+
Alternatively, use the SSH protocol:
4643

4744
.. code-block:: bash
4845
4946
$ git clone git@github.com:YOURACC/COLLECTION_REPO.git ~/ansible_collections/NAMESPACE/COLLECTION_NAME
5047
51-
6. Go to your new cloned repository.
48+
6. Navigate to the repository you cloned:
5249

5350
.. code-block:: bash
5451
5552
$ cd ~/ansible_collections/NAMESPACE/COLLECTION_NAME
5653
57-
7. Ensure you are in the default branch (it is usually ``main``):
54+
7. Verify that you are on the default branch, typically ``main``:
5855

5956
.. code-block:: bash
6057
6158
$ git status
6259
63-
8. Show remotes. There should be the ``origin`` repository only:
60+
8. Display the remotes. You should see only the ``origin`` repository:
6461

6562
.. code-block:: bash
6663
6764
$ git remote -v
6865
69-
9. Add the ``upstream`` repository:
66+
9. Add the ``upstream`` repository. This is the repository from which you forked:
7067

7168
.. code-block:: bash
7269
7370
$ git remote add upstream https://github.com/ansible-collections/COLLECTION_REPO.git
7471
75-
This is the repository where you forked from.
76-
77-
10. Update your local default branch. Assuming that it is ``main``:
72+
10. Update your local default branch. If your default branch is ``main``, run:
7873

7974
.. code-block:: bash
8075
@@ -90,81 +85,93 @@ Prepare your environment
9085
Change the code
9186
===============
9287

93-
.. note::
88+
Do not combine multiple unrelated bug fixes or features in a single pull request. Instead, use separate pull requests for different changes.
9489

95-
Do NOT mix several bug fixes or features that are not tightly related in one pull request. Use separate pull requests for different changes.
90+
Start by writing integration and unit tests, if applicable. These tests can verify that a bug exists before you apply your code fix and confirm that your code fixed the bug once the tests pass.
9691

97-
You should start with writing integration and unit tests if applicable. These can verify the bug exists (prior to your code fix) and verify your code fixed that bug once the tests pass.
92+
Add integration tests
93+
---------------------
9894

9995
.. note::
10096

101-
If there are any difficulties with writing or running the tests or you are not sure if the case can be covered, you can skip this step. Other contributors can help you with tests later if needed.
97+
* Some collections do not have integration tests. In such cases, unit tests are highly recommended.
98+
* If you have difficulty writing or running tests, or you are unsure if a case can be covered, skip this step. Other contributors can help you with tests later if needed.
10299

103-
.. note::
100+
All integration tests reside in ``tests/integration/targets`` subdirectories.
104101

105-
Some collections do not have integration tests. In this case, unit tests are required.
102+
Navigate to the subdirectory that contains the name of the module you plan to change.
103+
For example, if you are fixing the ``mysql_user`` module in the ``community.mysql`` collection, its tests are in ``tests/integration/targets/test_mysql_user/tasks``.
106104

107-
All integration tests are stored in ``tests/integration/targets`` subdirectories.
108-
Go to the subdirectory containing the name of the module you are going to change.
109-
For example, if you are fixing the ``mysql_user`` module in the ``community.mysql`` collection,
110-
its tests are in ``tests/integration/targets/test_mysql_user/tasks``.
105+
The ``main.yml`` file contains test tasks and includes other test files.
106+
Look for a suitable existing test file to integrate your tests, or create and include a dedicated test file.
107+
You can use an existing test file as a template.
111108

112-
The ``main.yml`` file holds test tasks and includes other test files.
113-
Look for a suitable test file to integrate your tests or create and include a dedicated test file.
114-
You can use one of the existing test files as a draft.
115-
116-
When fixing a bug, write a task that reproduces the bug from the issue.
117-
118-
Put the reported case in the tests, then run integration tests with the following command:
109+
When you fix a bug, write a task that reproduces the bug from the reported issue.
110+
Then run integration tests by using the following command:
119111

120112
.. code-block:: bash
121113
122-
$ ansible-test integration name_of_test_subdirectory --docker -v
114+
$ ansible-test integration TEST_TARGET_DIRECTORY_NAME --docker -v
123115
124-
For example, if the test files you changed are stored in ``tests/integration/targets/test_mysql_user/``, the command is as follows:
116+
For example, if you want to run tasks residing in ``tests/integration/targets/test_mysql_user/``, the command is:
125117

126118
.. code-block:: bash
127119
128120
$ ansible-test integration test_mysql_user --docker -v
129121
130-
You can use the ``-vv`` or ``-vvv`` argument if you need more detailed output.
122+
You can use the ``-vv`` or ``-vvv`` argument for more detailed output.
131123

132-
In the examples above, the default test image is automatically downloaded and used to create and run a test container.
133-
Use the default test image for platform-independent integration tests such as those for cloud modules.
124+
The examples above automatically download and use the default test image to create and run a test container.
125+
Use the default test image for platform-independent integration tests.
134126

135-
If you need to run the tests against a specific distribution, see the :ref:`list of supported container images <test_container_images>`. For example:
127+
If you need to run tests against a specific distribution, see the :ref:`list of supported container images <test_container_images>`. For example:
136128

137129
.. code-block:: bash
138130
139-
$ ansible-test integration name_of_test_subdirectory --docker fedora35 -v
131+
$ ansible-test integration TEST_TARGET_DIRECTORY_NAME --docker fedora40 -v
132+
133+
If you are unsure whether to use the default image or a specific image for testing, skip this step. The community can assist you later. You can also inspect the collection repository's CI to determine which containers it uses.
134+
135+
If the tests run successfully, two outcomes are possible:
136+
137+
* If the bug has not appeared and the tests passed, ask the reporter for more details. The issue might not be a bug, or it might relate to a specific software version or the reporter's local environment configuration.
138+
* The bug appeared, and the tests failed as expected, showing the reported symptoms.
139+
140+
Add unit tests
141+
--------------
140142

141143
.. note::
142144

143-
If you are not sure whether you should use the default image for testing or a specific one, skip the entire step - the community can help you later. You can also try to use the collection repository's CI to figure out which containers are used.
145+
* Some collections do not have unit tests. In such cases, focus on integration tests.
146+
* If you have difficulty writing or running tests, or you are unsure if a case can be covered, skip this step. Other contributors can help you with tests later if needed.
147+
148+
We recommend that you cover all changes with unit tests.
144149

145-
If the tests run successfully, there are usually two possible outcomes:
150+
* **Location**: All unit tests are located in the ``tests/unit/`` directory.
151+
* **Adding Tests**:
146152

147-
- If the bug has not appeared and the tests have passed successfully, ask the reporter to provide more details. It may not be a bug or can relate to a particular software version used or specifics of the reporter's local environment configuration.
148-
- The bug has appeared and the tests have failed as expected showing the reported symptoms.
153+
* Find an existing test file that corresponds to the code you are modifying.
154+
* If a relevant file doesn't exist, create a new one.
155+
* Use ``Pytest`` as testing framework.
149156

150-
Fix the bug
151-
=============
157+
See the :ref:`test_your_changes` section for detailed instructions on how to run the unit tests.
152158

153-
See :ref:`module_contribution` for some general guidelines about Ansible module development that may help you craft a good code fix for the bug.
159+
.. _test_your_changes:
154160

155161
Test your changes
156162
=================
157163

158-
1. Install ``flake8`` (``pip install flake8``, or install the corresponding package on your operating system).
164+
To test your changes, complete the following steps:
165+
166+
1. Install ``flake8``.
159167

160168
2. Run ``flake8`` against a changed file:
161169

162170
.. code-block:: bash
163171
164172
$ flake8 path/to/changed_file.py
165173
166-
167-
This shows unused imports, which are not shown by sanity tests, as well as other common issues.
174+
This command identifies unused imports, which sanity tests do not show, and other common issues.
168175
Optionally, you can use the ``--max-line-length=160`` command-line argument.
169176

170177
3. Run sanity tests:
@@ -173,40 +180,39 @@ Test your changes
173180
174181
$ ansible-test sanity path/to/changed_file.py --docker -v
175182
176-
If they failed, look at the output carefully - it is informative and helps to identify a problem line quickly.
177-
Sanity failings usually relate to incorrect code and documentation formatting.
183+
If the tests fail, carefully examine the output; it provides informative details that help you quickly identify the problem line.
184+
Sanity failures typically relate to incorrect code and documentation formatting.
178185

179186
4. Run integration tests:
180187

181188
.. code-block:: bash
182189
183-
$ ansible-test integration name_of_test_subdirectory --docker -v
190+
$ ansible-test integration TEST_TARGET_DIRECTORY_NAME --docker -v
184191
185-
For example, if the test files you changed are stored in ``tests/integration/targets/test_mysql_user/``, the command is:
192+
For example, if your changed test files are in ``tests/integration/targets/test_mysql_user/``, the command is:
186193

187194
.. code-block:: bash
188195
189196
$ ansible-test integration test_mysql_user --docker -v
190197
191198
You can use the ``-vv`` or ``-vvv`` argument if you need more detailed output.
192199

200+
Two possible outcomes are:
193201

194-
There are two possible outcomes:
195-
196-
- They have failed. Look at the output of the command. Fix the problem in the code and run again. Repeat the cycle until the tests pass.
197-
- They have passed. Remember they failed originally? Our congratulations! You have fixed the bug.
202+
* The tests failed. Examine the command's output. Fix the problem in the code and run the tests again. Repeat this cycle until the tests pass.
203+
* The tests passed. If they originally failed, you have successfully fixed the bug.
198204

199-
In addition to the integration tests, you can also cover your changes with unit tests. This is often required when integration tests are not applicable to the collection.
205+
5. In addition to integration tests, you can also cover your changes with unit tests. This is often necessary when integration tests do not apply to the collection.
200206

201207
We use `pytest <https://docs.pytest.org/en/latest/>`_ as a testing framework.
202208

203-
Files with unit tests are stored in the ``tests/unit/plugins/`` directory. If you want to run unit tests, say, for ``tests/unit/plugins/test_myclass.py``, the command is:
209+
Unit test files are in the ``tests/unit/plugins/`` directory. To run unit tests, for example, for ``tests/unit/plugins/test_myclass.py``, use the following command:
204210

205211
.. code-block:: bash
206212
207213
$ ansible-test units tests/unit/plugins/test_myclass.py --docker
208214
209-
If you want to run all unit tests available in the collection, run:
215+
To run all available unit tests in the collection, run:
210216

211217
.. code-block:: bash
212218
@@ -215,7 +221,9 @@ If you want to run all unit tests available in the collection, run:
215221
Submit a pull request
216222
=====================
217223

218-
1. Commit your changes with an informative but short commit message:
224+
To submit a pull request, complete the following steps:
225+
226+
1. Commit your changes with a concise and informative commit message:
219227

220228
.. code-block:: bash
221229
@@ -232,19 +240,15 @@ Submit a pull request
232240

233241
4. Click the :guilabel:`Pull requests` tab.
234242

235-
GitHub is tracking your fork, so it should see the new branch in it and automatically offer to create a pull request. Sometimes GitHub does not do it, and you should click the :guilabel:`New pull request` button yourself. Then choose :guilabel:`compare across forks` under the :guilabel:`Compare changes` title.
243+
GitHub tracks your fork and should automatically offer to create a pull request for your new branch. If GitHub does not do this, click the :guilabel:`New pull request` button yourself. Then, under the :guilabel:`Compare changes` title, choose :guilabel:`compare across forks`.
236244

237245
5. Choose your repository and the new branch you pushed in the right drop-down list. Confirm.
238246

239-
a. Fill out the pull request template with all the information you want to mention.
240-
241-
b. Put ``Fixes + link to the issue`` in the pull request's description.
242-
243-
c. Put ``[WIP] + short description`` in the pull request's title. Mention the name of the module/plugin you are modifying at the beginning of the description.
247+
a. Complete the pull request template with all relevant information.
248+
b. Add ``Fixes + link to the issue`` in the pull request's description.
249+
c. Click :guilabel:`Create pull request`.
244250

245-
d. Click :guilabel:`Create pull request`.
246-
247-
6. Add a :ref:`changelog fragment <collection_changelog_fragments>` to the ``changelogs/fragments`` directory. It will be published in release notes, so users will know about the fix.
251+
6. Add a :ref:`changelog fragment <collection_changelog_fragments>` to the ``changelogs/fragments`` directory. This fragment will be published in the release notes, informing users about the fix.
248252

249253
a. Run the sanity test for the fragment:
250254

@@ -261,12 +265,10 @@ Submit a pull request
261265
$ git commit -m "Add changelog fragment"
262266
$ git push origin name_of_my_branch
263267
264-
7. Verify the CI tests that run automatically on Red Hat infrastructure are successful after every commit.
265-
266-
You will see the CI status at the bottom of your pull request. If they are green and you think that you do not want to add more commits before someone should take a closer look at it, remove ``[WIP]`` from the title. Mention the issue reporter in a comment and let contributors know that the pull request is "Ready for review".
268+
7. Verify that the CI tests, which run automatically on Red Hat infrastructure, are successful.
267269

268-
8. Wait for reviews. You can also ask for a review in the ``#ansible-community`` :ref:`Matrix/Libera.Chat IRC channel <communication_irc>`.
270+
You will see the CI status at the bottom of your pull request. If the tests are green and you do not plan to add more commits, add a "Ready for review" comment.
269271

270-
9. If the pull request looks good to the community, committers will merge it.
272+
8. If the pull request looks good to the community, committers will merge it. You can mention them explicitly.
271273

272-
For more in-depth details on this process, see the :ref:`Ansible developer guide <developer_guide>`.
274+
For more detailed information on this process, see the :ref:`Ansible developer guide <developer_guide>`.

0 commit comments

Comments
 (0)