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
<?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
// we will then have $client and $repo available
require('setup.php');
require 'setup.php';
// close all issues
// 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
<?php
/****************************************************
/*
* This will loop through a list of label names
* 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
// we will then have $client and $repo available
require('setup.php');
require 'setup.php';
//define the repeat terms
$names = [
'janurary', 'feburary', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december',
'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday',
'daily','weekly','fortnightly','monthly','yearly'
'daily', 'weekly', 'fortnightly', 'monthly', 'yearly',
];
//loop through the names

View File

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

View File

@ -1,14 +1,14 @@
#!/usr/bin/php
<?php
/**************************************************************
/*
* This will delete all comments that match a specific keyword
* 1. Process all issues that 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
// we will then have $client and $repo available
require('setup.php');
require 'setup.php';
// loop through the issues
// 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
foreach ($issue->getComments() as $comment) {
// if the comment body matches
if($comment->body=='NAG!'){
if ('NAG!' == $comment->body) {
// delete the commend
$repo->deleteComment($comment);
}

View File

@ -1,15 +1,15 @@
#!/usr/bin/php
<?php
/*******************************************************
/*
* This will loop through all issues and add some custom
* text to the issue body. It will use a placeholder so
* that it can be automatically updated without replacing
* the whole issue body
********************************************************/
*/
// load the config, create the connection and load the repo sepcified on the cmd line args
// we will then have $client and $repo available
require('setup.php');
require 'setup.php';
//this is the function to generate the custom text
$text = function ($issue) {
@ -19,11 +19,11 @@ $text=function($issue){
//callback function to add/replace the tag with our text
$tmp = function ($issue) use ($text) {
// 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-->';
}
//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();
};

View File

@ -1,30 +1,40 @@
#!/usr/bin/php
<?php
/***************************************************************************************************************
/*
* 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
* 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')
****************************************************************************************************************/
*/
// load the config, create the connection and load the repo sepcified on the cmd line args
// we will then have $client and $repo available
require('setup.php');
require 'setup.php';
//get the labels of interest
$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');
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
$callback = function ($issue) use ($nolabelLabel,$nomilestoneLabel) {
// do the no-label thing
$labelCount = count($issue->labels);
if($issue->hasLabel($nolabelLabel)) $labelCount--; //dont count the no-label label
if($nomilestoneLabel && $issue->hasLabel($nomilestoneLabel)) $labelCount--; //dont count the no-milestone label
if($labelCount==0 && !$issue->hasLabel($nolabelLabel) ){
if ($issue->hasLabel($nolabelLabel)) {
--$labelCount;
}
//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);
} elseif ($labelCount > 0 && $issue->hasLabel($nolabelLabel)) {
$issue->removeLabel($nolabelLabel);

View File

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

View File

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

View File

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