This commit is contained in:
Varun 2020-11-02 10:26:36 +05:30
parent ef8680db7b
commit 53e399c3ac
No known key found for this signature in database
GPG key ID: 93FB46DCF16E0D6F
2 changed files with 27 additions and 0 deletions

View file

@ -8,6 +8,7 @@ require_once __DIR__ . '/php/inputvar.php';
require_once __DIR__ . '/php/env.php';
require_once __DIR__ . '/php/general-functions.php';
define( 'GITHUB_REPOSITORY', gh_env( 'GITHUB_REPOSITORY' ) . '/' );
define( 'GH_WORKSPACE', gh_env( 'GITHUB_WORKSPACE' ) . '/' );
define( 'GH_REF_BRANCH', trim( str_replace( 'refs/heads/', '', gh_env( 'GITHUB_REF' ) ) ) );

View file

@ -55,4 +55,30 @@ function validate_save_path( $dest_path, $default_filename = '' ) {
@mkdir( GH_WORKSPACE . $base_dirname, 0777, true );
}
return $dest_path;
}
function github_url( $raw = false, $repository = false, $branch = false, $file_path = false ) {
$url = ( $raw ) ? 'https://raw.githubusercontent.com/' : 'https://github.com/';
if ( false !== $repository ) {
$repository = ( empty( $repository ) ) ? GITHUB_REPOSITORY : $repository;
$url .= $repository . '/';
}
if ( false !== $branch ) {
$branch = ( empty( $branch ) ) ? GH_REF_BRANCH : $branch;
$url .= ( $raw ) ? 'blob/' : '';
$url .= $branch . '/';
}
if ( false !== $file_path ) {
$url .= ( ! empty( $file_path ) ) ? $file_path : '';
}
return $url;
}
function gh_commit( $file, $commit_msg = 'File Updated' ) {
shell_exec( 'git add -f ' . GH_WORKSPACE . $file );
shell_exec( 'git commit -m "' . $commit_msg . '" ' );
}