Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature auto suggest commit messages #129

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
4 changes: 4 additions & 0 deletions assets/js/revisr-staging.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ jQuery(document).ready(function($) {

$.post(ajaxurl, data, function(response) {
document.getElementById('pending_files_result').innerHTML = response;
old_title = document.getElementById('title');
new_title = document.getElementById('title-tmp');
document.getElementById('titlewrap').replaceChild(new_title, old_title);
new_title.id = 'title';
});

}
Expand Down
13 changes: 13 additions & 0 deletions classes/class-revisr-admin-pages.php
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,19 @@ public function site5_notice() {
<?php _e( 'Sponsored by', 'revisr' ); ?>
<a href="http://www.site5.com/" target="_blank"><img id="site5_logo" src="<?php echo REVISR_URL . 'assets/img/site5.png'; ?>" width="80" /></a>
</div>

<style>
#TB_window {
width: 95% !important;
left: 0px !important;
margin-left: 52px !important;
}
#TB_ajaxContent {
width: 98% !important;
height: 95% !important;
font-family: monospace;
}
</style>
<?php
}

Expand Down
2 changes: 1 addition & 1 deletion classes/class-revisr-git.php
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ public function merge( $branch ) {
* @param array $commits The commits we're pulling (used in callback).
*/
public function pull( $commits = array() ) {
$this->reset();
//$this->reset();
$pull = $this->run( 'pull', array( '-Xtheirs', '--quiet', $this->remote, $this->branch ), __FUNCTION__, $commits );
return $pull;
}
Expand Down
67 changes: 62 additions & 5 deletions classes/class-revisr-meta-boxes.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,23 +61,47 @@ public function pending_files() {
check_ajax_referer( 'staging_nonce', 'security' );
$output = revisr()->git->status();
$total_pending = count( $output );
$text = sprintf( __( 'There are <strong>%s</strong> untracked files that can be added to this commit.', 'revisr' ), $total_pending, revisr()->git->branch );
$commit_items = array(); // Categorize the changed files into categories for automated commit message creation
$unstaged = array(); // Store changes that do not match wp-content/plugins/plugin-name/ or wp-content/plugins/plugin-name.php
$text = sprintf( __( 'There are <strong>%s</strong> untracked files that can be added to this commit.', 'revisr' ), $total_pending, revisr()->git->branch );
echo "<br>" . $text . "<br><br>";
_e( 'Use the boxes below to select the files to include in this commit. Only files in the "Staged Files" section will be included.<br>Double-click files marked as "Modified" to view the changes to the file.<br><br>', 'revisr' );
if ( is_array( $output ) ) {
?>
<!-- Staging -->
<div class="stage-container">
<p><strong><?php _e( 'Staged Files', 'revisr' ); ?></strong></p>
<select id='staged' multiple="multiple" name="staged_files[]" size="6">
<select id='staged' multiple="multiple" name="staged_files[]" size="15" style="resize: vertical;">
<?php
// Clean up output from git status and echo the results.
foreach ( $output as $result ) {
$result = str_replace( '"', '', $result );
$short_status = substr( $result, 0, 3 );
$file = substr( $result, 3 );
$status = Revisr_Git::get_status( $short_status );
echo "<option class='pending' value='{$result}'>{$file} [{$status}]</option>";
$status = Revisr_Git::get_status( $short_status );
$item = "<option class='pending' value='{$result}'>{$file} [{$status}]</option>";

if ( preg_match('/wp-content\/plugins\/((.*?)\/|(.*?)\.php)/', $file, $match) ) { // Match plugin name, example : wp-content/plugins/plugin-name/ or wp-content/plugins/plugin-name.php
$plugin_matched = !empty($match[2]) ? $match[2] : $match[3];

if( $status == 'Untracked' && isset($commit_items['Modified']) ) { // New file or folder created in existing plugin is not added to commit_items if plugin name is in modified
if(in_array($plugin_matched, $commit_items['Modified'])) {
echo $item;
continue;
}
}

if( !isset($commit_items[$status]) ) { // No status yet
$commit_items[$status][] = $plugin_matched;
} else if( !in_array($plugin_matched, $commit_items[$status]) ) { // Prevent duplicates
$commit_items[$status][] = $plugin_matched;
}

echo $item;
} else { // No plugin matched, move to unstaged
$unstaged[] = $item;
}

}
?>
</select>
Expand All @@ -92,7 +116,15 @@ public function pending_files() {
<!-- Unstaging -->
<div class="stage-container">
<p><strong><?php _e( 'Unstaged Files', 'revisr' ); ?></strong></p>
<select id="unstaged" multiple="multiple" name="unstaged_files[]" size="6">
<select id="unstaged" multiple="multiple" name="unstaged_files[]" size="15" style="resize: vertical;">
<?php
// Echo all files that are in unstaged array
if( !empty($unstaged) ) {
foreach( $unstaged as $option ) {
echo $option;
}
}
?>
</select>
<div class="stage-nav">
<input id="stage-file" type="button" class="button button-primary stage-nav-button" value="<?php _e( 'Stage Selected', 'revisr' ); ?>" onclick="stage_file()" />
Expand All @@ -101,6 +133,31 @@ public function pending_files() {
</div>
</div><!-- /Unstaging -->

<?php
// Improve commit message
$commit_msg = "";
foreach( $commit_items as $status => $plugins ) {
switch($status) {
case 'Modified':
$commit_msg .=" Plugin updates";
break;
case 'Untracked':
$commit_msg .=" New plugins";
break;
case 'Deleted':
$commit_msg .=" Deleted plugins";
break;
default:
$commit_msg .=" " . $status;
}
$commit_msg .= " - " . implode(", ", $plugins); // Build commit message from plugin names and statuses
}
$commit_msg = trim($commit_msg);
?>

<!-- New input for commit msg -->
<input type="text" name="post_title" size="30" value="<?php echo $commit_msg; ?>" id="title-tmp" spellcheck="true" autocomplete="off" placeholder="Enter a message for your commit">

<?php
}
exit();
Expand Down
14 changes: 7 additions & 7 deletions classes/class-revisr-process.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,18 +238,18 @@ public function pull() {
Revisr_Admin::verify_nonce( $_REQUEST['revisr_dashboard_nonce'], 'revisr_dashboard_nonce' );

// Fetch the changes so we can compare them.
revisr()->git->reset();
//revisr()->git->reset();
revisr()->git->fetch();

// Build an array of the commits we don't have locally.
$commits_since = revisr()->git->run( 'log', array( revisr()->git->branch . '..' . revisr()->git->remote . '/' . revisr()->git->branch, '--pretty=oneline' ) );

// Maybe backup database.
if ( revisr()->git->get_config( 'revisr', 'import-pulls' ) === 'true' ) {
revisr()->db->backup();
$undo_hash = revisr()->git->current_commit();
revisr()->git->set_config( 'revisr', 'last-db-backup', $undo_hash );
}
// if ( revisr()->git->get_config( 'revisr', 'import-pulls' ) === 'true' ) {
// revisr()->db->backup();
// $undo_hash = revisr()->git->current_commit();
// revisr()->git->set_config( 'revisr', 'last-db-backup', $undo_hash );
// }

// Fires before the changes are pulled.
do_action( 'revisr_pre_pull', $commits_since );
Expand Down
6 changes: 3 additions & 3 deletions revisr.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
*
* Plugin Name: Revisr
* Plugin URI: https://revisr.io/
* Description: A plugin that allows users to manage WordPress websites with Git repositories.
* Version: 2.0.2
* Description: A plugin that allows users to manage WordPress websites with Git repositories. FV: Removing the db backup from pull function and improving the admin UI a bit
* Version: 100.2.0.2.fv
* Author: Expanded Fronts, LLC
* Author URI: http://expandedfronts.com/
* License: GPL-3.0+
Expand Down Expand Up @@ -228,7 +228,7 @@ private function define_constants() {
define( 'REVISR_URL', plugin_dir_url( REVISR_FILE ) );

// The current version of the plugin.
define( 'REVISR_VERSION', '2.0.2' );
define( 'REVISR_VERSION', '2.0.3' );
}

/**
Expand Down