-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathupdater.php
47 lines (33 loc) · 1.07 KB
/
updater.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env php
<?php
function ask(string $question, string $default = ''): string
{
$answer = readline($question.($default ? " {$default}" : null).': ');
if (! $answer) {
return $default;
}
return $answer;
}
function confirm(string $question, bool $default = false): bool
{
$answer = ask($question.' ('.($default ? 'Y/n' : 'y/N').')');
if (! $answer) {
return $default;
}
return strtolower($answer) === 'y';
}
function run(string $command): string
{
return trim((string) shell_exec($command));
}
function runUpdate(string $commitMessage,string $pushBranch): string
{
$shellCmd = 'git add . && git commit -m"'.$commitMessage.'" && git push -u --force origin '.$pushBranch;
run($shellCmd);
return "Repo updated !";
}
$time = time();
$commitMessage = ask("Commit message : ", "auto-update-{$time}");
$pushBranch = ask("Push Branch : ");
confirm("Commit this repo into {$pushBranch} branch with '{$commitMessage}' as message ?","y") &&
runUpdate($commitMessage,$pushBranch );