ICErepo plugin added

Not quite finished yet, but an early version added for use
This commit is contained in:
Matt Pass
2012-08-27 15:47:48 +01:00
parent f12b4914e6
commit 76224c40fe
13 changed files with 559 additions and 11 deletions

View File

@@ -0,0 +1,24 @@
Copyright (C) 2012 Matt Pass
Website: mattpass.com
Email: matt@mattpass.com
Twitter: @mattpass
#ICErepo License
##Standard Open Source Initiative MIT License
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@@ -0,0 +1,61 @@
ICErepo
=======
Show diffs, push, pull & sync your site and Github repo's.
While Github has a fantastic website, mobile app, desktop app and of course bash system, there's no web based UI I can find to sync your website code with Github repo's or vice versa. That's what ICErepo provides.
Originally intended to be a plugin for ICEcoder (https://github.com/mattpass/ICEcoder), I have decided to make it a standalone lib so it can run by itself or easily be integrated into any existing system.
The aim is a simple UI to view diffs between your server dir's and related Github repo's. This list will consist of new files (those only on server), deleted files (those only on Github) and changed files (files that exist in both places but are different). Files that exist in both locations and the same are not shown to keep things minimalist.
Users can then to pick & choose the files & folder they'd like to commit, provide a title and message, then commit to Github. As each file is synced by the user to match the server it dissapears from the UI list. Alternatively you can pull files & folders from Github to sync your server dir's with the repo itself.
Cool huh?
**Current screnshot:**
<img src="http://www.icecoder.net/github/screenshot.jpg" alt="ICErepo screenshot">
This lib uses customised & minified versions of these brilliant and time tested repos:
Github API lib: https://github.com/michael/github
JS Diff lib: https://github.com/cemerick/jsdifflib
###Installation
####Step 1: Clone the repo
```
$ git clone git@github:mattpass/ICErepo
```
####Step 2: Enter your auth settings
```
Open index.php and enter either your Github oauth token or username & password
oauth is recommended here, view http://developer.github.com/v3/oauth/ for info
(If using oauth ensure you have repo scope & your app is granted the URL you'll run under)
```
####Step 3: Enter your repo & server dir settings
```
Also in index.php, enter the repo & corresponding server paths
Enter 'selected' as a 3rd param next to your default repo/server option to autoload that
Finally, set $_SESSION['userLevel'] to be > 0 with your own login system, or simply uncomment line 3
Upload ICErepo, visit in a web browser & enjoy
```
**Dev schedule:**
**v0.8**
Bug testing, refactoring & optimisation
**v0.9**
Alpha testing
**v0.95**
Beta testing
**v1.0**
Version 1 released

View File

@@ -0,0 +1,127 @@
<?php
session_start();
if ($_SESSION['userLevel'] == 0) {
die("Sorry, you need to be logged in to use ICErepo");
}
function strClean($var) {
// returns converted entities where there are HTML entity equivalents
return htmlentities($var, ENT_QUOTES, "UTF-8");
}
function numClean($var) {
// returns a number, whole or decimal or null
return is_numeric($var) ? floatval($var) : false;
}
?>
<!DOCTYPE html>
<html>
<head>
<title>ICErepo v<?php echo $version;?></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script src="lib/base64.js"></script>
<script src="lib/github.js"></script>
<script src="lib/difflib.js"></script>
<script src="ice-repo.js"></script>
<link rel="stylesheet" type="text/css" href="ice-repo.css">
</head>
<body>
<?php
// Function to sort given values alphabetically
function alphasort($a, $b) {
return strcmp($a->getPathname(), $b->getPathname());
}
// Class to put forward the values for sorting
class SortingIterator implements IteratorAggregate {
private $iterator = null;
public function __construct(Traversable $iterator, $callback) {
$array = iterator_to_array($iterator);
usort($array, $callback);
$this->iterator = new ArrayIterator($array);
}
public function getIterator() {
return $this->iterator;
}
}
// Get a full list of dirs & files and begin sorting using above class & function
$repoPath = explode("@",strClean($_POST['repo']));
$repo = $repoPath[0];
$path = $repoPath[1];
$objectList = new SortingIterator(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::SELF_FIRST), 'alphasort');
// Finally, we have our ordered list, so display
$i=0;
$dirListArray = array();
$dirSHAArray = array();
$dirTypeArray = array();
$finfo = finfo_open(FILEINFO_MIME_TYPE);
foreach ($objectList as $objectRef) {
$fileFolderName = rtrim(substr($objectRef->getPathname(), strlen($path)),"..");
if ($objectRef->getFilename()!="." && $fileFolderName[strlen($fileFolderName)-1]!="/") {
$contents = file_get_contents($path.$fileFolderName);
if (strpos(finfo_file($finfo, $path.$fileFolderName),"text")===0) {
$contents = str_replace("\r","",$contents);
};
$store = "blob ".strlen($contents)."\000".$contents;
$i++;
array_push($dirListArray,ltrim($fileFolderName,"/"));
array_push($dirSHAArray,sha1($store));
$type = is_dir($path.$fileFolderName) ? "dir" : "file";
array_push($dirTypeArray,$type);
}
}
finfo_close($finfo);
?>
<script>
top.repo = '<?php echo $repo;?>';
top.path = '<?php echo $path;?>';
dirListArray = [<?php echo "'".implode("','", $dirListArray)."'";?>];
dirSHAArray = [<?php echo "'".implode("','", $dirSHAArray)."'";?>];
dirTypeArray = [<?php echo "'".implode("','", $dirTypeArray)."'";?>];
</script>
<div id="compareList" class="mainContainer"></div>
<div id="commitPane" class="commitPane">
<b style='font-size: 18px'>COMMIT CHANGES:</b><br><br>
<form name="fcForm" action="file-control.php" target="fileControl" method="POST">
<input type="text" name="title" value="Title..." style="width: 260px; border: 0; background: #f8f8f8; margin-bottom: 10px" onFocus="titleDefault='Title...'; if(this.value==titleDefault) {this.value=''}" onBlur="if(this.value=='') {this.value=titleDefault}"><br>
<textarea name="message" style="width: 260px; height: 180px; border: 0; background: #f8f8f8; margin-bottom: 5px" onFocus="messageDefault='Message...'; if(this.value==messageDefault) {this.value=''}" onBlur="if(this.value=='') {this.value=messageDefault}">Message...</textarea>
<input type="hidden" name="token" value="<?php echo strClean($_POST['token']);?>">
<input type="hidden" name="username" value="<?php echo strClean($_POST['username']);?>">
<input type="hidden" name="password" value="<?php echo strClean($_POST['password']);?>">
<input type="hidden" name="path" value="<?php echo $path; ?>">
<input type="hidden" name="rowID" value="">
<input type="hidden" name="gitRepo" value="<?php echo $repo; ?>">
<input type="hidden" name="repo" value="">
<input type="hidden" name="dir" value="">
<input type="hidden" name="action" value="">
<input type="submit" name="commit" value="Commit changes" onClick="return commitChanges()" style="border: 0; background: #555; color: #fff; cursor: pointer">
</form>
</div>
<div id="infoPane" class="infoPane"></div>
<script>
top.fcFormAlias = document.fcForm;
var github = new Github(<?php
if ($_POST['token']!="") {
echo '{token: "'.strClean($_POST['token']).'", auth: "oauth"}';
} else{
echo '{username: "'.strClean($_POST['username']).'", password: "'.strClean($_POST['password']).'", auth: "basic"}';
}?>);
repoListArray = [];
repoSHAArray = [];
window.onLoad=gitCommand('repo.show','<?php echo strClean($_POST['repo']);?>');
</script>
<iframe name="fileControl" style="display: none"></iframe>
</body>
</html>

