function version($newVersion) { $token = get_token(); $user = get_user(); $repo = get_repo(); $oldVersion = Boris::VERSION; $phar = "boris.phar"; printf("Building version v%s...\n", $newVersion); printf(" Updating Boris::VERSION (%s) to %s...\n", $oldVersion, $newVersion); `perl -pi -e 's/{$oldVersion}/{$newVersion}/' lib/Boris/Boris.php README.md`; printf(" Committing changes...\n"); `git commit -am "Version bump to {$newVersion}"`; printf(" Pushing changes upstream...\n"); `git push`; printf(" Creating tag v%s...\n", $newVersion); `git tag -a "v{$newVersion}" -m "Auto-generated tag"`; printf(" Pushing tags upstream...\n"); `git push --tags`; printf(" Creating release on github...\n"); $response = `curl \\\n -sL \\\n -XPOST \\\n -H "Authorization: token {$token}" \\\n --data-binary '{"tag_name":"v{$newVersion}"}' \\\n https://api.github.com/repos/{$user}/{$repo}/releases`; $json = json_decode($response, true); $id = $json['id']; if (empty($id)) { printf("Failed.\n"); printf("%s\n", $response); exit(1); } printf(" Building phar...\n"); `box build`; printf("Uploading phar to GitHub...\n"); `curl -XPOST \\\n -sL \\\n -H "Authorization: token {$token}" \\\n -H "Content-Type: application/octet-stream" \\\n --data-binary @{$phar} \\\n https://uploads.github.com/repos/{$user}/{$repo}/releases/{$id}/assets?name={$phar}`; printf("Done.\n"); }
/** * Move modified files from a temporary (working) repository on top of another (template) repository * @param $param[1] temporary repository * @param $param['repo'] repository to switch to * @param $param['clean_before'] run "make clean" before determining the modified files (default: true) * @param $param['clean_after'] run "make clean" after determining the modified files (default: true) */ function api_post_temp_switch_repo($param = array()) { $temp = $param[1]; if (!@is_dir(tmp_dir($temp))) { router_error_404('Cannot get ' . $temp); } if (empty($param['repo'])) { router_error_400('Required parameter repo missing or empty'); } else { $repo = $param['repo']; } // client can specify whether to run "make clean" before or after the switch if (isset($param['clean_before'])) { $clean_before = (bool) $param['clean_before']; } else { $clean_before = true; } if (isset($param['clean_after'])) { $clean_after = (bool) $param['clean_after']; } else { $clean_after = true; } // create a new repository under a temporary name $staging = get_repo($repo); if ($staging === false) { router_error_404('Cannot get ' . $repo); } // clean, if requested if ($clean_before) { make_run($temp, 'clean'); } // copy the modified files over $old_umask = @umask(00); foreach (repo_get_modified_files($temp) as $fn) { // make sure the containing directories exist create_containing_dir(tmp_dir($staging) . '/' . $fn); // copy @copy(tmp_dir($temp) . '/' . $fn, tmp_dir($staging) . '/' . $fn); } @umask($old_umask); // remove original repository if (false === rm_recursive(tmp_dir($temp))) { router_error_500('Cannot delete ' . $temp); } // move new repository to location of original repository if (false === @rename(tmp_dir($staging), tmp_dir($temp))) { router_error_500('Cannot rename ' . $staging . ' to ' . $temp); } // clean, if requested if ($clean_after) { make_run($temp, 'clean'); } return true; }
function github_post_push($param = array()) { $commit_msg_prefix = 'Regenerate output files'; $payload = json_decode($param['payload'], true); // prevent error on "ping" notifications if (!isset($payload['head_commit']['message'])) { return 'Not a commit'; } // prevent recursions if (substr($payload['head_commit']['message'], 0, strlen($commit_msg_prefix)) === $commit_msg_prefix) { return 'Not acting on my own changes'; } // ref is like "refs/heads/master" $branch = @array_pop(explode('/', $payload['ref'])); $tmp_key = get_repo($payload['repository']['clone_url'], $branch, true); if ($tmp_key === false) { router_error_500('Error getting branch ' . $branch . ' of ' . $payload['repository']['clone_url']); } $ret_val = make_run(tmp_dir($tmp_key), 'all', $out); // run "make clean" to remove temporary files (but not output files, that's the idea) make_run(tmp_dir($tmp_key), 'clean'); $modified = repo_get_modified_files($tmp_key); if (empty($modified) && $ret_val === 0) { // nothing to commit, no error return 'No changes'; } $ret = repo_stage_files($tmp_key, $modified); if ($ret === false) { router_error_500('Error staging files ' . implode(', ', $modified) . ' to ' . $tmp_key); } // setup commit message $msg = $commit_msg_prefix; // this needs to come first if ($ret_val !== 0) { $msg .= ' (error)' . "\n\n"; $msg .= 'The process returned error code ' . $ret_val . '. '; } else { $msg .= "\n\n"; } $msg .= 'The version of Pandoc used is ' . get_pandoc_version() . '.' . "\n\n"; $msg .= 'Output:' . "\n"; $msg .= implode("\n", $out); $ret = repo_commit($tmp_key, $msg); if ($ret === false) { router_error_500('Error committing ' . $tmp_key); } $ret = repo_push($tmp_key, $payload['repository']['ssh_url']); if ($ret === false) { router_error_500('Error pushing to ' . $payload['repository']['ssh_url']); } // count the number of collaborators $seen = array(); foreach ($payload['commits'] as $commit) { if (!in_array($commit['author']['email'], $seen)) { $seen[] = $commit['author']['email']; } } if (1 < $seen) { // subtract the sausage machine $seen--; } // XXX (later): create helper functions, make atomic $s = @file_get_contents(rtrim(config('content_dir', 'content'), '/') . '/projects.json'); $projects = @json_decode($s, true); if (!@is_array($projects)) { $projects = array(); } foreach ($projects as &$p) { if ($payload['repository']['full_name'] === $p['github_repo']) { $p['updated'] = time(); $p['collaborators'] = count($seen); } } $old_umask = @umask(00); @file_put_contents(rtrim(config('content_dir', 'content'), '/') . '/projects.json', json_encode($projects)); @umask($old_umask); return 'Success'; }
<head> <?php include_once "../includes/head_tags.php"; require_once "../includes/repoapi.inc"; ?> <title>Secure Your Images - ToyApp</title> </head> <body class="auth-user"> <?php include_once "../includes/header.inc"; ?> <div id="dash-board"> <ul class="dash-options"> <?php $uinfo = get_user_info(); $file_array = get_repo($uinfo['uid']); foreach ($file_array as $file) { $f = explode('/', $file['url'])[3]; ?> <li><a href="secure_reconstruct.php?f=<?php echo $f; ?> &i=<?php echo $file['fid']; ?> ">File <?php echo $file['fid']; ?> </a></li> <?php }