This commit is contained in:
James 2019-11-10 15:02:44 +00:00
parent 5352a3ea37
commit 3fcd44e9ce
9 changed files with 142 additions and 130 deletions

View File

@ -1,12 +1,13 @@
#!/usr/bin/php #!/usr/bin/php
<?php <?php
/****************** /*
* close ALL issues * get ALL open issues
******************/ * 1. close thm
*/
// load the config, create the connection and load the repo sepcified on the cmd line args // load the config, create the connection and load the repo sepcified on the cmd line args
// we will then have $client and $repo available // we will then have $client and $repo available
require('setup.php'); require 'setup.php';
// close all issues // close all issues
// we use getIssues() here rather than forIssues() (see https://git.jhodges.co.uk/jhodges/GiteaBot/issues/1) // we use getIssues() here rather than forIssues() (see https://git.jhodges.co.uk/jhodges/GiteaBot/issues/1)

View File

@ -1,19 +1,19 @@
#!/usr/bin/php #!/usr/bin/php
<?php <?php
/**************************************************** /*
* This will loop through a list of label names * This will loop through a list of label names
* If the label exists on the repo, delete the label * If the label exists on the repo, delete the label
****************************************************/ */
// load the config, create the connection and load the repo sepcified on the cmd line args // load the config, create the connection and load the repo sepcified on the cmd line args
// we will then have $client and $repo available // we will then have $client and $repo available
require('setup.php'); require 'setup.php';
//define the repeat terms //define the repeat terms
$names = [ $names = [
'janurary', 'feburary', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december', 'janurary', 'feburary', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december',
'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday',
'daily','weekly','fortnightly','monthly','yearly' 'daily', 'weekly', 'fortnightly', 'monthly', 'yearly',
]; ];
//loop through the names //loop through the names

View File

