Skip to content

Instantly share code, notes, and snippets.

@0m3r
Last active April 1, 2020 10:58
Show Gist options
  • Save 0m3r/16241092b5839345216dcdb1408baaae to your computer and use it in GitHub Desktop.
Save 0m3r/16241092b5839345216dcdb1408baaae to your computer and use it in GitHub Desktop.
Add vaimo/composer-patches from console.

Php workarounds for weary travelers composer/composer#8353

curl -s https://gist.githubusercontent.com/0m3r/16241092b5839345216dcdb1408baaae/raw/add_vaimo_patch.bash | sha1sum 
910c77732701413018898d314dc073600833599e

curl -s https://gist.githubusercontent.com/0m3r/16241092b5839345216dcdb1408baaae/raw/add_vaimo_patch.bash | bash -s "vendor/module-package" "Path title #1" http://re.ro/path.diff

curl -s https://gist.githubusercontent.com/0m3r/16241092b5839345216dcdb1408baaae/raw/add_vaimo_patch.bash | bash -s "vendor/module-package" "Path title #1" "source":"http://re.po/1.diff","version":">2.3.1 <= 2.4","sha1":"@123"
#!/bin/bash
[ ! -f ./composer.json ] && { echo >&2 "composer.json doesn't exist"; exit 1; }
if test "$#" -ne 3; then
echo >&2 "Usage examples : ";
echo >&2 " curl -s [gist.url]add_vaimo_patch.sh | bash -s \"vendor/module-package\" \"Path title #1\" http://re.ro/path.diff";
echo >&2 " cat add_vaimo_patch.sh | bash -s \"vendor/module-package\" \"Path title #1\" http://re.ro/path.diff";
echo >&2 " cat add_vaimo_patch.sh | bash -s \"vendor/module-package\" \"Path title #2\" \"source\":\"http://re.po/1.diff\",\"version\":\">2.3.1 <= 2.4\",\"sha1\":\"@123\"";
exit 1;
fi
printf '%s' "$1|$2|$3" | php -r '
$f = "composer.json";
$c = json_decode(file_get_contents($f), 1);
$in = explode("|", file_get_contents("php://stdin"));
if (strpos($in[2],",")){
$v = [];
foreach(explode(",", $in[2]) as $p){
list($k,$w) = explode(":",$p,2);
$v[$k]=$w;
}
} else {
$v = $in[2];
}
$c["extra"]["patches"][$in[0]][$in[1]]=$v;
print_r($c["extra"]);
$fg=JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES;
file_put_contents($f, json_encode($c, $fg));'
@0m3r
Copy link
Author

0m3r commented Feb 6, 2020

Notes

Testing your SSH connection

ssh -T git@github.com

Get/create github api token
https://gist.github.com/ozh/4725166
Understanding scopes for OAuth Apps

curl -u ':USERNAME' -d '{"scopes":["repo"],"note":"Google Issues to GH"}' https://api.github.com/authorizations
curl -H "Authorization: bearer :TOKEN" https://api.github.com/users/:USERNAME -I

Shell script to retrieve the patch file for a pull request in a private repo on github

curl -H "Authorization: token xxxx" -H "Accept: application/vnd.github.v3.patch" https://api.github.com/repos/swissup/module-pagespeed/commits/da92f60d2b9b85899d5d5aecb1156fce7dce8a2b

curl -H "Authorization: token xxxx" -H "Accept: application/vnd.github.v3.diff" https://api.github.com/repos/swissup/module-pagespeed/commits/da92f60d2b9b85899d5d5aecb1156fce7dce8a2b

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment