Skip to content

Commit 6a99539

Browse files
authored
Merge pull request #1 from autoframe/dev1
Release 1.0.0 Http git hook call for action for fetch pull checkout commit push
2 parents 0763c3c + 4c2cbfe commit 6a99539

File tree

8 files changed

+1020
-2
lines changed

8 files changed

+1020
-2
lines changed

.github/workflows/phpunit.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# https://help.github.com/en/categories/automating-your-workflow-with-github-actions
2+
3+
on:
4+
pull_request:
5+
push:
6+
7+
name: "PHPUnit-tests"
8+
9+
permissions:
10+
contents: "read"
11+
12+
jobs:
13+
phpunit:
14+
name: "Tests php ${{ matrix.php-version }}"
15+
16+
runs-on: "${{ matrix.operating-system }}"
17+
18+
strategy:
19+
fail-fast: false
20+
matrix:
21+
php-version:
22+
- "7.4"
23+
- "8.0"
24+
- "8.1"
25+
- "8.2"
26+
operating-system:
27+
- "ubuntu-latest"
28+
29+
steps:
30+
- name: "Checkout"
31+
uses: "actions/checkout@v4"
32+
33+
- name: "Install PHP"
34+
uses: "shivammathur/setup-php@v2"
35+
with:
36+
coverage: "none"
37+
php-version: "${{ matrix.php-version }}"
38+
# extensions: curl, mbstring, zip
39+
# ini-values: memory_limit=-1
40+
tools: "composer:v2"
41+
42+
- name: "Install Dependencies"
43+
run: "composer install"
44+
45+
- name: "Run tests with PHPUnit"
46+
run: "vendor/bin/phpunit"
47+
48+
# - name: "Send code coverage report to Codecov.io"
49+
# env:
50+
# CODECOV_TOKEN: "${{ secrets.CODECOV_TOKEN }}"
51+
# run: "bash <(curl -s https://codecov.io/bash) || true"

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
composer.phar
2+
/vendor/
3+
composer.lock
4+
.phpunit.result.cache
5+
.phpunit.result
6+
.idea/

README.md

