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

Add a command to remove old/unneeded git branches #11

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions dop
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

require __DIR__ . '/vendor/autoload.php';

use DrupalPatchUtils\Command\CleanupGitBranches;
use DrupalPatchUtils\Command\Configure;
use DrupalPatchUtils\Command\CreateIssue;
use DrupalPatchUtils\Command\IssuePruner;
Expand All @@ -29,4 +30,5 @@ $application->add(new Login());
$application->add(new Logout());
$application->add(new RemainingCriticals());
$application->add(new IssuePruner());
$application->add(new CleanupGitBranches());
$application->run();
59 changes: 59 additions & 0 deletions src/DrupalPatchUtils/Command/CleanupGitBranches.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

/**
* @file
* Contains \DrupalPatchUtils\Command\CleanupGitBranches.
*/

namespace DrupalPatchUtils\Command;

use DrupalPatchUtils\DoBrowser;
use DrupalPatchUtils\DoFormBase;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Process\Process;

class CleanupGitBranches extends CommandBase {

/**
* {@inheritdoc}
*/
protected function configure()
{
$this
->setName('cleanupGitBranches')
->setAliases(['cgb'])
->setDescription('Removes all git branches which has closed issues.');
}

/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output) {
$process = new Process('git branch');
$process->run();

$branches = array_map('trim', explode("\n", $process->getOutput()));

$browser = new DoBrowser();
if (!$browser->loggedIn()) {
$browser->login($this->getConfig()->getDrupalUser(), $this->ask($output, "Enter your Drupal.org password: ", '', TRUE));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to use the new tfa supporting code. Just do $browser = $this->login(OutputInterface $output);

}

// Find all branches which don't need further work on.
foreach ($branches as $branch) {
if (is_numeric($branch)) {
$issue = $this->getIssue($branch);

$form = $browser->getCommentForm($issue->getUri());
if (in_array($form->getStatus(), [DoFormBase::STATUS_CLOSED_DUPLICATE, DoFormBase::STATUS_CLOSED_WONT_FIX, DoFormBase::STATUS_CLOSED_WORKS, DoFormBase::STATUS_CLOSED_CANT_REPRODUCE, DoFormBase::STATUS_CLOSED_FIXED])) {
$output->writeln(sprintf("Remove branch: %s", $branch));
$process = new Process(sprintf('git branch -d %s', $branch));
$process->run();
}
}
}
}


}
5 changes: 5 additions & 0 deletions src/DrupalPatchUtils/DoFormBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,10 @@ protected function setStatus($value) {
return $this;
}

public function getStatus() {
$status = $this->form->get('field_issue_status[und]');
return $status->getValue();
}

}