2012-02-15 35 views
0

現在,我已經做了在GitHub上託管了a small RSS-reading CMS的代碼,我就喜歡實現與github上

  • 自動檢查是否有自動版的自我檢查和更新的PHP腳本自身的新版本在主分支
  • 允許用戶更新該腳本,也就是說,它會覆蓋本身與新版本
+1

那麼你遇到了什麼問題? – jprofitt 2012-02-15 13:05:27

+0

?那麼我不知道從哪裏開始!你(我)如何做到這一點?有沒有PHP的功能? 是否有一個github的API函數? 它甚至有可能嗎? 我有這個頁面,index.php,在服務器上A. 而服務器B上的同一頁index.php只有更新。 我在serverA/index.php中檢查serverB/index.php的版本是什麼? – yPhil 2012-02-15 13:12:20

回答

2

這裏是what I came up with(感謝cillosis的答案)

$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; 

這樣我就不必維護標籤,只是比較提交。

2

應該可以維持在腳本中的當前版本號,然後將其與存儲庫usi進行比較Repositories API

你可以得到回購標籤,像這樣捲曲(更換:用戶:回購你的東西):

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

您可以顯示這樣的分支:

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

該API中還有許多其他信息可用。

一旦你得到那個,把它和當前的比較,並進行更新。

+0

對於遲到的接受,這似乎是確實的方式。 – yPhil 2013-09-16 12:13:28

+2

爲我工作的命令:'curl https:// api.github.com/repos/user_name/repository_name/tags' – yPhil 2013-09-16 12:34:00