~aleteoryx/muditaos

30c70d53cf3c4480a5577025eb7e012bc8d589c9 — Wojtek Cichoń 5 years ago 6ce0dc4
[EGD-4658] Change 'dev workflow' article (#1130)

Changed 'Development workflow' article regarding how to
write commit messages and introduced a template for commit messages.
4 files changed, 106 insertions(+), 11 deletions(-)

A .gitmessage
A config/prepare-commit-msg
M doc/development_workflow.md
M doc/quickstart.md
A .gitmessage => .gitmessage +18 -0
@@ 0,0 1,18 @@
# Commit subject: [JIRA-TICKET] <Add/Change/Fix> changes summary, don't end with a period
# No more than 72 chars. ########################### 72 chars is here: #
<Title>
# Remember blank line between title and commit message.

# Commit message: Explain *what* and *why* (not *how*).
# Wrap at 72 chars. ################################### which is here: #

# How to Write a Git Commit Message:
# https://chris.beams.io/posts/git-commit/
#
# 1. Separate subject from message with a blank line
# 2. Limit the subject line to 72 characters
# 3. Capitalize the subject line
# 4. Do not end the subject line with a period
# 5. Use the imperative mood in the subject line
# 6. Wrap the commit message body at 72 characters
# 7. Use the commit message to explain what and why vs. how

A config/prepare-commit-msg => config/prepare-commit-msg +32 -0
@@ 0,0 1,32 @@
#!/bin/bash
#source: https://medium.com/better-programming/how-to-automatically-add-the-ticket-number-in-git-commit-message-bda5426ded05

FILE=$1
MESSAGE=$(cat $FILE)
BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD)
TITLE_TAG="<Title>"

BRANCH_REGEXP="^(\w+/)?(\w+[-_])?([0-9]+)[-_](.*)$"
if [[ ${BRANCH_NAME} =~ ${BRANCH_REGEXP} ]]; then
    TICKET="[${BASH_REMATCH[2]}${BASH_REMATCH[3]}]"
    MESSAGE_TEXT="${BASH_REMATCH[4]//[-_]/ }"

    if [[ ${MESSAGE} == "${TICKET}"* ]]; then
        exit 0
    fi

    NEW_TITLE="${TICKET} ${MESSAGE_TEXT}"

    echo "FILE:$FILE"
    echo "TITLE_TAG:$TITLE_TAG"
    FROM_TEMPLATE=$(cat ${FILE} | grep "${TITLE_TAG}")
    echo "FROM_TEMPLATE: '${FROM_TEMPLATE}'"
    if [[ -n $( cat $FILE | grep "${TITLE_TAG}" ) ]]; then
        sed  -i "s:${TITLE_TAG}:${NEW_TITLE}:" $FILE
    else 
        echo -e "$TICKET $MESSAGE_TEXT \n $MESSAGE" > $FILE
    fi
else
    echo "$MESSAGE" > $FILE
fi


M doc/development_workflow.md => doc/development_workflow.md +18 -11
@@ 2,32 2,35 @@

When submitting code or documentation changes please follow these steps to have bigger chances of getting your piece of work merged into the master branch.

## Create a new branch
## Create a new branch or fork

Create a branch, which name is connected to the feature, bug fix, or documentation change you want to contribute e.g. `feature/some-feature` or `fix/some-fix`.
Create a branch or fork, which name is connected to the feature, bug fix, or documentation change you want to contribute e.g. `feature/some-feature` or `fix/some-fix`.

**Note:** If you're part of the MuditaOS core development team, please precede the branch name with a relevant Jira ticket number e.g. `EGD-5555-some-feature`.

## Commit changes

Commit your work. Each commit that makes it from your branch or fork into the master branch must have a title and a clear description.
Each commit that makes it from your branch or fork into the master branch must have a title and a clear description.

If you're part of the MuditaOS core development team, your commit's title *must* start with a Jira ticket number in square brackets. It can also point to which component you are working on, e.g., `[EGD-5555] phonebook: fix contact details`. A list of components is not yet defined, so please follow the names that are already in use. Do not add commits that are out of the scope of the Jira issue you are working on.
If you're part of the MuditaOS core development team, your commit's title *must* start with a Jira ticket number in square brackets e.g. `[EGD-5555]`. 

Start your commit's description with a single sentence describing what you are changing using present simple tense and an infinitive form. It must start with one of the following verbs: "Add", "Change" or "Fix", depending on whether you are adding a new feature, changing its
behavior, or fixing it. This sentence will be a part of the project changelog, so please ensure it will be clear to the non-technical
readers. Do not use proper names such as names of classes or functions. 
Commits from the community will be accompanied by a relevant Jira ticket number during the merge. Don't add commits that are out of the scope of the Jira issue you are working on.

Then, in the next paragraph, you must include a short description of what commit is changing in the project. You should be clear about
Your commit's subject line should be a single sentence describing what you are changing using present simple tense and an imperative mood. Please follow these rules:

- It must start with one of the following verbs: "Add", "Change" or "Fix", depending on whether you are adding a new feature, changing its behavior, or fixing it. This sentence will be a part of the project changelog, so please ensure it will be clear to the non-technical readers. 
- Don't use proper names such as names of classes or functions. 
- Try to be as concise as possible in the limit of 72 characters (including the Jira ticket number - 11 characters). 
- Don't end the subject line with a period. 

Then, in the commit message, you must include a short description of what the commit is changing in the project. You should be clear about
your motivation to do the change and how it influences the project.

If it's impossible to provide any of the above information, then your commit is likely excessive or redundant and should be squashed with another commit.

An example of a correctly formatted commit:
```
    [EGD-4544] doc: update requirements for commits
    
    Change the requirements for commits' description.
    [EGD-4544] Change requirements for commits
    
    In order to be able to remove the obligation to change the project
    changelog with every PR, provide requirements for commits' title and


@@ 38,6 41,10 @@ An example of a correctly formatted commit:

Here's [a helpful article about writing good Git commit messages](https://chris.beams.io/posts/git-commit/).

You can add a commit template and hook that will help with proper defining both branch name and a message title:

- [commit message template](./doc/quickstart.md#commit-message-template)
- [commit message hook](./doc/quickstart.md#commit-message-hook)

## Basic checks before Pull Request


M doc/quickstart.md => doc/quickstart.md +38 -0
@@ 114,6 114,44 @@ git commit
To fix the style for Pull Request CI:
`./config/pre-commit.hook --branch-fix`

## Commit message template

To add commit message template use this command:

```bash
git config commit.template .gitmessage
```

This way each time you add new commit you will see template that will help
you with proper message format. More about that in (Development Workflow)[./doc/development_workflow.md#commit-changes]

## Commit message hook
This hooks automatically converts your branch name to commit title

rules:
if branch starts with EGD-xxxx it is treated as jira ticket
all `-` and `_` are converted to spaces

### adding a hook:
```bash
cd .git/hooks
ln -s ../../config/prepare-commit-msg
```
### using hook:

Create a branch

```bash
git checkout origin/master -b EGD-1234-Add_change_description
```

Do your changes, and prepare commit

```bash
git commit
```


## Longstart

Run the provisioning script `./config/bootstrap.sh` to install all dependencies. The script is written for Ubuntu and tested on 20.04.