View File

@@ -0,0 +1,144 @@
<?php
session_start();
if ($_SESSION['userLevel'] == 0) {
die("Sorry, you need to be logged in to use ICErepo");
}
// returns converted entities where there are HTML entity equivalents
function strClean($var) {
return htmlentities($var, ENT_QUOTES, "UTF-8");
}
// returns a number, whole or decimal or null
function numClean($var) {
return is_numeric($var) ? floatval($var) : false;
}
$repoPath = strClean($_POST['repoPath']);
$gitRepo = strClean($_POST['gitRepo']);
$path = strClean($_POST['path']);
$rowID = strClean($_POST['rowID']);
$repo = strClean($_POST['repo']);
$dir = strClean($_POST['dir']);
$action = str_replace("PULL:","",str_replace("SAVEPULLS:","",strClean($_POST['action'])));
$rowIDArray = explode(",",$rowID);
$repoArray = explode(",",$repo);
$dirArray = explode(",",$dir);
$actionArray = explode(",",$action);
?>
<!DOCTYPE html>
<html>
<head>
<title>ICErepo v<?php echo $version;?></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script src="lib/underscore-min.js"></script>
<script src="lib/base64.js"></script>
<script src="lib/github.js"></script>
<script src="lib/difflib.js"></script>
<script src="ice-repo.js"></script>
<link rel="stylesheet" type="text/css" href="ice-repo.css">
</head>
<body>
<script>
fullRepoPath='<?php echo $repo;?>';
gitRepo='<?php echo $gitRepo;?>';
var github = new Github(<?php
if ($_POST['token']!="") {
echo '{token: "'.strClean($_POST['token']).'", auth: "oauth"}';
} else{
echo '{username: "'.strClean($_POST['username']).'", password: "'.strClean($_POST['password']).'", auth: "basic"}';
}?>);
repoUser = gitRepo.split('/')[0];
repoName = gitRepo.split('/')[1];
filePath = fullRepoPath.replace(repoUser+"/"+repoName+"/","");
var repo = github.getRepo(repoUser,repoName);
</script>
<?php if ($_POST['action']=="view") {?>
<form name="fcForm">
<textarea name="fileContents"><?php echo htmlentities(file_get_contents($dir)); ?></textarea>
</form>
<script>
rowID = <?php echo $rowID; ?>;
baseTextName = "Server: <?php echo str_replace($_SERVER['DOCUMENT_ROOT']."/","",$dir);?> ";
newTextName = "Github: <?php echo $repo;?>";
window.onLoad = sendData(baseTextName,newTextName);
</script>
<?php } else if (substr($_POST['action'],0,5)=="PULL:") { ?>
<form name="fcForm" action="file-control.php" method="POST">
<?php
echo '<input type="hidden" name="rowID" value="'.$rowID.'">';
echo '<input type="hidden" name="repo" value="'.$repo.'">';
echo '<input type="hidden" name="dir" value="'.$dir.'">';
echo '<input type="hidden" name="action" value="SAVEPULLS:'.$action.'">';
echo '<input type="hidden" name="path" value="'.$path.'">';
for ($i=0;$i<count($rowIDArray);$i++) {
if ($repoArray[$i]!="") {
echo '<textarea name="repoContents'.$rowIDArray[$i].'"></textarea>';
}
}
?>
</form>
<script>
rowIDArray = [<?php echo implode(",", $rowIDArray);?>];
repoArray = [<?php echo "'".implode("','", $repoArray)."'";?>];
dirArray = [<?php echo "'".implode("','", $dirArray)."'";?>];
actionArray = [<?php echo "'".implode("','", $actionArray)."'";?>];
window.onLoad = getData();
</script>
<?php } else if (substr($_POST['action'],0,10)=="SAVEPULLS:") {?>
<script>
<?php
for ($i=0;$i<count($rowIDArray);$i++) {
if ($actionArray[$i]!="new") {
$dirs = explode("/",$repoArray[$i]);
$relDir = "";
for ($j=0;$j<count($dirs)-1;$j++) {
$relDir .= "/".$dirs[$j];
if (!is_dir($path.$relDir)) {
mkdir($path.$relDir, 0755);
}
}
$fh = fopen($path."/".$repoArray[$i], 'w') or die("alert('Sorry, there was a problem pulling ".$repoArray[$i].". Either the file is unavailable on Github or server permissions aren\'t allowing it to be created/updated.');get('blackMask','top').style.display='none';");
fwrite($fh, $_POST['repoContents'.$rowIDArray[$i]]);
fclose($fh);
echo "hideRow(".$rowIDArray[$i].");top.newCount--;";
} else {
is_dir($dir) ? $success = rmdir($dir) : $success = unlink($dir);
if (!$success) {
echo "alert('Sorry, couldn\'t delete ".$dir."\\n\\n";
echo "Maybe you need to give file permissions for it to be deleted?');";
} else {
echo "hideRow(".$rowIDArray[$i].");top.deletedCount--;";
}
}
}
echo "get('blackMask','top').style.display = 'none';";
?>
</script>
<?php } else { ?>
<form name="fcForm">
<?php
for ($i=0;$i<count($rowIDArray);$i++) {
if ($dirArray[$i]!="") {
echo '<textarea name="fileContents'.$rowIDArray[$i].'">';
echo htmlentities(file_get_contents($dirArray[$i]));
echo '</textarea>';
}
}
?>
</form>
<script>
rowIDArray = [<?php echo implode(",", $rowIDArray);?>];
repoArray = [<?php echo "'".implode("','", $repoArray)."'";?>];
dirArray = [<?php echo "'".implode("','", $dirArray)."'";?>];
actionArray = [<?php echo "'".implode("','", $actionArray)."'";?>];
window.onLoad = startProcess();
</script>
<?php } ?>
</body>
</html>

