Blame docs/contribute/contribute.adoc

Packit 517ee8
= How to Contribute to OpenSCAP
Packit 517ee8
Packit 517ee8
This document is meant for new OpenSCAP contributors and it describes how to
Packit 517ee8
contribute to the OpenSCAP project. Let's suppose that you already have an
Packit 517ee8
active Github's account with a user name _adam_ and you want to fix one of the
Packit 517ee8
issue from the link:https://github.com/OpenSCAP/openscap/issues[tracker]. Let's
Packit 517ee8
say that you want to fix the issue with number _455_ and the fix will go into
Packit 517ee8
the `maint-1.2` branch.
Packit 517ee8
Packit 517ee8
NOTE: This guide also applies for adding a new feature, the process is the same
Packit 517ee8
as for fixing an issue described below.
Packit 517ee8
Packit 517ee8
Packit 517ee8
== Fork and setup the OpenSCAP repository
Packit 517ee8
Before you start working on a fix it's a good practice to leave a
Packit 517ee8
comment in the issue that you work on the fix so other contributors know that
Packit 517ee8
the fix is in progress.  Next thing you have to do is to fork the OpenSCAP
Packit 517ee8
repository. You can do that by pressing the *'Fork'* button in the top-right
Packit 517ee8
corner on the Github's link:https://github.com/OpenSCAP/openscap[OpenSCAP page].
Packit 517ee8
It will create a copy of the original repository which you can use for
Packit 517ee8
proposing changes. Then you can clone your forked repository:
Packit 517ee8
[source,bash]
Packit 517ee8
----
Packit 517ee8
$ git clone git@github.com:adam/openscap.git
Packit 517ee8
----
Packit 517ee8
Packit 517ee8
Sometimes you will need to update your forked repository with the latest
Packit 517ee8
upstream changes. To be able to do so you need to add a remote (we will name it
Packit 517ee8
upstream) which will track the upstream OpenSCAP repository:
Packit 517ee8
[source,bash]
Packit 517ee8
----
Packit 517ee8
$ cd openscap/
Packit 517ee8
# add remote name 'upstream' to refer to the upstream's repository
Packit 517ee8
$ git remote add upstream git@github.com:OpenSCAP/openscap.git
Packit 517ee8
----
Packit 517ee8
Packit 517ee8
NOTE: In the code snippets, lines starting with # are comments and lines
Packit 517ee8
starting with $ are commands.
Packit 517ee8
Packit 517ee8
Packit 517ee8
== Choose the right branch
Packit 517ee8
Before you start working on the fix it's necessary to determine which branch the
Packit 517ee8
fix will go into. If you are not familiar with the OpenSCAP's branches or
Packit 517ee8
versions yet please have a look at the link:versioning.adoc[versioning]
Packit 517ee8
document. Be aware that the fact that an issue description says that the fix
Packit 517ee8
should go to the `maint-1.2` branch doesn't have to be true. It's a good practice
Packit 517ee8
to investigate the correct branch first or ask experienced developers on our
Packit 517ee8
FreeNode IRC channel called `#openscap` or
Packit 517ee8
link:https://www.redhat.com/mailman/listinfo/open-scap-list[mailing list].
Packit 517ee8
Packit 517ee8
NOTE: The default branch of the openscap repository is set to the `maint-1.2`.
Packit 517ee8
Packit 517ee8
Once you have forked the repository and decided that the fix will go into the
Packit 517ee8
`maint-1.2` branch you can create a new branch from it, which we will call
Packit 517ee8
_fix_455_, where you can work on the fix. Remember that the name of the new
Packit 517ee8
branch will appear in the commit message when your fix is merged so choose the
Packit 517ee8
name wisely:
Packit 517ee8
Packit 517ee8
[source,bash]
Packit 517ee8
----
Packit 517ee8
$ git checkout maint-1.2
Packit 517ee8
# create a new branch
Packit 517ee8
$ git checkout -b fix_455
Packit 517ee8
----
Packit 517ee8
Packit 517ee8
On the other hand, if you decided that the fix will go into the `master` branch
Packit 517ee8
you have to switch to this branch first before creating a new one:
Packit 517ee8
[source,bash]
Packit 517ee8
----
Packit 517ee8
# create a new local branch to track the remote master branch
Packit 517ee8
$ git checkout -b master remotes/origin/master
Packit 517ee8
# and now create a new branch from the master branch which will contain your fix
Packit 517ee8
$ git checkout -b fix_455
Packit 517ee8
----
Packit 517ee8
Packit 517ee8
Packit 517ee8
== Fix the issue
Packit 517ee8
NOTE: OpenSCAP is licensed under _LGPL v2.1_. Any fixes or improvements must be
Packit 517ee8
licensed under the same license to be included. Check the COPYING file in the
Packit 517ee8
repository for more details.
Packit 517ee8
Packit 517ee8
Now you can work on the fix. Try to create small commits which can be easily
Packit 517ee8
reviewed and make self-explaining commit messages. The
Packit 517ee8
link:http://chris.beams.io/posts/git-commit/[How to Write a Git Commit
Packit 517ee8
Message] article could help you with that. Nobody will review a pull request
Packit 517ee8
which contains a four thousand new lines of code.
Packit 517ee8
Packit 517ee8
NOTE: Since you're fixing issue number 455 make sure that your commit
Packit 517ee8
message contain a
Packit 517ee8
link:https://help.github.com/articles/closing-issues-via-commit-messages/[keyword]
Packit 517ee8
which will close the issue automatically when your pull request is merged.
Packit 517ee8
Packit 517ee8
Let's say that you've fixed the issue, made a few commits to your local fix_455
Packit 517ee8
branch and you think it's ready to be reviewed by other contributors. Before you
Packit 517ee8
push your local changes to your remote forked repository it's necessary to check
Packit 517ee8
if your changes will be applicable and won't be in a conflict with some work that
Packit 517ee8
other contributors could have published while you were working on the fix.
Packit 517ee8
Packit 517ee8
Packit 517ee8
== Optional: Write an automated test for your code
Packit 517ee8
There is a big chance that the code you've fixed or the code that you've added
Packit 517ee8
has no test coverage. We encourage you to write a new test or extend the
Packit 517ee8
existing one to cover the changes/additions to OpenSCAP that you have made.
Packit 517ee8
It is not mandatory, so reviewer will not require you to write a test, but keep
Packit 517ee8
in mind that providing a test might uncover some unexpected issues with the
Packit 517ee8
code. We also run these tests on every pull request so adding a test for your
Packit 517ee8
fix or new feature might prevent someone from breaking it in the future. If you
Packit 517ee8
decided to add a test please see our
Packit 517ee8
link:testing.adoc[guide for writing and running tests].
Packit 517ee8
Packit 517ee8
Packit 517ee8
== Rebase before pull request
Packit 517ee8
If some other contributor pushed some code to the `maint-1.2` branch while you
Packit 517ee8
were working on the fix and if there would be a conflict between your changes
Packit 517ee8
then it might be necessary to fetch those changes and rebase your fix on top
Packit 517ee8
of them. First you need to make sure that your local `maint-1.2` branch is
Packit 517ee8
up-to date:
Packit 517ee8
Packit 517ee8
[source,bash]
Packit 517ee8
----
Packit 517ee8
# checkout to branch 'maint-1.2' in your local forked repository
Packit 517ee8
$ git checkout maint-1.2
Packit 517ee8
# download and apply any upstream changes to your local maint-1.2 branch
Packit 517ee8
$ git pull upstream maint-1.2
Packit 517ee8
# now you can optionally also push these changes to your fork on Github (recommended)
Packit 517ee8
$ git push origin maint-1.2
Packit 517ee8
----
Packit 517ee8
Packit 517ee8
Now you can go back to your local branch with the fix and try to rebase your
Packit 517ee8
changes on top of your local updated `maint-1.2` branch:
Packit 517ee8
Packit 517ee8
[source,bash]
Packit 517ee8
----
Packit 517ee8
# checkout back to your branch with the fix
Packit 517ee8
$ git checkout fix_455
Packit 517ee8
# rebase your changes on the top of the updated maint-1.2 branch
Packit 517ee8
$ git rebase maint-1.2
Packit 517ee8
----
Packit 517ee8
Packit 517ee8
If there are no conflicts then you can push your branch with the fix to your
Packit 517ee8
remote forked repository:
Packit 517ee8
Packit 517ee8
[source,bash]
Packit 517ee8
----
Packit 517ee8
# push your changes to your remote forked repository (also see the note below)
Packit 517ee8
$ git push origin fix_455
Packit 517ee8
----
Packit 517ee8
Packit 517ee8
NOTE: The previous `git push` command will not work if you've already pushed the
Packit 517ee8
branch to your remote repository. If this is the case, but you made some new
Packit 517ee8
changes/updates and you want to push them into the fix_455 branch then append
Packit 517ee8
the `--force` after the `git push` command. Be aware that it will rewrite your
Packit 517ee8
fix_455 branch in your remote forked repository.
Packit 517ee8
Packit 517ee8
Packit 517ee8
== Create a new pull request
Packit 517ee8
Once you have pushed your local fix_455 branch to your remote forked repository
Packit 517ee8
you can link:https://help.github.com/articles/creating-a-pull-request/[create] a
Packit 517ee8
new pull request. You can create the pull request on the OpenSCAP's
Packit 517ee8
link:https://github.com/OpenSCAP/openscap/pulls[github page] when you click on
Packit 517ee8
the *'Pull requests'* in the right menu then you see the green
Packit 517ee8
*'New pull request'* button. In the branch menu choose the branch that contains
Packit 517ee8
your fix. That is the fix_455 branch and also don't forget to set `maint-1.2`
Packit 517ee8
as the base branch. The base branch is the one that your fix_455 will be
Packit 517ee8
compared to. If there are no conflicts add some description and hit the
Packit 517ee8
*'Create pull request'* button.
Packit 517ee8
Packit 517ee8
Developers and contributor that watch the repository should now
Packit 517ee8
receive an email about a new pull request. They will review your code and
Packit 517ee8
probably leave you some comments. If there are any you should get back to your
Packit 517ee8
code and make the changes.
Packit 517ee8
Packit 517ee8
=== Make changes in the submitted pull request
Packit 517ee8
After the review is done and one or more experienced developers is complaining
Packit 517ee8
about your code you have to do some changes. There are two ways to change your
Packit 517ee8
code in a submitted pull request:
Packit 517ee8
Packit 517ee8
 . Add a new commit,