@ -1,21 +1,21 @@
#!/usr/bin/php #!/usr/bin/php
<?php <?php
/************************************************** /*
* this will process all issues titled "delete me": * this will process all issues titled "delete me":
* 1. remove all labels * 1. remove all labels
* 2. close the issue * 2. close the issue
* 3. change the title to "deleted" * 3. change the title to "deleted"
**************************************************/ */
// load the config, create the connection and load the repo sepcified on the cmd line args // load the config, create the connection and load the repo sepcified on the cmd line args
// we will then have $client and $repo available // we will then have $client and $repo available
require('setup.php'); require 'setup.php';
// loop through all matching issues // loop through all matching issues
// we use getIssues() here rather than forIssues() (see https://git.jhodges.co.uk/jhodges/GiteaBot/issues/1) // we use getIssues() here rather than forIssues() (see https://git.jhodges.co.uk/jhodges/GiteaBot/issues/1)
foreach ($repo->getIssues(['q' => 'delete me']) as $issue) { foreach ($repo->getIssues(['q' => 'delete me']) as $issue) {
// check for exact match // check for exact match
if($issue->title=='delete me'){ if ('delete me' == $issue->title) {
// remove all labels // remove all labels
foreach ($issue->labels as $label) { foreach ($issue->labels as $label) {
$issue->removeLabel($label); $issue->removeLabel($label);
@ -25,4 +25,4 @@ foreach($repo->getIssues(['q'=>'delete me']) as $issue){
$issue->title = 'deleted'; $issue->title = 'deleted';
$issue->save(); $issue->save();
} }
}; }

View File

@ -1,14 +1,14 @@
#!/usr/bin/php #!/usr/bin/php
<?php <?php
/************************************************************** /*
* This will delete all comments that match a specific keyword * This will delete all comments that match a specific keyword
* 1. Process all issues that match "NAG!": * 1. Process all issues that match "NAG!":
* 2. Delete any comments that body exactly match "NAG!" * 2. Delete any comments that body exactly match "NAG!"
**************************************************************/ */
// load the config, create the connection and load the repo sepcified on the cmd line args // load the config, create the connection and load the repo sepcified on the cmd line args
// we will then have $client and $repo available // we will then have $client and $repo available
require('setup.php'); require 'setup.php';
// loop through the issues // loop through the issues
// we use getIssues() here rather than forIssues() (see https://git.jhodges.co.uk/jhodges/GiteaBot/issues/1) // we use getIssues() here rather than forIssues() (see https://git.jhodges.co.uk/jhodges/GiteaBot/issues/1)
@ -16,7 +16,7 @@ foreach($repo->getIssues(['q'=>'NAG!']) as $issue){
// loop through the current issues comments // loop through the current issues comments
foreach ($issue->getComments() as $comment) { foreach ($issue->getComments() as $comment) {
// if the comment body matches // if the comment body matches
if($comment->body=='NAG!'){ if ('NAG!' == $comment->body) {
// delete the commend // delete the commend
$repo->deleteComment($comment); $repo->deleteComment($comment);
} }

View File

@ -1,15 +1,15 @@
#!/usr/bin/php #!/usr/bin/php
<?php <?php
/******************************************************* /*
* This will loop through all issues and add some custom * This will loop through all issues and add some custom
* text to the issue body. It will use a placeholder so * text to the issue body. It will use a placeholder so
* that it can be automatically updated without replacing * that it can be automatically updated without replacing
* the whole issue body * the whole issue body
********************************************************/ */
// load the config, create the connection and load the repo sepcified on the cmd line args // load the config, create the connection and load the repo sepcified on the cmd line args
// we will then have $client and $repo available // we will then have $client and $repo available
require('setup.php'); require 'setup.php';
//this is the function to generate the custom text //this is the function to generate the custom text
$text = function ($issue) { $text = function ($issue) {
@ -19,11 +19,11 @@ $text=function($issue){
//callback function to add/replace the tag with our text //callback function to add/replace the tag with our text
$tmp = function ($issue) use ($text) { $tmp = function ($issue) use ($text) {
// add a tag to the body if to doesn't exist // add a tag to the body if to doesn't exist
if( strpos($issue->body,'<!--BOT-->')===false ){ if (false === strpos($issue->body, '<!--BOT-->')) {
$issue->body .= '<hr/><!--BOT--><!--ENDBOT-->'; $issue->body .= '<hr/><!--BOT--><!--ENDBOT-->';
} }
//replace the tag contents with the result from our $text function //replace the tag contents with the result from our $text function
$issue->body=preg_replace("#<!--BOT-->.*?<!--ENDBOT-->#s",'<!--BOT-->'.$text($issue).'<!--ENDBOT-->',$issue->body); $issue->body = preg_replace('#<!--BOT-->.*?<!--ENDBOT-->#s', '<!--BOT-->'.$text($issue).'<!--ENDBOT-->', $issue->body);
$issue->save(); $issue->save();
}; };

View File

@ -1,30 +1,40 @@
#!/usr/bin/php #!/usr/bin/php
<?php <?php
/*************************************************************************************************************** /*
* 1. Adds a 'no-milestone' label to any issues with no milestone * 1. Adds a 'no-milestone' label to any issues with no milestone
* 2. Removes the 'no-milestone' label if present on an issue with a milestone * 2. Removes the 'no-milestone' label if present on an issue with a milestone
* 3. Adds a 'no-label' label to any issues with no labels (excluding 'no-label' and 'no-milestone') * 3. Adds a 'no-label' label to any issues with no labels (excluding 'no-label' and 'no-milestone')
* 4. Removes the 'no-label' label if present on an issue with a label (excluding 'no-label' and 'no-milestone') * 4. Removes the 'no-label' label if present on an issue with a label (excluding 'no-label' and 'no-milestone')
****************************************************************************************************************/ */
// load the config, create the connection and load the repo sepcified on the cmd line args // load the config, create the connection and load the repo sepcified on the cmd line args
// we will then have $client and $repo available // we will then have $client and $repo available
require('setup.php'); require 'setup.php';
//get the labels of interest //get the labels of interest
$nolabelLabel = $repo->getLabelByName('no-label'); $nolabelLabel = $repo->getLabelByName('no-label');
if(!$nolabelLabel) die ("Can't find 'no-label' label in repo\n"); if (!$nolabelLabel) {
die("Can't find 'no-label' label in repo\n");
}
$nomilestoneLabel = $repo->getLabelByName('no-milestone'); $nomilestoneLabel = $repo->getLabelByName('no-milestone');
if(!$nomilestoneLabel) die ("Can't find 'no-milestone' label in repo\n"); if (!$nomilestoneLabel) {
die("Can't find 'no-milestone' label in repo\n");
}
//define the function to process each issue //define the function to process each issue
$callback = function ($issue) use ($nolabelLabel,$nomilestoneLabel) { $callback = function ($issue) use ($nolabelLabel,$nomilestoneLabel) {
// do the no-label thing // do the no-label thing
$labelCount = count($issue->labels); $labelCount = count($issue->labels);
if($issue->hasLabel($nolabelLabel)) $labelCount--; //dont count the no-label label if ($issue->hasLabel($nolabelLabel)) {
if($nomilestoneLabel && $issue->hasLabel($nomilestoneLabel)) $labelCount--; //dont count the no-milestone label --$labelCount;
if($labelCount==0 && !$issue->hasLabel($nolabelLabel) ){ }
//dont count the no-label label
if ($nomilestoneLabel && $issue->hasLabel($nomilestoneLabel)) {
--$labelCount;
}
//dont count the no-milestone label
if (0 == $labelCount && !$issue->hasLabel($nolabelLabel)) {
$issue->addLabel($nolabelLabel); $issue->addLabel($nolabelLabel);
} elseif ($labelCount > 0 && $issue->hasLabel($nolabelLabel)) { } elseif ($labelCount > 0 && $issue->hasLabel($nolabelLabel)) {
$issue->removeLabel($nolabelLabel); $issue->removeLabel($nolabelLabel);

View File

@ -1,17 +1,17 @@
<?php <?php
require(__DIR__.'/../vendor/autoload.php');
require __DIR__.'/../vendor/autoload.php';
use JHodges\GiteaBot\Client; use JHodges\GiteaBot\Client;
$config=require(__DIR__.'/config.php'); $config = require __DIR__.'/config.php';
//pass cmd line args //pass cmd line args
if ($argc < 3) { if ($argc < 3) {
die(basename(__FILE__)." <USER> <REPO> [debug]\n"); die(basename(__FILE__)." <USER> <REPO> [debug]\n");
} }
$debug = ($argc==4 && $argv[3]=='debug'); $debug = (4 == $argc && 'debug' == $argv[3]);
//open connection and repo //open connection and repo
$client = new Client($config['url'], $config['user'], $config['pass'], $debug); $client = new Client($config['url'], $config['user'], $config['pass'], $debug);
$repo = $client->getRepo($argv[1], $argv[2]); $repo = $client->getRepo($argv[1], $argv[2]);

View File

@ -2,7 +2,7 @@
<?php <?php
// load the config, create the connection and load the repo sepcified on the cmd line args // load the config, create the connection and load the repo sepcified on the cmd line args
// we will then have $client and $repo available // we will then have $client and $repo available
require('setup.php'); require 'setup.php';
//get the test label or create if not exist //get the test label or create if not exist
if (!$label = $repo->getLabelByName('Test')) { if (!$label = $repo->getLabelByName('Test')) {
@ -12,7 +12,7 @@ if(!$label=$repo->getLabelByName('Test')){
//create a test issue //create a test issue
$issue = $repo->createIssue([ $issue = $repo->createIssue([
'title' => 'Test', 'title' => 'Test',
'body'=>'Just testing' 'body' => 'Just testing',
]); ]);
$issue->addLabel($label); $issue->addLabel($label);
$issue->addComment('Test comment'); $issue->addComment('Test comment');

View File

@ -1,13 +1,13 @@
#!/usr/bin/php #!/usr/bin/php
<?php <?php
/******************************************************* /*
* Creats a csv report of times spend on issues for * Creats a csv report of times spend on issues for
* a specific month of a specific user. * a specific month of a specific user.
********************************************************/ */
// load the config, create the connection and load the repo sepcified on the cmd line args // load the config, create the connection and load the repo sepcified on the cmd line args
// we will then have $client and $repo available // we will then have $client and $repo available
require('setup.php'); require 'setup.php';
// Build a crazy id to number lookup table // Build a crazy id to number lookup table
// https://github.com/go-gitea/gitea/issues/8513 // https://github.com/go-gitea/gitea/issues/8513
@ -37,14 +37,15 @@ foreach($repo->getTimesByUsername($name) as $time){
$sums[$number] = [ $sums[$number] = [
'id' => $number, 'id' => $number,
'name' => $issue->title, 'name' => $issue->title,
'time'=>0 'time' => 0,
]; ];
} }
$sums[$number]['time'] += $time->time; $sums[$number]['time'] += $time->time;
} }
} }
function format_time($t){ function format_time($t)
{
return sprintf('%02d:%02d:%02d', floor($t / 3600), ($t / 60) % 60, $t % 60); return sprintf('%02d:%02d:%02d', floor($t / 3600), ($t / 60) % 60, $t % 60);
} }