[ github ] extract github pr hook using PHP

In github, choose

Content type : application/json

Example code to decode

$data_array = json_decode(file_get_contents( 'php://input' ), true);
$data = var_export($data_array, true);

Example array callback

array (
'action' => 'closed',
'number' => 28,
'pull_request' =>
array (
'url' => 'https://api.github.com/repos/phong-wildsky/pong-test-repo/pulls/28',
'id' => 297456404,
'node_id' => 'MDExOlB1bGxSZXF1ZXN0Mjk3NDU2NDA0',
'html_url' => 'https://github.com/phong-wildsky/pong-test-repo/pull/28',
'diff_url' => 'https://github.com/phong-wildsky/pong-test-repo/pull/28.diff',
'patch_url' => 'https://github.com/phong-wildsky/pong-test-repo/pull/28.patch',
'issue_url' => 'https://api.github.com/repos/phong-wildsky/pong-test-repo/issues/28',
'number' => 28,
'state' => 'closed',
'locked' => false,
'title' => 'Update README.md',
'user' =>
array (
'login' => 'phong-wildsky',
'id' => 25359460,
'node_id' => 'MDQ6VXNlcjI1MzU5NDYw',
'avatar_url' => 'https://avatars0.githubusercontent.com/u/25359460?v=4',
'gravatar_id' => '',
'url' => 'https://api.github.com/users/phong-wildsky',
'html_url' => 'https://github.com/phong-wildsky',
'followers_url' => 'https://api.github.com/users/phong-wildsky/followers',
'following_url' => 'https://api.github.com/users/phong-wildsky/following{/other_user}',
'gists_url' => 'https://api.github.com/users/phong-wildsky/gists{/gist_id}',
'starred_url' => 'https://api.github.com/users/phong-wildsky/starred{/owner}{/repo}',
'subscriptions_url' => 'https://api.github.com/users/phong-wildsky/subscriptions',
'organizations_url' => 'https://api.github.com/users/phong-wildsky/orgs',
'repos_url' => 'https://api.github.com/users/phong-wildsky/repos',
'events_url' => 'https://api.github.com/users/phong-wildsky/events{/privacy}',
'received_events_url' => 'https://api.github.com/users/phong-wildsky/received_events',
'type' => 'User',
'site_admin' => false,
),
'body' => '29',
'created_at' => '2019-07-15T03:15:50Z',
'updated_at' => '2019-07-15T03:21:37Z',
'closed_at' => '2019-07-15T03:21:37Z',
'merged_at' => '2019-07-15T03:21:37Z',
'merge_commit_sha' => 'a5ca5dda6949ad0f23450de64d1e9c5246985be0',
'assignee' => NULL,
'assignees' =>
array (
),
'requested_reviewers' =>
array (
),
'requested_teams' =>
array (
),
'labels' =>
array (
),
'milestone' => NULL,
'commits_url' => 'https://api.github.com/repos/phong-wildsky/pong-test-repo/pulls/28/commits',
'review_comments_url' => 'https://api.github.com/repos/phong-wildsky/pong-test-repo/pulls/28/comments',
'review_comment_url' => 'https://api.github.com/repos/phong-wildsky/pong-test-repo/pulls/comments{/number}',
'comments_url' => 'https://api.github.com/repos/phong-wildsky/pong-test-repo/issues/28/comments',
'statuses_url' => 'https://api.github.com/repos/phong-wildsky/pong-test-repo/statuses/4176ebb4e8d2c9be5ca39fe719d71ad9c721f0cf',
'head' =>
array (
'label' => 'phong-wildsky:test-branch-29',
'ref' => 'test-branch-29',
'sha' => '4176ebb4e8d2c9be5ca39fe719d71ad9c721f0cf',
'user' =>
array (
'login' => 'phong-wildsky',
'id' => 25359460,
'node_id' => 'MDQ6VXNlcjI1MzU5NDYw',
'avatar_url' => 'https://avatars0.githubusercontent.com/u/25359460?v=4',
'gravatar_id' => '',
'url' => 'https://api.github.com/users/phong-wildsky',
'html_url' => 'https://github.com/phong-wildsky',
'followers_url' => 'https://api.github.com/users/phong-wildsky/followers',
'following_url' => 'https://api.github.com/users/phong-wildsky/following{/other_user}',
'gists_url' => 'https://api.github.com/users/phong-wildsky/gists{/gist_id}',
'starred_url' => 'https://api.github.com/users/phong-wildsky/starred{/owner}{/repo}',
'subscriptions_url' => 'https://api.github.com/users/phong-wildsky/subscriptions',
'organizations_url' => 'https://api.github.com/users/phong-wildsky/orgs',
'repos_url' => 'https://api.github.com/users/phong-wildsky/repos',
'events_url' => 'https://api.github.com/users/phong-wildsky/events{/privacy}',
'received_events_url' => 'https://api.github.com/users/phong-wildsky/received_events',
'type' => 'User',
'site_admin' => false,
),
'repo' =>
array (
'id' => 154774092,
'node_id' => 'MDEwOlJlcG9zaXRvcnkxNTQ3NzQwOTI=',
'name' => 'pong-test-repo',
'full_name' => 'phong-wildsky/pong-test-repo',
'private' => false,
'owner' =>
array (
'login' => 'phong-wildsky',
'id' => 25359460,
'node_id' => 'MDQ6VXNlcjI1MzU5NDYw',
'avatar_url' => 'https://avatars0.githubusercontent.com/u/25359460?v=4',
'gravatar_id' => '',
'url' => 'https://api.github.com/users/phong-wildsky',
'html_url' => 'https://github.com/phong-wildsky',
'followers_url' => 'https://api.github.com/users/phong-wildsky/followers',
'following_url' => 'https://api.github.com/users/phong-wildsky/following{/other_user}',
'gists_url' => 'https://api.github.com/users/phong-wildsky/gists{/gist_id}',
'starred_url' => 'https://api.github.com/users/phong-wildsky/starred{/owner}{/repo}',
'subscriptions_url' => 'https://api.github.com/users/phong-wildsky/subscriptions',
'organizations_url' => 'https://api.github.com/users/phong-wildsky/orgs',
'repos_url' => 'https://api.github.com/users/phong-wildsky/repos',
'events_url' => 'https://api.github.com/users/phong-wildsky/events{/privacy}',
'received_events_url' => 'https://api.github.com/users/phong-wildsky/received_events',
'type' => 'User',
'site_admin' => false,
),
'html_url' => 'https://github.com/phong-wildsky/pong-test-repo',
'description' => NULL,
'fork' => false,
'url' => 'https://api.github.com/repos/phong-wildsky/pong-test-repo',
'forks_url' => 'https://api.github.com/repos/phong-wildsky/pong-test-repo/forks',
'keys_url' => 'https://api.github.com/repos/phong-wildsky/pong-test-repo/keys{/key_id}',
'collaborators_url' => 'https://api.github.com/repos/phong-wildsky/pong-test-repo/collaborators{/collaborator}',
'teams_url' => 'https://api.github.com/repos/phong-wildsky/pong-test-repo/teams',
'hooks_url' => 'https://api.github.com/repos/phong-wildsky/pong-test-repo/hooks',
'issue_events_url' => 'https://api.github.com/repos/phong-wildsky/pong-test-repo/issues/events{/number}',
'events_url' => 'https://api.github.com/repos/phong-wildsky/pong-test-repo/events',
'assignees_url' => 'https://api.github.com/repos/phong-wildsky/pong-test-repo/assignees{/user}',
'branches_url' => 'https://api.github.com/repos/phong-wildsky/pong-test-repo/branches{/branch}',
'tags_url' => 'https://api.github.com/repos/phong-wildsky/pong-test-repo/tags',
'blobs_url' => 'https://api.github.com/repos/phong-wildsky/pong-test-repo/git/blobs{/sha}',
'git_tags_url' => 'https://api.github.com/repos/phong-wildsky/pong-test-repo/git/tags{/sha}',
'git_refs_url' => 'https://api.github.com/repos/phong-wildsky/pong-test-repo/git/refs{/sha}',
'trees_url' => 'https://api.github.com/repos/phong-wildsky/pong-test-repo/git/trees{/sha}',
'statuses_url' => 'https://api.github.com/repos/phong-wildsky/pong-test-repo/statuses/{sha}',
'languages_url' => 'https://api.github.com/repos/phong-wildsky/pong-test-repo/languages',
'stargazers_url' => 'https://api.github.com/repos/phong-wildsky/pong-test-repo/stargazers',
'contributors_url' => 'https://api.github.com/repos/phong-wildsky/pong-test-repo/contributors',
'subscribers_url' => 'https://api.github.com/repos/phong-wildsky/pong-test-repo/subscribers',
'subscription_url' => 'https://api.github.com/repos/phong-wildsky/pong-test-repo/subscription',
'commits_url' => 'https://api.github.com/repos/phong-wildsky/pong-test-repo/commits{/sha}',
'git_commits_url' => 'https://api.github.com/repos/phong-wildsky/pong-test-repo/git/commits{/sha}',
'comments_url' => 'https://api.github.com/repos/phong-wildsky/pong-test-repo/comments{/number}',
'issue_comment_url' => 'https://api.github.com/repos/phong-wildsky/pong-test-repo/issues/comments{/number}',
'contents_url' => 'https://api.github.com/repos/phong-wildsky/pong-test-repo/contents/{+path}',
'compare_url' => 'https://api.github.com/repos/phong-wildsky/pong-test-repo/compare/{base}...{head}',
'merges_url' => 'https://api.github.com/repos/phong-wildsky/pong-test-repo/merges',
'archive_url' => 'https://api.github.com/repos/phong-wildsky/pong-test-repo/{archive_format}{/ref}',
'downloads_url' => 'https://api.github.com/repos/phong-wildsky/pong-test-repo/downloads',
'issues_url' => 'https://api.github.com/repos/phong-wildsky/pong-test-repo/issues{/number}',
'pulls_url' => 'https://api.github.com/repos/phong-wildsky/pong-test-repo/pulls{/number}',
'milestones_url' => 'https://api.github.com/repos/phong-wildsky/pong-test-repo/milestones{/number}',
'notifications_url' => 'https://api.github.com/repos/phong-wildsky/pong-test-repo/notifications{?since,all,participating}',
'labels_url' => 'https://api.github.com/repos/phong-wildsky/pong-test-repo/labels{/name}',
'releases_url' => 'https://api.github.com/repos/phong-wildsky/pong-test-repo/releases{/id}',
'deployments_url' => 'https://api.github.com/repos/phong-wildsky/pong-test-repo/deployments',
'created_at' => '2018-10-26T03:48:35Z',
'updated_at' => '2019-07-15T03:12:41Z',
'pushed_at' => '2019-07-15T03:21:37Z',
'git_url' => 'git://github.com/phong-wildsky/pong-test-repo.git',
'ssh_url' => 'git@github.com:phong-wildsky/pong-test-repo.git',
'clone_url' => 'https://github.com/phong-wildsky/pong-test-repo.git',
'svn_url' => 'https://github.com/phong-wildsky/pong-test-repo',
'homepage' => NULL,
'size' => 29,
'stargazers_count' => 0,
'watchers_count' => 0,
'language' => NULL,
'has_issues' => true,
'has_projects' => true,
'has_downloads' => true,
'has_wiki' => true,
'has_pages' => false,
'forks_count' => 0,
'mirror_url' => NULL,
'archived' => false,
'disabled' => false,
'open_issues_count' => 2,
'license' => NULL,
'forks' => 0,
'open_issues' => 2,
'watchers' => 0,
'default_branch' => 'master',
),
),
'base' =>
array (
'label' => 'phong-wildsky:master',
'ref' => 'master',
'sha' => 'df9d6ca2a55d5a556af07069fb78cdc8dfee86e6',
'user' =>
array (
'login' => 'phong-wildsky',
'id' => 25359460,
'node_id' => 'MDQ6VXNlcjI1MzU5NDYw',
'avatar_url' => 'https://avatars0.githubusercontent.com/u/25359460?v=4',
'gravatar_id' => '',
'url' => 'https://api.github.com/users/phong-wildsky',
'html_url' => 'https://github.com/phong-wildsky',
'followers_url' => 'https://api.github.com/users/phong-wildsky/followers',
'following_url' => 'https://api.github.com/users/phong-wildsky/following{/other_user}',
'gists_url' => 'https://api.github.com/users/phong-wildsky/gists{/gist_id}',
'starred_url' => 'https://api.github.com/users/phong-wildsky/starred{/owner}{/repo}',
'subscriptions_url' => 'https://api.github.com/users/phong-wildsky/subscriptions',
'organizations_url' => 'https://api.github.com/users/phong-wildsky/orgs',
'repos_url' => 'https://api.github.com/users/phong-wildsky/repos',
'events_url' => 'https://api.github.com/users/phong-wildsky/events{/privacy}',
'received_events_url' => 'https://api.github.com/users/phong-wildsky/received_events',
'type' => 'User',
'site_admin' => false,
),
'repo' =>
array (
'id' => 154774092,
'node_id' => 'MDEwOlJlcG9zaXRvcnkxNTQ3NzQwOTI=',
'name' => 'pong-test-repo',
'full_name' => 'phong-wildsky/pong-test-repo',
'private' => false,
'owner' =>
array (
'login' => 'phong-wildsky',
'id' => 25359460,
'node_id' => 'MDQ6VXNlcjI1MzU5NDYw',
'avatar_url' => 'https://avatars0.githubusercontent.com/u/25359460?v=4',
'gravatar_id' => '',
'url' => 'https://api.github.com/users/phong-wildsky',
'html_url' => 'https://github.com/phong-wildsky',
'followers_url' => 'https://api.github.com/users/phong-wildsky/followers',
'following_url' => 'https://api.github.com/users/phong-wildsky/following{/other_user}',
'gists_url' => 'https://api.github.com/users/phong-wildsky/gists{/gist_id}',
'starred_url' => 'https://api.github.com/users/phong-wildsky/starred{/owner}{/repo}',
'subscriptions_url' => 'https://api.github.com/users/phong-wildsky/subscriptions',
'organizations_url' => 'https://api.github.com/users/phong-wildsky/orgs',
'repos_url' => 'https://api.github.com/users/phong-wildsky/repos',
'events_url' => 'https://api.github.com/users/phong-wildsky/events{/privacy}',
'received_events_url' => 'https://api.github.com/users/phong-wildsky/received_events',
'type' => 'User',
'site_admin' => false,
),
'html_url' => 'https://github.com/phong-wildsky/pong-test-repo',
'description' => NULL,
'fork' => false,
'url' => 'https://api.github.com/repos/phong-wildsky/pong-test-repo',
'forks_url' => 'https://api.github.com/repos/phong-wildsky/pong-test-repo/forks',
'keys_url' => 'https://api.github.com/repos/phong-wildsky/pong-test-repo/keys{/key_id}',
'collaborators_url' => 'https://api.github.com/repos/phong-wildsky/pong-test-repo/collaborators{/collaborator}',
'teams_url' => 'https://api.github.com/repos/phong-wildsky/pong-test-repo/teams',
'hooks_url' => 'https://api.github.com/repos/phong-wildsky/pong-test-repo/hooks',
'issue_events_url' => 'https://api.github.com/repos/phong-wildsky/pong-test-repo/issues/events{/number}',
'events_url' => 'https://api.github.com/repos/phong-wildsky/pong-test-repo/events',
'assignees_url' => 'https://api.github.com/repos/phong-wildsky/pong-test-repo/assignees{/user}',
'branches_url' => 'https://api.github.com/repos/phong-wildsky/pong-test-repo/branches{/branch}',
'tags_url' => 'https://api.github.com/repos/phong-wildsky/pong-test-repo/tags',
'blobs_url' => 'https://api.github.com/repos/phong-wildsky/pong-test-repo/git/blobs{/sha}',
'git_tags_url' => 'https://api.github.com/repos/phong-wildsky/pong-test-repo/git/tags{/sha}',
'git_refs_url' => 'https://api.github.com/repos/phong-wildsky/pong-test-repo/git/refs{/sha}',
'trees_url' => 'https://api.github.com/repos/phong-wildsky/pong-test-repo/git/trees{/sha}',
'statuses_url' => 'https://api.github.com/repos/phong-wildsky/pong-test-repo/statuses/{sha}',
'languages_url' => 'https://api.github.com/repos/phong-wildsky/pong-test-repo/languages',
'stargazers_url' => 'https://api.github.com/repos/phong-wildsky/pong-test-repo/stargazers',
'contributors_url' => 'https://api.github.com/repos/phong-wildsky/pong-test-repo/contributors',
'subscribers_url' => 'https://api.github.com/repos/phong-wildsky/pong-test-repo/subscribers',
'subscription_url' => 'https://api.github.com/repos/phong-wildsky/pong-test-repo/subscription',
'commits_url' => 'https://api.github.com/repos/phong-wildsky/pong-test-repo/commits{/sha}',
'git_commits_url' => 'https://api.github.com/repos/phong-wildsky/pong-test-repo/git/commits{/sha}',
'comments_url' => 'https://api.github.com/repos/phong-wildsky/pong-test-repo/comments{/number}',
'issue_comment_url' => 'https://api.github.com/repos/phong-wildsky/pong-test-repo/issues/comments{/number}',
'contents_url' => 'https://api.github.com/repos/phong-wildsky/pong-test-repo/contents/{+path}',
'compare_url'...(length 28436)

[ gae ] Request host is not whitelist enabled for this server. Please use the –host command-line flag to whitelist a specific host (recommended) or use –enable_host_checking to disable host checking. See the command-line flags help text for more information.

Problem

Request host is not whitelist enabled for this server. Please use the --host command-line flag to whitelist a specific host (recommended) or use --enable_host_checking to disable host checking. See the command-line flags help text for more information.

Solution

dev_appserver.py app.yaml --enable_host_checking=false

[ wordpress ] gcloud

Switch Gcloud project

gcloud config set project my-project

Create database

1) a new Cloud SQL for MySQL Second Generation instance

gcloud sql instances create wordpress \
    --activation-policy=ALWAYS \
    --tier=db-n1-standard-1

Describe where your database is

gcloud sql instances describe wordpress | grep region

TIPS : delete

gcloud sql instances delete wordpress

2) Create the database
instance name / database name : `wordpress`
database user name : `root`

gcloud sql databases create wordpress --instance wordpress

TIPS : delete

gcloud sql databases delete wordpress --instance wordpress

3) change root password

gcloud sql users set-password root % \
    --instance wordpress \
    --password=YOUR_INSTANCE_ROOT_PASSWORD # Don't use this password!

Composer

composer require google/cloud-tools
composer require google/cloud-tools
php vendor/bin/wp-gae

wp-gae command provides a convenient way for you to either create a new WordPress project or add the required configuration to an existing one

The wp-gae command will ask you several question in order to set up your Cloud SQL database connection, and then write the required configuration to your wp-config.php configuration file. It also copies the following files into your project directory to allow WordPress to run on Google App Engine:

app.yaml: The App Engine configuration file that specifies the runtime and static asset handlers.
cron.yaml: The App Engine configuration file that ensures wp-cron.php is run every 15 minutes.
php.ini: For setting PHP configuration in App Engine specific to WordPress.
gae-app.php: The Front Controller, which is required for all App Engine applications.

Create a new WordPress project

php vendor/bin/wp-gae create

 

 

Migrate existing project to gcloud

php vendor/bin/wp-gae update path/to/your-wordpress-site

deploy 

gcloud app deploy app.yaml cron.yaml

Pricing :

“for the month of November and December which amounts to $8.05 per month. So it’s almost the same as paying for shared hosting I’d say. It looks like the Cloud SQL instance does not shut down.”

https://stackoverflow.com/questions/27654922/wordpress-on-google-app-engine-pricing

ref : https://cloud.google.com/community/tutorials/run-wordpress-on-appengine-standard?authuser=3

[ css ] javascript load deferred style

put the `link href` into `noscript id=”deferred-styles”`

Then insert this javascript

    var loadDeferredStyles = function() {
      var addStylesNode = document.getElementById("deferred-styles");
      var replacement = document.createElement("div");
      replacement.innerHTML = addStylesNode.textContent;
      document.body.appendChild(replacement)
      addStylesNode.parentElement.removeChild(addStylesNode);
    };
    var raf = requestAnimationFrame || mozRequestAnimationFrame ||
        webkitRequestAnimationFrame || msRequestAnimationFrame;
    if (raf) raf(function() { window.setTimeout(loadDeferredStyles, 0); });
    else window.addEventListener('load', loadDeferredStyles);
  

[ ApolloClient ] fetch error on IE 11

Error on IE 11 : 

fetch is not found globally and no fetcher passed, to fix pass a fetch for\nyour environment like https://www.npmjs.com/package/" + library + ".\n\n
// For example:\nimport fetch from '" + library + "';\nimport { createHttpLink } from 'apollo-link-http';\n\nconst link = createHttpLink({ uri: '/graphql', fetch: fetch });");

Solution :

if (!window.fetch) window.fetch = fetch

ref : https://www.npmjs.com/package/whatwg-fetch

[ git ] revert PR, then move all the PR branch content to the new branch

  1. Create patch file that contains a diff between 2 branch
git diff develop..link-to-category-page > link-to-category-page.patch

2) Create new branch and apply patch to new branch

git apply link-to-category-page.patch

 

ref : https://gist.github.com/patkujawa-wf/9960173

, https://stackoverflow.com/questions/24922094/taking-a-git-diff-and-creating-a-new-branch-in-different-repo/24922587#comment38724313_24922094