Packit 517ee8
 . or edit existing commits.
Packit 517ee8
Packit 517ee8
==== Add a new commit
Packit 517ee8
Adding a new commit is easy and it is a good option if you have to add something
Packit 517ee8
new like a function or a new module.
Packit 517ee8
Packit 517ee8
==== Edit existing commits
Packit 517ee8
If you just need to fix something (for example a typo) you need to go back to
Packit 517ee8
the commit where the change is needed and use commit's `--amend` option to
Packit 517ee8
change the commit. You can use the following steps to do that:
Packit 517ee8
Packit 517ee8
[source,bash]
Packit 517ee8
----
Packit 517ee8
# show all the commits in your fix_455 branch
Packit 517ee8
$ git rebase -i maint-1.2
Packit 517ee8
# replace 'pick' with 'e' at the line with commit(s) you'd like to edit
Packit 517ee8
# make your changes
Packit 517ee8
# vim my_source_file.c
Packit 517ee8
# commit your new changes
Packit 517ee8
$ git commit --amend
Packit 517ee8
# move to the next commit which you selected for editing using 'e' in the
Packit 517ee8
# 'git rebase' command
Packit 517ee8
$ git rebase --continue
Packit 517ee8
----
Packit 517ee8
Packit 517ee8
When you are finished with editing commits you can force push all the changes
Packit 517ee8
into your remote repository to update it with your latest edits. The pull
Packit 517ee8
request will be updated automatically too:
Packit 517ee8
Packit 517ee8
[source,bash]
Packit 517ee8
----
Packit 517ee8
$ git push --force origin fix_455
Packit 517ee8
----
Packit 517ee8
Packit 517ee8
=== Closing the pull request
Packit 517ee8
Once the pull request has been merged to upstream's branch the pull request will
Packit 517ee8
be closed automatically. The issue will be also closed if you used the right
Packit 517ee8
keyword in the commit message. Now you can delete your `fix_455` branch:
Packit 517ee8
Packit 517ee8
[source,bash]
Packit 517ee8
----
Packit 517ee8
# detele the fix_455 branch locally
Packit 517ee8
$ git branch -d fix_455
Packit 517ee8
# optionally also delete the fix_455 branch from your remote forked repository
Packit 517ee8
$ git push origin --delete fix_455
Packit 517ee8
----