Lines changed: 198 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,198 @@
1-
# git-exec-hook
2-
Http git hook call fo action for fetch pull checkout commit push
1+
# Autoframe is a low level framework that is oriented on SOLID flexibility
2+
## 👨🏼‍💻 git-exec-hook
3+
4+
[![License: The 3-Clause BSD License](https://img.shields.io/github/license/autoframe/git-exec-hook)](https://opensource.org/license/bsd-3-clause/)
5+
![Packagist Version](https://img.shields.io/packagist/v/autoframe/git-exec-hook?label=packagist%20stable)
6+
[![Downloads](https://img.shields.io/packagist/dm/autoframe/git-exec-hook.svg)](https://packagist.org/packages/autoframe/git-exec-hook)
7+
8+
# Http git hook call for action for fetch pull checkout commit push
9+
10+
*Config with constants or constructor args*
11+
12+
```php
13+
14+
define('X_HUB_SIGNATURE','sha1 hook token'); //or use in AfrGitHook constructor
15+
define('X_HUB_SIGNATURE_256','sha256 hook token'); //or use sha 256
16+
17+
18+
define('X_PATH_TO_GIT_REPO_DIR','path to current repo dir'); //or use in AfrGitExec constructor
19+
```
20+
21+
---
22+
23+
```php
24+
`AfrGitHook`
25+
26+
use Autoframe\GitExecHook\AfrGitHook;
27+
use Autoframe\GitExecHook\AfrGitExec;
28+
29+
//Hook example
30+
$oGhr = new AfrGitHook('HOOK_TOKEN', '', true);
31+
$gitExec = new AfrGitExec(__DIR__ . '/origin');
32+
33+
//print_r($gitExec->setGitConfigDefault('autoframe','USER@gmail.com'));
34+
//print_r($gitExec->gitCloneWithUserToken('https://github.com/autoframe/hx','USER','ghp_TOKEN'));
35+
36+
37+
if ($oGhr->isPushOnMasterBranch()) {
38+
$aLog = $gitExec->allInOnePushCurrentThenSwitchToMasterPullAddCommitAndPush();
39+
echo '<pre>';
40+
print_r($aLog);
41+
echo '</pre>';
42+
}
43+
44+
```
45+
46+
---
47+
48+
```php
49+
`AfrGitExec`
50+
51+
use Autoframe\GitExecHook\AfrGitExec;
52+
53+
$gitExec = new AfrGitExec('/PATH_TO_GIT_REPO_DIR');
54+
55+
echo '<pre>';
56+
print_r(
57+
$gitExec->gitAddCommitAndPush(
58+
'Manual commit ' . gmdate('Y-m-d H:i:s') . ' GMT',
59+
$gitExec->getCurrentBranchName()
60+
)
61+
);
62+
echo '</pre>';
63+
64+
```
65+
66+
---
67+
68+
# 🚀 git install on Cpanel / WHM 🤖
69+
70+
### 💻 Ubuntu
71+
72+
sudo apt update
73+
sudo apt install git
74+
git --version
75+
76+
### 💻 CentOS 8
77+
78+
sudo dnf update -y
79+
sudo dnf install git -y
80+
git --version
81+
82+
### 💻 CentOS 7
83+
sudo yum update
84+
sudo yum install git
85+
git --version
86+
87+
---
88+
89+
# ⚙️ Config
90+
91+
### ssh / gpg / armour / fingerprint
92+
https://docs.github.com/en/github/authenticating-to-github/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent#generating-a-new-ssh-key
93+
94+
ssh-keygen -o
95+
96+
### 📚 List current config
97+
98+
git config --list
99+
100+
### 🛠️ Set config globally
101+
102+
git config --global user.name "Your Name"
103+
git config --global user.email "you@example.com"
104+
105+
git config --global core.logallrefupdates true
106+
git config --global core.autocrlf false
107+
git config --global core.symlinks false
108+
git config --global core.bare false
109+
git config --global core.ignorecase true
110+
git config --global core.eol lf
111+
112+
### 🔧 Set config to current project
113+
just ignore ***--global***
114+
115+
cd ~/some-dir/project-dir
116+
117+
# 🍀🌈🦄 Clone
118+
119+
cd ~/some-dir/project-dir
120+
git clone git@github.com:autoframe/xxxx.git
121+
git clone 'https://github.com/autoframe/xxxx.git'
122+
123+
### ⛔ clone private repos
124+
Create a new token for the repo: https://github.com/settings/tokens
125+
126+
git clone https://user:TOKEN@github.com/autoframe/repo/
127+
git clone https://user:TOKEN@github.com/username/repo.git
128+
git clone https://oauth2:<YOUR-PERSONAL_ACCESS-TOKEN>@github.com/<your_user>/<your_repo>.git
129+
git clone https://<pat>@github.com/<your account or organization>/<repo>.git
130+
131+
132+
### 📄 Afterward, you can do the following two steps to normalize all files:
133+
134+
git rm --cached -r . ⚠️ Remove every file from git's index.
135+
git reset --hard ⚠️ Rewrite git's index to pick up all the new line endings.
136+
137+
---
138+
139+
# ❗⚠️ Reset commands
140+
141+
git checkout . #If you want to revert changes made to your working copy, do this:
142+
git reset #If you want to revert changes made to the index (i.e., that you have added), do this. Warning this will reset all of your unpushed commits to master!:
143+
git clean -f #If you want to remove untracked files (e.g., new files, generated files):
144+
git clean -fd #Or untracked directories (e.g., new or automatically generated directories):
145+
146+
git revert <commit 1> <commit 2> #If you want to revert a change that you have committed, do this:
147+
148+
# 🌐 Read from upstream
149+
git pull #Pull branch info
150+
git fetch #Refresh branches
151+
152+
# 📥 Checkout
153+
git checkout master #Checkout master branch
154+
git checkout -q master #Quiet, suppress feedback messages.
155+
git checkout -f master #When switching branches, proceed even if the index or the working tree differs from HEAD. This is used to throw away local changes.
156+
157+
### 🙈 checkout args
158+
https://git-scm.com/docs/git-checkout
159+
160+
-q, --quiet
161+
Quiet, suppress feedback messages.
162+
163+
-f, --force
164+
When switching branches, proceed even if the index or the working tree differs from HEAD. This is used to throw away local changes.
165+
166+
-b
167+
**git checkout -b new-branch-name**
168+
169+
Create a new branch named <new_branch> and start it at <start_point>; see git-branch(1) for details.
170+
171+
-m, --merge
172+
When switching branches, if you have local modifications to one or more files that are different between the current branch and the branch to which you are switching, the command refuses to switch branches in order to preserve your modifications in context. However, with this option, a three-way merge between the current branch, your working tree contents, and the new branch is done, and you will be on the new branch.
173+
174+
--ours, --theirs
175+
When checking out paths from the index, do not fail upon unmerged entries; instead, unmerged entries are ignored.
176+
177+
178+
# 📤 Push
179+
180+
git diff
181+
git add .
182+
git commit -m "#uztpOegQ comment info"
183+
git commit -m "PROPT-6264 second commit"
184+
185+
git push <remote> <branch>
186+
git push -u origin branch_name
187+
188+
### 🙈 push args
189+
https://git-scm.com/docs/git-push
190+
191+
-u, --set-upstream
192+
For every branch that is up-to-date or successfully pushed, add upstream (tracking) reference, used by argument-less git-pull[1] and other commands.
193+
194+
-q, --quiet
195+
Suppress all output, including the listing of updated refs, unless an error occurs. Progress is not reported to the standard error stream.
196+
197+
--all, --branches
198+
Push all branches (i.e. refs under refs/heads/); cannot be used with other <refspec>.

Tests/Unit/AfrGitExecTest.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Unit;
5+
6+
use Autoframe\GitExecHook\AfrGitExec;
7+
use PHPUnit\Framework\TestCase;
8+
use Throwable;
9+
10+
class AfrGitExecTest extends TestCase
11+
{
12+
/**
13+
* @test
14+
* @throws \Exception
15+
*/
16+
public function AfrGitExecTest(): void
17+
{
18+
// JUST TEST the construct, that will run and check if git is installed and git --version is called
19+
$oAfrGitExec = null;
20+
try{
21+
$oAfrGitExec = new AfrGitExec(__DIR__);
22+
}
23+
catch (Throwable $e){
24+
throw new \Exception(
25+
$e->getMessage().' in '.$e->getFile().' on line '.$e->getLine()
26+
);
27+
}
28+
29+
$this->assertSame(true, $oAfrGitExec instanceof AfrGitExec);
30+
}
31+
32+
}

composer.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"type": "library",
3+
"name": "autoframe/git-exec-hook",
4+
"description": "Http git hook call for action for fetch pull checkout commit push",
5+
"license": "MIT",
6+
"homepage": "https://github.com/autoframe",
7+
"require": {
8+
"php": ">=7.4",
9+
"ext-json": "*"
10+
},
11+
"version": "1.0.0",
12+
"authors": [
13+
{
14+
"name": "Nistor Alexandru Marius",
15+
"homepage": "https://autoframe.ro",
16+
"role": "Developer"
17+
}
18+
],
19+
"keywords": ["git hook", "git fetch", "git pull", "git checkout", "git commit", "git push"],
20+
"autoload": {
21+
"psr-4": {
22+
"Autoframe\\GitExecHook\\": "src/"
23+
}
24+
},
25+
"autoload-dev": {
26+
"psr-4": {
27+
"Unit\\": "Tests/Unit"
28+
}
29+
},
30+
"require-dev": {
31+
"phpunit/phpunit": "^9.6 || ^10"
32+
}
33+
34+
}

phpunit.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<phpunit colors="true" bootstrap="vendor/autoload.php">
3+
<testsuites>
4+
<testsuite name="Autoframe GIT HOOK AND GIT EXEC">
5+
<directory>Tests/Unit</directory>
6+
</testsuite>
7+
</testsuites>
8+
</phpunit>

0 commit comments

Comments
 (0)