[DO-0] Initial commit
This commit is contained in:
56
README.md
56
README.md
@@ -1,3 +1,55 @@
|
||||
# template-default-repository
|
||||
# Проверка именования фича-бранчей и оформления Commit Message
|
||||
Внедрение в репозиторий Git Pre-Commit check в качестве скрипта, который будет проверять на валидацию оформления
|
||||
коммитов в основную ветку репозитория
|
||||
- Проверка названия фича-бранчей
|
||||
- Проверка коммит сообщения
|
||||
|
||||
Template with default configuration for Avroid GIT project
|
||||
Проверка осуществляется через добавление настройке администрирования репозитория Settings > GitHooks > Pre-Commit
|
||||
bash-скрипта. Пример скрипта, настроенного на данном репозитории: check_commits.sh
|
||||
|
||||
Протестировать работу можно на этом репозитории
|
||||
|
||||
## Branch name check
|
||||
Коммитить напрямую в master/main ветку запрещено, все изменения проводятся через PR из feature-branch в master/main ветку
|
||||
|
||||
|
||||
### Допустимые названия веток
|
||||
|
||||
В проектах мы выделяем следующие типы веток:
|
||||
```commandline
|
||||
master/main # мастер ветка, может быть любое другое название. Определяется в конфигурации репозитория
|
||||
release # ветки релизов
|
||||
rc # ветки релиз-кандидатов
|
||||
smoke # ветки смоков
|
||||
feature # ветки, в которых ведется разработка фичей или изменение хеша сабмодулей, обычно именуются с именем Eva тикета и описанием
|
||||
hotfix/bugfix # срочные исправления. могут не иметь Eva тикета в названии
|
||||
```
|
||||
Основные требования к именованию:
|
||||
- Для разделения блоков имен используется нижнее подчеркивание "_"
|
||||
- Все ветки в своем названии должны содержать номер тикера из Eva / код проекта
|
||||
- Все ветки должны иметь краткое описание, к чему относится эта ветка / версию
|
||||
- В зависимости от типа ветки, к основному названию может добавляться приставка или суффикс
|
||||
|
||||
## PR name check
|
||||
PR-ветки создаются автоматически при создании PR в Gitea.
|
||||
|
||||
- EvaID в имени PR должно совпадать с именем EvaID из feature-ветки
|
||||
- Если PR находится в состоянии "Work in progress", то ставится префикс "WIP: ". В Gitea есть функция помечать PR в WIP.
|
||||
|
||||
```commandline
|
||||
Feature-branch name example: T-UST-6499_Use_Keychain
|
||||
PR name example: [T-UST-6499] Use Keychain
|
||||
```
|
||||
|
||||
|
||||
## Commit message check
|
||||
- В начале сообщении коммита в обязательном порядке должен быть указан номер EvaID тикета в квадратных скобках
|
||||
- После скобок пишется краткое содержание коммита
|
||||
- Валидация сообщений коммитов на наличие EvaID проходит на стороне Git сервера. При отсутствии EvaID - коммиты, PR реджектятся.
|
||||
|
||||
```
|
||||
Example Git commit message:
|
||||
[T-UST-1234] My very useful commit message
|
||||
| |
|
||||
EvaID ticket Commit message
|
||||
```
|
||||
112
check_commits.sh
Normal file
112
check_commits.sh
Normal file
@@ -0,0 +1,112 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Error message for BRANCH POLICY
|
||||
error_msg_branch=$(cat <<-END
|
||||
|
||||
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||
@ @
|
||||
@ !!! Push not allowed by BRANCH NAME policy !!! @
|
||||
@ @
|
||||
@ You branch should be named with these templates: @
|
||||
@ - master @
|
||||
@ - main @
|
||||
@ - feature/EVA_ID-000--* @
|
||||
@ - bugfix/* @
|
||||
@ - hotfix/* @
|
||||
@ @
|
||||
@ Example: feature/DO-167--add_new_functionality @
|
||||
@ @
|
||||
@ Wiki: https://eva.avroid.tech/project/Document/DOC-000518 @
|
||||
@ @
|
||||
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||
|
||||
END
|
||||
)
|
||||
|
||||
error_msg_commit=$(cat <<-END
|
||||
|
||||
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||
@ @
|
||||
@ !!! Your Commit does not have a referance to Eva ticket !!! @
|
||||
@ @
|
||||
@ Please correct your Git messages, and push again. @
|
||||
@ Example: "[DO-1234] This is a correct Eva reference" @
|
||||
@ @
|
||||
@ Wiki: https://eva.avroid.tech/project/Document/DOC-000518 @
|
||||
@ @
|
||||
@ To FORCE push, use "bugfix" or "hotfix" in your commit message @
|
||||
@ @
|
||||
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
|
||||
|
||||
END
|
||||
)
|
||||
|
||||
while read oldrev newrev refname
|
||||
do
|
||||
#
|
||||
# Step 1:
|
||||
# Get Git commit information
|
||||
#
|
||||
BRANCH_NAME_FULL=$refname
|
||||
BRANCH_NAME="$(echo $BRANCH_NAME_FULL | sed 's/refs\/heads\///g')"
|
||||
COMMIT_MESSAGE=$(git log --format=%B -n 1)
|
||||
echo "[INFO] BRANCH NAME: $BRANCH_NAME"
|
||||
|
||||
|
||||
#
|
||||
# Step 2:
|
||||
# Policy - Check that brunch name is enforced by branch name
|
||||
#
|
||||
echo "[INFO] Policy - Check that brunch name is enforced by branch name"
|
||||
# Regexp for allowed names of branches
|
||||
branch_name_format='^master|^main|^feature\/[a-zA-Z0-9,\.\_\-]+-[0-9]+.*|^hotfix\/.*|^bugfix\/.*'
|
||||
|
||||
if [[ ! $BRANCH_NAME =~ $branch_name_format ]]; then
|
||||
echo "$error_msg_branch" >&2
|
||||
exit 1
|
||||
else
|
||||
echo "Push is successful"
|
||||
fi
|
||||
|
||||
|
||||
#
|
||||
# Step 3:
|
||||
# Policy - Check commit message for Eva issue number
|
||||
#
|
||||
|
||||
# Configuration
|
||||
echo "[INFO] Policy - Check commit message for Eva issue number"
|
||||
issueIdRegex="[a-zA-Z0-9,\.\_\-]+-[0-9]+"
|
||||
fixMsgRegex="bugfix|hotfix"
|
||||
info_msg="[INFO] The commit message looks good"
|
||||
error_msg="[POLICY] The commit doesn't reference a Eva issue"
|
||||
|
||||
# Get all commits from this push
|
||||
for sha1Commit in $(git rev-list $oldrev..$newrev);
|
||||
do
|
||||
# Receive git commits sha from git history in chronologic order
|
||||
echo "[INFO] Processing commit with sha: $sha1Commit";
|
||||
# Get commit message from commit
|
||||
commitMessage=$(git log --format=%B -n 1 $sha1Commit)
|
||||
# Check with RegEX if commit has Eva reference
|
||||
issueIds=$(echo $commitMessage | grep -Eo $issueIdRegex)
|
||||
fixMsg=$(echo $commitMessage | grep -Eo $fixMsgRegex)
|
||||
# Check if this commit urgent e.g. hotfox or bugfix
|
||||
if [[ -n "${fixMsg}" ]]; then
|
||||
echo "[WARNING] Found "bugfix|hotfix" in msg. Force skipping check for EvaID"
|
||||
exit 0
|
||||
fi
|
||||
# Check for issueIDs in commit message
|
||||
echo "[INFO] Found Eva IDs in commit: $issueIds"
|
||||
if [[ -z "${issueIds}" ]]; then
|
||||
echo "$error_msg: $commitMessage" >&2
|
||||
echo "$error_msg_commit" >&2
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
done
|
||||
|
||||
#
|
||||
# Exit
|
||||
#
|
||||
exit 0
|
||||
Reference in New Issue
Block a user