|
| 1 | +# Contributing |
| 2 | + |
| 3 | +## Where to start |
| 4 | + |
| 5 | +Contributions, bug reports, bug fixes, documentation improvements, enhancements, and ideas are |
| 6 | +welcome. |
| 7 | + |
| 8 | +The best place to start is to check the [issues](https://github.com/sanders41/python-project-generator/issues) |
| 9 | +for something that interests you. |
| 10 | + |
| 11 | +## Bug Reports |
| 12 | + |
| 13 | +Please include: |
| 14 | + |
| 15 | +1. A short, self-contained snippet reproducing the problem. You can format the code by using |
| 16 | +[GitHub markdown](https://docs.github.com/en/free-pro-team@latest/github/writing-on-github). For |
| 17 | +example: |
| 18 | + |
| 19 | + ```sh |
| 20 | + python-project create |
| 21 | + ``` |
| 22 | + |
| 23 | +2. Explain what is currently happening and what you expect instead. |
| 24 | + |
| 25 | +## Working on the code |
| 26 | + |
| 27 | +### Fork the project |
| 28 | + |
| 29 | +In order to work on the project you will need your own fork. To do this click the "Fork" button on |
| 30 | +this project. |
| 31 | + |
| 32 | +Once the project is forked clone it to your local machine: |
| 33 | + |
| 34 | +```sh |
| 35 | +git clone [email protected]:your-user-name/python-project-generator |
| 36 | +cd python-project-generator |
| 37 | +git remote add upstream [email protected]:sanders41/python-project-generator |
| 38 | +``` |
| 39 | + |
| 40 | +This creates the directory python-project-generator and connects your repository to the upstream (main project) |
| 41 | +repository. |
| 42 | + |
| 43 | +### Creating a branch |
| 44 | + |
| 45 | +You want your main branch to reflect only production-ready code, so create a feature branch for |
| 46 | +making your changes. For example: |
| 47 | + |
| 48 | +```sh |
| 49 | +git checkout -b my-new-feature |
| 50 | +``` |
| 51 | + |
| 52 | +This changes your working directory to the my-new-feature branch. Keep any changes in this branch |
| 53 | +specific to one bug or feature so the purpose is clear. You can have many my-new-features and switch |
| 54 | +in between them using the git checkout command. |
| 55 | + |
| 56 | +When creating this branch, make sure your main branch is up to date with the latest upstream |
| 57 | +main version. To update your local main branch, you can do: |
| 58 | + |
| 59 | +```sh |
| 60 | +git checkout main |
| 61 | +git pull upstream main --ff-only |
| 62 | +``` |
| 63 | + |
| 64 | +### Code linting, formatting, and tests |
| 65 | + |
| 66 | +You can run linting on your code at any time with: |
| 67 | + |
| 68 | +```sh |
| 69 | +cargo clippy --all-targets |
| 70 | +``` |
| 71 | + |
| 72 | +To format the code run: |
| 73 | + |
| 74 | +```sh |
| 75 | +cargo fmt |
| 76 | +``` |
| 77 | + |
| 78 | +To run the tests: |
| 79 | + |
| 80 | +```sh |
| 81 | +cargo test |
| 82 | +``` |
| 83 | + |
| 84 | +To ensure the code compiles run: |
| 85 | + |
| 86 | +```sh |
| 87 | +cargo check --all-targets |
| 88 | +``` |
| 89 | + |
| 90 | +Be sure to run all these checks before submitting your pull request. |
| 91 | + |
| 92 | +## Committing your code |
| 93 | + |
| 94 | +Once you have made changes to the code on your branch you can see which files have changed by running: |
| 95 | + |
| 96 | +```sh |
| 97 | +git status |
| 98 | +``` |
| 99 | + |
| 100 | +If new files were created that and are not tracked by git they can be added by running: |
| 101 | + |
| 102 | +```sh |
| 103 | +git add . |
| 104 | +``` |
| 105 | + |
| 106 | +Now you can commit your changes in your local repository: |
| 107 | + |
| 108 | +```sh |
| 109 | +git commit -am 'Some short helpful message to describe your changes' |
| 110 | +``` |
| 111 | + |
| 112 | +## Push your changes |
| 113 | + |
| 114 | +Once your changes are ready and all linting/tests are passing you can push your changes to your |
| 115 | +forked repository: |
| 116 | + |
| 117 | +```sh |
| 118 | +git push origin my-new-feature |
| 119 | +``` |
| 120 | + |
| 121 | +origin is the default name of your remote repository on GitHub. You can see all of your remote |
| 122 | +repositories by running: |
| 123 | + |
| 124 | +```sh |
| 125 | +git remote -v |
| 126 | +``` |
| 127 | + |
| 128 | +## Making a Pull Request |
| 129 | + |
| 130 | +After pushing your code to origin it is now on GitHub but not yet part of the python-project-generator project. |
| 131 | +When you’re ready to ask for a code review, file a pull request. Before you do, once again make sure |
| 132 | +that you have followed all the guidelines outlined in this document regarding code style, tests, and |
| 133 | +documentation. You should also double check your branch changes against the branch it was based on by: |
| 134 | + |
| 135 | +1. Navigating to your repository on GitHub |
| 136 | +1. Click on Branches |
| 137 | +1. Click on the Compare button for your feature branch |
| 138 | +1. Select the base and compare branches, if necessary. This will be main and my-new-feature, respectively. |
| 139 | + |
| 140 | +### Make the pull request |
| 141 | + |
| 142 | +If everything looks good, you are ready to make a pull request. This is how you let the maintainers |
| 143 | +of the python-project-generator project know you have code ready to be reviewed. To submit the pull request: |
| 144 | + |
| 145 | +1. Navigate to your repository on GitHub |
| 146 | +1. Click on the Pull Request button for your feature branch |
| 147 | +1. You can then click on Commits and Files Changed to make sure everything looks okay one last time |
| 148 | +1. Write a description of your changes in the Conversation tab |
| 149 | +1. Click Send Pull Request |
| 150 | + |
| 151 | +This request then goes to the repository maintainers, and they will review the code. |
| 152 | + |
| 153 | +### Updating your pull request |
| 154 | + |
| 155 | +Changes to your code may be needed based on the review of your pull request. If this is the case you |
| 156 | +can make them in your branch, add a new commit to that branch, push it to GitHub, and the pull |
| 157 | +request will be automatically updated. Pushing them to GitHub again is done by: |
| 158 | + |
| 159 | +```sh |
| 160 | +git push origin my-new-feature |
| 161 | +``` |
| 162 | + |
| 163 | +This will automatically update your pull request with the latest code and restart the Continuous |
| 164 | +Integration tests. |
| 165 | + |
| 166 | +Another reason you might need to update your pull request is to solve conflicts with changes that |
| 167 | +have been merged into the main branch since you opened your pull request. |
| 168 | + |
| 169 | +To do this, you need to rebase your branch: |
| 170 | + |
| 171 | +```sh |
| 172 | +git checkout my-new-feature |
| 173 | +git fetch upstream |
| 174 | +git rebase upstream/main |
| 175 | +``` |
| 176 | + |
| 177 | +There may be some merge conficts that need to be resolved. After the feature branch has been update |
| 178 | +locally, you can now update your pull request by pushing to the branch on GitHub: |
| 179 | + |
| 180 | +```sh |
| 181 | +git push origin my-new-feature |
| 182 | +``` |
| 183 | + |
| 184 | +If you rebased and get an error when pushing your changes you can resolve it with: |
| 185 | + |
| 186 | +```sh |
| 187 | +git push origin my-new-feature --force |
| 188 | +``` |
| 189 | + |
| 190 | +## Delete your merged branch (optional) |
| 191 | + |
| 192 | +Once your feature branch is accepted into upstream, you’ll probably want to get rid of the branch. |
| 193 | +First, merge upstream main into your main branch so git knows it is safe to delete your branch: |
| 194 | + |
| 195 | +```sh |
| 196 | +git fetch upstream |
| 197 | +git checkout main |
| 198 | +git merge upstream/main |
| 199 | +``` |
| 200 | + |
| 201 | +Then you can do: |
| 202 | + |
| 203 | +```sh |
| 204 | +git branch -d my-new-feature |
| 205 | +``` |
| 206 | + |
| 207 | +Make sure you use a lower-case -d, or else git won’t warn you if your feature branch has not |
| 208 | +actually been merged. |
| 209 | + |
| 210 | +The branch will still exist on GitHub, so to delete it there do: |
| 211 | + |
| 212 | +```sh |
| 213 | +git push origin --delete my-new-feature |
| 214 | +``` |
0 commit comments