-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[HUP-785] Feature: Created git hooks pre-commit and prepare-commit-ms…
…g and added git commit message templates. -Added gitconfig for make a settings other changes like githooks, commit-message-template. -Added pre-commit hooks for checking branch names like "main, master and production". If branch names are these names not allowed commit. -Added prepare-commit-msg hooks for checking commit message template. If doesn't follow this template that gives an error message. -Also created some classes for unity project start event and added some git configuration for applying to local git configuration for just developer.
- Loading branch information
1 parent
a53c309
commit c3d2a0a
Showing
8 changed files
with
199 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[core] | ||
hooksPath = .github/.githooks | ||
[commit] | ||
template = .github/.gitmessages | ||
[pull] | ||
rebase = true | ||
[alias] | ||
co = checkout # exampöe: git co master | ||
ci = commit # example: git ci -m "commit message" | ||
st = status # example: git st | ||
br = branch # example: git br | ||
hist = log --pretty=format:\"%h %ad | %s%d [%an]\" --graph --date=short # example: git hist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/bin/sh | ||
|
||
branch="$(git rev-parse --abbrev-ref HEAD)" | ||
protected_branches=("main" "master" "production") | ||
|
||
for i in "${protected_branches[@]}" | ||
do | ||
if [ "$branch" = "$i" ]; then | ||
echo "You cannot commit to the $i branch. Please create a new branch and make a Pull Request." | ||
exit 1 | ||
fi | ||
done | ||
|
||
exit 0 | ||
|
||
# Path: .githooks/post-commit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#!/bin/bash | ||
|
||
# Define the valid keywords and prefixes | ||
type_keyword=("Feature" "Fix" "Hotfix" "Docs" "Style" "Refactor" "Perf" "Test" "Chore" "Revert") | ||
|
||
# Get the first line of the commit message | ||
START_LINE=`head -n1 $1` | ||
SIZE=${#START_LINE} | ||
|
||
# Check if the commit message starts with a valid prefix(Jira Key) | ||
if [[ $START_LINE == "[HUP-"*"]"* ]]; then | ||
prefix_found=true | ||
else | ||
prefix_found=false | ||
fi | ||
|
||
# Check if the commit message starts with a valid keyword | ||
for keyword in "${type_keyword[@]}"; do | ||
if [[ $START_LINE == *"$keyword"* ]]; then | ||
keyword_found=true | ||
break | ||
fi | ||
done | ||
|
||
# Validate the commit message | ||
if [[ $prefix_found != true ]]; then | ||
echo "Jira Key must be written in the commit message." | ||
exit 1 | ||
elif [[ $keyword_found != true ]]; then | ||
echo "Commit message must include with one of these keywords: ${type_keyword[@]}" | ||
exit 1 | ||
elif (( $SIZE < 50 )); then | ||
echo "Enter a descriptive commit message. (Min 50 characters)" | ||
exit 1 | ||
fi | ||
|
||
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[<Jira Issue Key>] <Type>: <Short Description> | ||
|
||
<Additional Details if Necessary> | ||
|
||
[Optional] Related Issues: | ||
- <Jira Issue Key>: <Description> | ||
- <Jira Issue Key>: <Description> | ||
|
||
[Optional] Screenshots or Visuals: | ||
- [Description or Link ] | ||
- [Description or Link ] | ||
|
||
[Optional] Notes: | ||
- Any additional information, considerations, or important notes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
using UnityEngine; | ||
|
||
/// <summary> | ||
/// This class is used to configure Git when the Unity project starts. | ||
/// It uses the System.Diagnostics.Process class to run a Git command in a new process. | ||
/// </summary> | ||
public class HMSConfigureGitStandards | ||
{ | ||
// Define Git commands as constants | ||
#region Git Commands | ||
private const string GitCommand = "git"; | ||
private const string GitConfigCommand = "config --local include.path ../.gitconfig"; | ||
private const string GitUnsetConfigCommand = "config --local --unset include.path"; | ||
private const string GitGetConfigCommand = "config --local --get include.path"; | ||
private const string GitVersionCommand = "--version"; | ||
#endregion | ||
|
||
public static void Start() | ||
{ | ||
if (IsGitInstalled()) | ||
{ | ||
if (!IsGitConfigured()) | ||
{ | ||
ConfigureGit(); | ||
} | ||
} | ||
else | ||
{ | ||
Debug.LogWarning("Git is not installed"); | ||
|
||
} | ||
} | ||
private static void ConfigureGit() | ||
{ | ||
Debug.Log("Configuring Git"); | ||
try | ||
{ | ||
RunProcess(GitCommand, GitConfigCommand); | ||
} | ||
catch (System.Exception e) | ||
{ | ||
Debug.Log("Error: " + e.Message); | ||
RunProcess(GitCommand, GitUnsetConfigCommand); | ||
} | ||
finally | ||
{ | ||
Debug.Log("Git Configured"); | ||
} | ||
} | ||
private static int RunProcess(string fileName, string arguments) | ||
{ | ||
var proc = new System.Diagnostics.Process | ||
{ | ||
StartInfo = new System.Diagnostics.ProcessStartInfo | ||
{ | ||
FileName = fileName, | ||
Arguments = arguments, | ||
CreateNoWindow = true, | ||
WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden, | ||
UseShellExecute = false, | ||
RedirectStandardOutput = true | ||
} | ||
}; | ||
|
||
proc.Start(); | ||
proc.WaitForExit(); | ||
|
||
return proc.ExitCode; | ||
} | ||
private static bool IsGitInstalled() | ||
{ | ||
return RunProcess(GitCommand, GitVersionCommand) == 0; | ||
} | ||
private static bool IsGitConfigured() | ||
{ | ||
return RunProcess(GitCommand, GitGetConfigCommand) == 0; | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using UnityEditor; | ||
using UnityEngine; | ||
|
||
|
||
[InitializeOnLoad] | ||
public class HMSUnityProjectStart | ||
{ | ||
static HMSUnityProjectStart() | ||
{ | ||
EditorApplication.update += RunOnce; | ||
} | ||
|
||
static void RunOnce() | ||
{ | ||
HMSConfigureGitStandards.Start(); | ||
|
||
EditorApplication.update -= RunOnce; | ||
} | ||
|
||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.