|
| 1 | +# Contributing to netunicorn-library |
| 2 | + |
| 3 | +Adapted from the IETF-tools/.github repository. |
| 4 | + |
| 5 | +#### Table Of Contents |
| 6 | + |
| 7 | +- [Rules](#rules) |
| 8 | + - [Python](#python) |
| 9 | + - [Git Commit Messages StyleGuide](#git-commit-messages-styleguide) |
| 10 | +- [Workflow Overview](#contributing-workflow-overview) |
| 11 | +- [Creating a Fork](#creating-a-fork) |
| 12 | +- [Cloning a Fork](#cloning-a-fork) |
| 13 | +- [Create a Local Branch](#create-a-local-branch) |
| 14 | +- [Create and Push Commits](#create-and-push-commits) |
| 15 | +- [Create a Pull Request](#create-a-pull-request) |
| 16 | +- [Sync your Fork](#sync-your-fork) |
| 17 | + |
| 18 | +## Rules |
| 19 | + |
| 20 | +### Python |
| 21 | + |
| 22 | +* Use folders `tasks` and `pipelines` for tasks and pipelines respectively. Choose (or create) a folder that best describes your task or pipeline. |
| 23 | +* Don't re-format or modify code you're not working on (even to fit your preferred style). |
| 24 | +* Adhere to PEP 8, the Style Guide for Python Code. Preferrably use Black style formatter to format your code. |
| 25 | +* Do not modify `pyproject.toml` file in the repository. This would be modified by the lead developer when a new release is to be made. |
| 26 | + |
| 27 | +### Git Commit Messages Styleguide |
| 28 | + |
| 29 | +* Use the present tense ("Add task" not "Added tasks") |
| 30 | +* Use the imperative mood ("Implement measurement..." not "Implements measurements for...") |
| 31 | +* Limit the first line *(title)* to 72 characters or less |
| 32 | +* Reference issues and pull requests liberally after the first line |
| 33 | + |
| 34 | + |
| 35 | + |
| 36 | + |
| 37 | +## Contributing Workflow Overview |
| 38 | + |
| 39 | +This project uses the **Git Feature Workflow** model. |
| 40 | + |
| 41 | +It consists of a **main** branch which reflects the latest development state. New tasks and pipelines are added to this branch, until the version of the package in pyproject.toml is increased. At this point, the new release of netunicorn-library would be created and pushed to the PyPI repository. |
| 42 | + |
| 43 | +A typical development workflow: |
| 44 | + |
| 45 | +1. First, [create a fork](#creating-a-fork) of the repository and then [clone the fork](#cloning-a-fork) to your local machine. |
| 46 | +2. [Create a new branch](#create-a-local-branch), based on the main branch, for the feature / task you are to work on. |
| 47 | +3. [Add one or more commits and push them](#create-and-push-commits) to this branch. |
| 48 | +4. [Create a pull request (PR)](#create-a-pull-request) to request your feature branch from your fork to be merged to the source repository `main` branch. |
| 49 | +5. The PR is reviewed by the lead developer / other developers and the PR is merged with the `main` branch. |
| 50 | +6. [Fast-forward (sync)](#sync-your-fork) your forked main branch to include the latest changes made by all developers. |
| 51 | +7. Repeat this workflow from step 2. |
| 52 | + |
| 53 | + |
| 54 | + |
| 55 | +## Creating a Fork |
| 56 | + |
| 57 | +As a general rule, work is never done directly on the project repository. You instead [create a fork](https://docs.github.com/en/get-started/quickstart/fork-a-repo) of the project. Creating a "fork" is producing a personal copy of the project. Forks act as a sort of bridge between the original repository and your personal copy. |
| 58 | + |
| 59 | +1. Navigate to https://github.com/netunicorn/netunicorn-library |
| 60 | +2. Click the **Fork** button. *You may be prompted to select where the fork should be created, in which case you should select your personal GitHub account.* |
| 61 | + |
| 62 | + |
| 63 | + |
| 64 | +Your personal fork contains all the branches / contents of the original repository as it was at the exact moment you created the fork. You are free to create new branches or modify existing ones on your personal fork, as it won't affect the original repository. |
| 65 | + |
| 66 | +Note that forks live on GitHub and not locally on your personal machine. To get a copy locally, we need to clone the fork... |
| 67 | + |
| 68 | +## Cloning a Fork |
| 69 | + |
| 70 | +Right now, you have a fork of the project repository, but you don't have the files in that repository locally on your computer. |
| 71 | + |
| 72 | +After forking the project repository, you should have landed on your personal forked copy. If that's not the case, make sure you are on the fork (e.g. `john-doe/netunicorn-library` and not the original repository `netunicorn/netunicorn-library`). |
| 73 | + |
| 74 | +Above the list of files, click the **Code** button. A clone dialog will appear. |
| 75 | + |
| 76 | + |
| 77 | + |
| 78 | +1. Copy the URL in the **Clone with SSL** dialog. |
| 79 | +2. In a terminal window, navigate to where you want to work. Subfolders will be created for each project you clone. **DO NOT** create empty folders for projects to be cloned. This is done automatically by git. |
| 80 | +3. Type `git clone` and then paste the URL you just copied, e.g.: |
| 81 | +```sh |
| 82 | +git clone [email protected]:YOUR-USERNAME/netunicorn-library.git |
| 83 | +``` |
| 84 | +4. Press **Enter**. Your local clone will be created in a subfolder named after the project. |
| 85 | + |
| 86 | +## Create a Local Branch |
| 87 | + |
| 88 | +While you could *technically* work directly on the main branch, it is best practice to create a branch for the tasks you are working on. It also makes it much easier to fast-forward your forks main branch to the match the source repository. |
| 89 | + |
| 90 | +1. From a terminal window, nagivate to the project directory you cloned earlier. |
| 91 | +2. First, make sure you are on the `main` branch.: |
| 92 | +```sh |
| 93 | +git checkout main |
| 94 | +``` |
| 95 | +3. Let's create a branch named `my-tasks` based on the `main` branch: |
| 96 | +```sh |
| 97 | +git checkout -b my-tasks |
| 98 | +``` |
| 99 | +4. Press **Enter**. A new branch will be created, being an exact copy of the main branch. |
| 100 | + |
| 101 | +You are now ready to work on your features or tasks in your favorite editor. |
| 102 | + |
| 103 | +## Create and Push Commits |
| 104 | + |
| 105 | +While implementing your features or tasks, you will create one or more commits. A commit is a snapshot of your code at a specific point in time. It's a good practice to create small commits that are focused on a single task. This makes it easier to review and revert changes if necessary. |
| 106 | + |
| 107 | +Push these commits to the remote branch (in our case, `my-tasks`) on your forked repository. |
| 108 | +```sh |
| 109 | +git push origin my-tasks |
| 110 | +``` |
| 111 | + |
| 112 | +## Create a Pull Request |
| 113 | + |
| 114 | +When your branch with tasks is ready to be merged with the source repository `main` branch, it's time to create a **Pull Request (PR)**. |
| 115 | + |
| 116 | +On GitHub, navigate to your branch (in your forked repository). A yellow banner will invite you to **Compare & pull request**. You can also click the **Contribute** dropdown to initiate a PR. |
| 117 | + |
| 118 | + |
| 119 | + |
| 120 | +Make sure the base repository is set to `netunicorn/netunicorn-library` with the branch `main` (this is the destination). |
| 121 | + |
| 122 | +Enter a title and description of what your PR includes and click **Create pull request** when ready. |
| 123 | + |
| 124 | +Your PR will then be reviewed by the lead developer / other developers. |
| 125 | + |
| 126 | +Once approved and merged, your changes will appear in the `main` branch. It's now time to fast-forward your fork to the source repository. This ensures your fork main branch is in sync with the source main branch... |
| 127 | + |
| 128 | +## Sync your Fork |
| 129 | + |
| 130 | +Your fork `main` branch is now behind the source `main` branch. To fast-forward it to the latest changes, click the **Fetch upstream** button: |
| 131 | + |
| 132 | + |
| 133 | + |
| 134 | +Note that you also need to fast-forward your **local machine** `main` branch. This can again be done quickly from your editor / GUI tool. If you're using the command line, run these commands: |
| 135 | + |
| 136 | +```sh |
| 137 | +git checkout main |
| 138 | +git pull |
| 139 | +``` |
0 commit comments