0

Now that the code for a small RSS-reading CMS that I've done is hosted on github, I'd like it to

  • check automatically if there is a newer version of itself's in the master branch
  • Allow the user to update said script, ie it would overwrite itself with the newer version
2
  • 1
    So what is the problem you're having? Commented Feb 15, 2012 at 13:05
  • ? Well I don't know where to start ! How do you (I) do that ? Is there a PHP function for that ? Is there a github API function for that ? Is it even possible ? I have this page, index.php, on a server A. And the same page, index.php, on the server B, only newer. What do I put in serverA/index.php to check for the version of serverB/index.php ? Commented Feb 15, 2012 at 13:12

2 Answers 2

4

Here is what I came up with (thanks to cillosis's answer)

$commits = json_decode(file_get_contents("https://api.github.com/repos/user_name/repository_name/commits"));

$current_commit_minus1 = $commits[1]->sha;
$ref_commit = "57b75c0f8aefa5ce87c1270265cace18a2347594";

if (!strcmp($current_commit_minus1, $ref_commit))
    $moved = true;
  else
    $moved = false;

That way I don't have to maintain tags, just compare commits.

Sign up to request clarification or add additional context in comments.

Comments

2

It should be possible maintaining a current version number within the script, and then comparing it to the repository using the Repositories API.

You can get repo tags with CURL like this (replace :user and :repo with your stuff):

curl http://github.com/api/v2/json/repos/show/:user/:repo/tags

You can show branches like this:

curl http://github.com/api/v2/json/repos/show/:user/:repo/branches

There is a lot of other info available in that API as well.

Once you get that, compare it to the current and procede with updating.

1 Comment

The command that worked for me : curl https://api.github.com/repos/user_name/repository_name/tags

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.