View File

@@ -0,0 +1,78 @@
/* First, reset everything to a standard */
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, font, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td {
font-family: arial, verdana, helvetica, sans-serif;
border: 0px;
margin: 0px;
padding: 0px;
outline: 0px;
font-size: 12px;
vertical-align: top;
}
html, body {background-color: #fff; width: 100%}
p {color: #444}
textarea, input {font-family: arial, verdana, helvetica, sans-serif; padding: 4px}
.header {position: absolute; width: 100%; height: 60px; background: #444; z-index: 1}
.mainContainer {position: relative; display: block; width: 900px; padding: 20px}
.blackMask {position: absolute; width: 100%; height: 100%; background: rgba(0,0,0,0.9); z-index: 200}
.loadingMsgCenter {position: absolute; display: inline-block; left: 50%; top: 50%; width: 1px; height: 1px}
.loadingMsgContainer {position: absolute; display: inline-block; left: -30px; top: -7px; width: 60px; height: 14px; background-color: #bbb; color: #222; font-weight: bold; text-align: center; padding: 15px; z-index: 201;
-webkit-box-shadow: 8px 8px 8px 8px rgba(0,0,0,0.4);
-moz-box-shadow: 8px 8px 8px 8px rgba(0,0,0,0.4);
box-shadow: 4px 4px 8px 4px rgba(0,0,0,0.4)}
.repoFrame {position: absolute; width: 100%; height: 90%; left: 0px; margin-top: 60px}
.row {position: relative; display: inline-block; background: #ccc; color: #000; width: 880px; padding: 10px 7px; margin-bottom: 2px; cursor: pointer; padding-left: 35px}
.row:hover {background: #888; color: #fff}
.row .icon {display: inline-block; width: 16px; height: 16px; margin-right: 7px; background-image:url(images/file-folder-icons.png); background-repeat: no-repeat}
.row .checkbox {position: absolute; display: inline-block; height: 38px; width: 30px; top: -4px; left: 0px}
.rowContent {position: relative; display: none; background: #eee; width: 100%; height: 300px; padding: 7px; margin-bottom: 10px; overflow: auto}
.pullGithub {position: absolute; display: inline-block; top: 7px; left: 822px; padding: 5px; background: #bbb; color: #444; font-size: 10px; cursor: pointer}
.pullGithubSel {position: absolute; display: inline-block; top: 7px; left: 822px; margin-top: 12px; margin-left: -22px; padding: 5px; background: #bbb; color: #444; font-size: 10px; cursor: pointer}
.version {position: absolute; display: inline-block; width: 100px; left: 1000px; top: 33px; font-size: 10px; color: #bbb; text-align: right}
.logo {position: absolute; left: 1107px; top: 12px}
.commitPane {position: fixed; background: #ccc; width: 270px; height: 300px; left: 960px; top: 0px; padding: 20px 10px 10px 10px; z-index: 100}
.infoPane {position: fixed; width: 270px; height: 100px; left: 960px; top: 340px; padding: 20px 10px 10px 10px; z-index: 100}
/* Folder */
.ext-folder {background-position: -16px 0}
/* Additional file types */
.ext-coffee {background-position: -32px 0}
.ext-css {background-position: -48px 0}
.ext-gif {background-position: -64px 0}
.ext-htm {background-position: -80px 0}
.ext-html {background-position: -80px 0}
.ext-jpg {background-position: -96px 0}
.ext-jpeg {background-position: -96px 0}
.ext-js {background-position: -112px 0}
.ext-less {background-position: -128px 0}
.ext-php {background-position: -144px 0}
.ext-png {background-position: -160px 0}
.ext-rb {background-position: -176px 0}
.ext-rbx {background-position: -176px 0}
.ext-rhtml {background-position: -176px 0}
.ext-ruby {background-position: -176px 0}
.ext-txt {background-position: -192px 0}
.ext-zip {background-position: -208px 0}
table.diff {color: #888; border: 0; white-space: pre-wrap}
table.diff tbody th {color:#888; font-size: 11px; font-weight: normal; padding: 2px; vertical-align:top}
table.diff thead th.texttitle {background: #444; color: #fff; text-align:left; padding: 2px}
table.diff tbody td {width: 100%; font-family: Courier, monospace; vertical-align: top}
table.diff .delete {background: #0b0; color: #fff}
table.diff .insert {background: #b00; color: #fff}
table.diff th.author {display: none}

File diff suppressed because one or more lines are too long

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

View File

@@ -1,21 +1,75 @@
<?php
session_start();
// $_SESSION['userLevel'] = 10;
if ($_SESSION['userLevel'] == 0) {
die("Sorry, you need to be logged in to use ICErepo");
}
$docRoot = $_SERVER['DOCUMENT_ROOT'];
$version = "0.7.2";
// AUTHENTICATION
// Can either be done by oauth, or username & password.
// oauth
$token = "";
// Basic
$username = "username";
$password = "password";
// REPOS & SERVER DIRS
// Here you identify the repo location and related path on your server
// (the last param is to identify which dropdown option to select by default).
$repos = array(
"mattpass/dirTree",$docRoot."/dirTree","",
"mattpass/CodeMirror2",$docRoot."/CodeMirror2","selected"
);
?>
<!DOCTYPE html>
<html>
<head>
<title>Github plugin coming soon!</title>
<title>ICErepo v<?php echo $version;?></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script src="lib/base64.js"></script>
<script src="lib/github.js"></script>
<script src="ice-repo.js"></script>
<link rel="stylesheet" type="text/css" href="ice-repo.css">
</head>
<body style="font-family: arial, helvetica, swiss, verdana">
<body style="margin: 0; overflow: hidden" onLoad="doRepo(get('repos').value)">
<div class="blackMask" id="blackMask" style="display: block">
<div id="loadingMsgCenter" class="loadingMsgCenter">
<div id="loadingMsgContainer" class="loadingMsgContainer">
WORKING...
</div>
</div>
</div>
<b>ICErepo - Plugin coming soon!</b>
<br><br>
<div class="header">
<select name="repos" id="repos" onChange="doRepo(this.value)" style="margin: 20px 0 0 20px">
<?php
for ($i=0;$i<count($repos);$i+=3) {
echo '<option id="repo'.($i/3).'" value="'.$repos[$i].'@'.$repos[$i+1].'"';
echo $repos[$i+2]=="selected" ? ' selected' : '';
echo '>'.$repos[$i]."</option>\n";
}
?>
</select>
<div class="pullGithubSel" onClick="pullContent('selected')">Pull selected from Github</div>
<div class="version"><?php echo $version;?></div>
<img src="images/ice-repo.gif" alt="ICErepo" class="logo">
</div>
I'm creating a Github plugin right now which will allow you to sync website code with Github repos.
<br><br>
Full details and dev at:<br>
<a href="http://github.com/mattpass/ICErepo">http://github.com/mattpass/ICErepo</a>
<br><br>
<b>Expected launch date:</b><br>
Wed 22nd Aug
<form name="showRepo" action="contents.php" target="repo" method="POST">
<input type="hidden" name="token" value="<?php echo $token;?>">
<input type="hidden" name="username" value="<?php echo $username;?>">
<input type="hidden" name="password" value="<?php echo $password;?>">
<input type="hidden" name="repo" value="">
</form>
<iframe id="repo" class="repoFrame" frameborder="0"></iframe>
</body>
</html>

View File

@@ -0,0 +1,5 @@
// This code was written by Tyler Akins and has been placed in the
// public domain. It would be nice if you left this header intact.
// Base64 code from Tyler Akins -- http://rumkin.com
var Base64=function(){var e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",t={encode:function(t){var n="",r,i,s,o,u,a,f,l=0;do r=t.charCodeAt(l++),i=t.charCodeAt(l++),s=t.charCodeAt(l++),o=r>>2,u=(r&3)<<4|i>>4,a=(i&15)<<2|s>>6,f=s&63,isNaN(i)?a=f=64:isNaN(s)&&(f=64),n=n+e.charAt(o)+e.charAt(u)+e.charAt(a)+e.charAt(f);while(l<t.length);return n},decode:function(t){var n="",r,i,s,o,u,a,f,l=0;t=t.replace(/[^A-Za-z0-9\+\/\=]/g,"");do o=e.indexOf(t.charAt(l++)),u=e.indexOf(t.charAt(l++)),a=e.indexOf(t.charAt(l++)),f=e.indexOf(t.charAt(l++)),r=o<<2|u>>4,i=(u&15)<<4|a>>2,s=(a&3)<<6|f,n+=String.fromCharCode(r),a!=64&&(n+=String.fromCharCode(i)),f!=64&&(n+=String.fromCharCode(s));while(l<t.length);return n}};return t}();window.Base64=Base64

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,11 @@
// This file contains the HTTP Req Abs, Repo API and getRepo
// portions of Top Level API from github.com/michael/github.js
// ORIGINAL LIB:
// Github.js 0.7.0
// (c) 2012 Michael Aufreiter, Development Seed
// Github.js is freely distributable under the MIT license.
// For all details and documentation:
// http://substance.io/michael/github
(function(){var e,t="https://api.github.com";e=window.Github=function(n){function r(e,r,i,s,o){function u(){var e=t+r;return e+(/\?/.test(e)?"&":"?")+(new Date).getTime()}var a=new XMLHttpRequest;o||(a.dataType="json"),a.open(e,u()),a.onreadystatechange=function(){this.readyState==4&&(this.status>=200&&this.status<300||this.status===304?s(null,o?this.responseText:this.responseText?JSON.parse(this.responseText):!0):s({request:this,error:this.status}))},a.setRequestHeader("Accept","application/vnd.github.raw"),a.setRequestHeader("Content-Type","application/json;charset=UTF-8"),(n.auth=="oauth"&&n.token||n.auth=="basic"&&n.username&&n.password)&&a.setRequestHeader("Authorization",n.auth=="oauth"?"token "+n.token:"Basic "+Base64.encode(n.username+":"+n.password)),i?a.send(JSON.stringify(i)):a.send()}e.Repository=function(e){function u(e,t){if(e===o.branch&&o.sha)return t(null,o.sha);i.getRef("heads/"+e,function(n,r){o.branch=e,o.sha=r,t(n,r)})}var t=e.name,n=e.user,i=this,s="/repos/"+n+"/"+t,o={branch:null,sha:null};this.getRef=function(e,t){r("GET",s+"/git/refs/"+e,null,function(e,n){if(e)return t(e);t(null,n.object.sha)})},this.createRef=function(e,t){r("POST",s+"/git/refs",e,t)},this.deleteRef=function(t,n){r("DELETE",s+"/git/refs/"+t,e,n)},this.listBranches=function(e){r("GET",s+"/git/refs/heads",null,function(t,n){if(t)return e(t);e(null,_.map(n,function(e){return _.last(e.ref.split("/"))}))})},this.getBlob=function(e,t){r("GET",s+"/git/blobs/"+e,null,t,"raw")},this.getSha=function(e,t,n){if(t==="")return i.getRef("heads/"+e,n);i.getTree(e+"?recursive=true",function(e,r){var i=_.select(r,function(e){return e.path===t})[0];n(null,i?i.sha:null)})},this.getTree=function(e,t){r("GET",s+"/git/trees/"+e,null,function(e,n){if(e)return t(e);t(null,n.tree)})},this.postBlob=function(e,t){typeof e=="string"&&(e={content:e,encoding:"utf-8"}),r("POST",s+"/git/blobs",e,function(e,n){if(e)return t(e);t(null,n.sha)})},this.updateTree=function(e,t,n,i){var o={base_tree:e,tree:[{path:t,mode:"100644",type:"blob",sha:n}]};r("POST",s+"/git/trees",o,function(e,t){if(e)return i(e);i(null,t.sha)})},this.postTree=function(e,t){r("POST",s+"/git/trees",{tree:e},function(e,n){if(e)return t(e);t(null,n.sha)})},this.commit=function(t,n,i,u){var a={message:i,author:{name:e.username},parents:[t],tree:n};r("POST",s+"/git/commits",a,function(e,t){o.sha=t.sha;if(e)return u(e);u(null,t.sha)})},this.updateHead=function(e,t,n){r("PATCH",s+"/git/refs/heads/"+e,{sha:t},function(e,t){n(e)})},this.show=function(e){r("GET",s,null,e)},this.contents=function(e,t){r("GET",s+"/contents",{path:e},t)},this.fork=function(e){r("POST",s+"/forks",null,e)},this.createPullRequest=function(e,t){r("POST",s+"/pulls",e,t)},this.read=function(e,t,n){i.getSha(e,t,function(e,t){if(!t)return n("not found",null);i.getBlob(t,function(e,r){n(e,r,t)})})},this.remove=function(e,t,n){u(e,function(r,s){i.getTree(s+"?recursive=true",function(r,o){var u=_.reject(o,function(e){return e.path===t});_.each(u,function(e){e.type==="tree"&&delete e.sha}),i.postTree(u,function(r,o){i.commit(s,o,"Deleted "+t,function(t,r){i.updateHead(e,r,function(e){n(e)})})})})})},this.move=function(e,t,n,r){u(e,function(s,o){i.getTree(o+"?recursive=true",function(s,u){_.each(u,function(e){e.path===t&&(e.path=n),e.type==="tree"&&delete e.sha}),i.postTree(u,function(n,s){i.commit(o,s,"Deleted "+t,function(t,n){i.updateHead(e,n,function(e){r(e)})})})})})},this.write=function(e,t,n,r,s){u(e,function(o,u){if(o)return s(o);i.postBlob(n,function(n,o){if(n)return s(n);i.updateTree(u,t,o,function(t,n){if(t)return s(t);i.commit(u,n,r,function(t,n){if(t)return s(t);i.updateHead(e,n,s)})})})})}},e.Gist=function(e){var t=e.id,n=this,i="/gists/"+t;this.read=function(e){r("GET",i,null,function(t,n){e(t,n)})},this.delete=function(e){r("DELETE",i,null,function(t,n){e(t,n)})},this.fork=function(e){r("POST",i+"/fork",null,function(t,n){e(t,n)})},this.update=function(e,t){r("PATCH",i,e,function(e,n){t(e,n)})}},this.getRepo=function(t,n){return new e.Repository({user:t,name:n})}}}).call(this)

12
plugins/ice-repo/lib/underscore-min.js vendored Normal file
View File

@@ -0,0 +1,12 @@
// This file contains the select, reject, forEach and has functions
// from underscore.js, then minified to make it extra tiny
// Underscore.js 1.3.3
// (c) 2009-2012 Jeremy Ashkenas, DocumentCloud Inc.
// Underscore may be freely distributed under the MIT license.
// Portions of Underscore are inspired or borrowed from Prototype,
// Oliver Steele's Functional, and John Resig's Micro-Templating.
// For all details and documentation:
// http://documentcloud.github.com/underscore
(function(){var e=this,t=Array.prototype,n=Object.prototype,r=t.forEach,i=t.filter,s=n.hasOwnProperty,o={};_=function(obj) {return new wrapper(obj);};_.filter=_.select=function(e,t,n){var r=[];return e==null?r:i&&e.filter===i?e.filter(t,n):(u(e,function(e,i,s){t.call(n,e,i,s)&&(r[r.length]=e)}),r)},_.reject=function(e,t,n){var r=[];return e==null?r:(u(e,function(e,i,s){t.call(n,e,i,s)||(r[r.length]=e)}),r)};var u=_.each=_.forEach=function(e,t,n){if(e==null)return;if(r&&e.forEach===r)e.forEach(t,n);else if(e.length===+e.length){for(var i=0,s=e.length;i<s;i++)if(i in e&&t.call(n,e[i],i,e)===o)return}else for(var u in e)if(_.has(e,u)&&t.call(n,e[u],u,e)===o)return};_.has=function(e,t){return s.call(e,t)}}).call(this)