Debian Codegraph @

docs/contribute/contribute.adoc

raw
1 = How to Contribute to OpenSCAP
2
3 This document is meant for new OpenSCAP contributors and it describes how to
4 contribute to the OpenSCAP project. Let's suppose that you already have an
5 active Github's account with a user name _adam_ and you want to fix one of the
6 issue from the link:https://github.com/OpenSCAP/openscap/issues[tracker]. Let's
7 say that you want to fix the issue with number _455_ and the fix will go into
8 the `maint-1.2` branch.
9
10 NOTE: This guide also applies for adding a new feature, the process is the same
11 as for fixing an issue described below.
12
13
14 == Code style
15
16 OpenSCAP project is following link:https://www.kernel.org/doc/html/v4.10/process/coding-style.html[Linux kernel coding style]
17 for newly-written code and preserves formatting of the existing codebase between major releases.
18
19
20 == Fork and setup the OpenSCAP repository
21 Before you start working on a fix it's a good practice to leave a
22 comment in the issue that you work on the fix so other contributors know that
23 the fix is in progress. Next thing you have to do is to fork the OpenSCAP
24 repository. You can do that by pressing the *'Fork'* button in the top-right
25 corner on the Github's link:https://github.com/OpenSCAP/openscap[OpenSCAP page].
26 It will create a copy of the original repository which you can use for
27 proposing changes. Then you can clone your forked repository:
28 [source,bash]
29 ----
30 $ git clone [email protected]:adam/openscap.git
31 ----
32
33 Sometimes you will need to update your forked repository with the latest
34 upstream changes. To be able to do so you need to add a remote (we will name it
35 upstream) which will track the upstream OpenSCAP repository:
36 [source,bash]
37 ----
38 $ cd openscap/
39 # add remote name 'upstream' to refer to the upstream's repository
40 $ git remote add upstream [email protected]:OpenSCAP/openscap.git
41 ----
42
43 NOTE: In the code snippets, lines starting with # are comments and lines
44 starting with $ are commands.
45
46
47 == Choose the right branch
48 Before you start working on the fix it's necessary to determine which branch the
49 fix will go into. If you are not familiar with the OpenSCAP's branches or
50 versions yet please have a look at the link:versioning.adoc[versioning]
51 document. Be aware that the fact that an issue description says that the fix
52 should go to the `maint-1.2` branch doesn't have to be true. It's a good practice
53 to investigate the correct branch first or ask experienced developers on our
54 FreeNode IRC channel called `#openscap` or
55 link:https://www.redhat.com/mailman/listinfo/open-scap-list[mailing list].
56
57 NOTE: The default branch of the openscap repository is set to the `main`.
58
59 Once you have forked the repository and decided that the fix will go into the
60 `maint-1.2` branch you can create a new branch from it, which we will call
61 _fix_455_, where you can work on the fix. Remember that the name of the new
62 branch will appear in the commit message when your fix is merged so choose the
63 name wisely:
64
65 [source,bash]
66 ----
67 $ git checkout maint-1.2
68 # create a new branch
69 $ git checkout -b fix_455
70 ----
71
72 On the other hand, if you decided that the fix will go into the `main` branch
73 you have to switch to this branch first before creating a new one:
74 [source,bash]
75 ----
76 # create a new local branch to track the remote main branch
77 $ git checkout -b main remotes/origin/main
78 # and now create a new branch from the main branch which will contain your fix
79 $ git checkout -b fix_455
80 ----
81
82
83 == Fix the issue
84 NOTE: OpenSCAP is licensed under _LGPL v2.1_. Any fixes or improvements must be
85 licensed under the same license to be included. Check the COPYING file in the
86 repository for more details.
87
88 Now you can work on the fix. Try to create small commits which can be easily
89 reviewed and make self-explaining commit messages. The
90 link:http://chris.beams.io/posts/git-commit/[How to Write a Git Commit
91 Message] article could help you with that. Nobody will review a pull request
92 which contains a four thousand new lines of code.
93
94 NOTE: Since you're fixing issue number 455 make sure that your commit
95 message contain a
96 link:https://help.github.com/articles/closing-issues-via-commit-messages/[keyword]
97 which will close the issue automatically when your pull request is merged.
98
99 Let's say that you've fixed the issue, made a few commits to your local fix_455
100 branch and you think it's ready to be reviewed by other contributors. Before you
101 push your local changes to your remote forked repository it's necessary to check
102 if your changes will be applicable and won't be in a conflict with some work that
103 other contributors could have published while you were working on the fix.
104
105
106 == Optional: Write an automated test for your code
107 There is a big chance that the code you've fixed or the code that you've added
108 has no test coverage. We encourage you to write a new test or extend the
109 existing one to cover the changes/additions to OpenSCAP that you have made.
110 It is not mandatory, so reviewer will not require you to write a test, but keep
111 in mind that providing a test might uncover some unexpected issues with the
112 code. We also run these tests on every pull request so adding a test for your
113 fix or new feature might prevent someone from breaking it in the future. If you
114 decided to add a test please see our
115 link:testing.adoc[guide for writing and running tests].
116
117
118 == Rebase before pull request
119 If some other contributor pushed some code to the `maint-1.2` branch while you
120 were working on the fix and if there would be a conflict between your changes
121 then it might be necessary to fetch those changes and rebase your fix on top
122 of them. First you need to make sure that your local `maint-1.2` branch is
123 up-to date:
124
125 [source,bash]
126 ----
127 # checkout to branch 'maint-1.2' in your local forked repository
128 $ git checkout maint-1.2
129 # download and apply any upstream changes to your local maint-1.2 branch
130 $ git pull upstream maint-1.2
131 # now you can optionally also push these changes to your fork on Github (recommended)
132 $ git push origin maint-1.2
133 ----
134
135 Now you can go back to your local branch with the fix and try to rebase your
136 changes on top of your local updated `maint-1.2` branch:
137
138 [source,bash]
139 ----
140 # checkout back to your branch with the fix
141 $ git checkout fix_455
142 # rebase your changes on the top of the updated maint-1.2 branch
143 $ git rebase maint-1.2
144 ----
145
146 If there are no conflicts then you can push your branch with the fix to your
147 remote forked repository:
148
149 [source,bash]
150 ----
151 # push your changes to your remote forked repository (also see the note below)
152 $ git push origin fix_455
153 ----
154
155 NOTE: The previous `git push` command will not work if you've already pushed the
156 branch to your remote repository. If this is the case, but you made some new
157 changes/updates and you want to push them into the fix_455 branch then append
158 the `--force` after the `git push` command. Be aware that it will rewrite your
159 fix_455 branch in your remote forked repository.
160
161
162 == Create a new pull request
163 Once you have pushed your local fix_455 branch to your remote forked repository
164 you can link:https://help.github.com/articles/creating-a-pull-request/[create] a
165 new pull request. You can create the pull request on the OpenSCAP's
166 link:https://github.com/OpenSCAP/openscap/pulls[github page] when you click on
167 the *'Pull requests'* in the right menu then you see the green
168 *'New pull request'* button. In the branch menu choose the branch that contains
169 your fix. That is the fix_455 branch and also don't forget to set `maint-1.2`
170 as the base branch. The base branch is the one that your fix_455 will be
171 compared to. If there are no conflicts add some description and hit the
172 *'Create pull request'* button.
173
174 Developers and contributor that watch the repository should now
175 receive an email about a new pull request. They will review your code and
176 probably leave you some comments. If there are any you should get back to your
177 code and make the changes.
178
179 === Make changes in the submitted pull request
180 After the review is done and one or more experienced developers is complaining
181 about your code you have to do some changes. There are two ways to change your
182 code in a submitted pull request:
183
184 . Add a new commit,
185 . or edit existing commits.
186
187 ==== Add a new commit
188 Adding a new commit is easy and it is a good option if you have to add something
189 new like a function or a new module.
190
191 ==== Edit existing commits
192 If you just need to fix something (for example a typo) you need to go back to
193 the commit where the change is needed and use commit's `--amend` option to
194 change the commit. You can use the following steps to do that:
195
196 [source,bash]
197 ----
198 # show all the commits in your fix_455 branch
199 $ git rebase -i maint-1.2
200 # replace 'pick' with 'e' at the line with commit(s) you'd like to edit
201 # make your changes
202 # vim my_source_file.c
203 # commit your new changes
204 $ git commit --amend
205 # move to the next commit which you selected for editing using 'e' in the
206 # 'git rebase' command
207 $ git rebase --continue
208 ----
209
210 When you are finished with editing commits you can force push all the changes
211 into your remote repository to update it with your latest edits. The pull
212 request will be updated automatically too:
213
214 [source,bash]
215 ----
216 $ git push --force origin fix_455
217 ----
218
219 === Closing the pull request
220 Once the pull request has been merged to upstream's branch the pull request will
221 be closed automatically. The issue will be also closed if you used the right
222 keyword in the commit message. Now you can delete your `fix_455` branch:
223
224 [source,bash]
225 ----
226 # detele the fix_455 branch locally
227 $ git branch -d fix_455
228 # optionally also delete the fix_455 branch from your remote forked repository
229 $ git push origin --delete fix_455
230 ----