fix cs
This commit is contained in:
parent
5352a3ea37
commit
3fcd44e9ce
@ -1,16 +1,17 @@
|
||||
#!/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)
|
||||
foreach($repo->getIssues() as $issue){
|
||||
$issue->state='closed';
|
||||
$issue->save();
|
||||
foreach ($repo->getIssues() as $issue) {
|
||||
$issue->state = 'closed';
|
||||
$issue->save();
|
||||
}
|
||||
|
@ -1,27 +1,27 @@
|
||||
#!/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'
|
||||
$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',
|
||||
];
|
||||
|
||||
//loop through the names
|
||||
foreach($names as $name){
|
||||
foreach ($names as $name) {
|
||||
//see if label exists?
|
||||
$label=$repo->getLabelByName($name);
|
||||
if($label){ //it exists
|
||||
//delete it
|
||||
$repo->deleteLabel($label);
|
||||
$label = $repo->getLabelByName($name);
|
||||
if ($label) { //it exists
|
||||
//delete it
|
||||
$repo->deleteLabel($label);
|
||||
}
|
||||
}
|
||||
|
@ -1,28 +1,28 @@
|
||||
#!/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'){
|
||||
// remove all labels
|
||||
foreach($issue->labels as $label){
|
||||
$issue->removeLabel($label);
|
||||
foreach ($repo->getIssues(['q' => 'delete me']) as $issue) {
|
||||
// check for exact match
|
||||
if ('delete me' == $issue->title) {
|
||||
// remove all labels
|
||||
foreach ($issue->labels as $label) {
|
||||
$issue->removeLabel($label);
|
||||
}
|
||||
//change status and title.
|
||||
$issue->state = 'closed';
|
||||
$issue->title = 'deleted';
|
||||
$issue->save();
|
||||
}
|
||||
//change status and title.
|
||||
$issue->state='closed';
|
||||
$issue->title='deleted';
|
||||
$issue->save();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -1,24 +1,24 @@
|
||||
#!/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)
|
||||
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!'){
|
||||
// delete the commend
|
||||
$repo->deleteComment($comment);
|
||||
foreach ($repo->getIssues(['q' => 'NAG!']) as $issue) {
|
||||
// loop through the current issues comments
|
||||
foreach ($issue->getComments() as $comment) {
|
||||
// if the comment body matches
|
||||
if ('NAG!' == $comment->body) {
|
||||
// delete the commend
|
||||
$repo->deleteComment($comment);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
26
src/edit.php
26
src/edit.php
@ -1,30 +1,30 @@
|
||||
#!/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){
|
||||
return "\n```plain\n".$issue->number."\n".$issue->title."\ntexting\n".time()."\n```\n";
|
||||
$text = function ($issue) {
|
||||
return "\n```plain\n".$issue->number."\n".$issue->title."\ntexting\n".time()."\n```\n";
|
||||
};
|
||||
|
||||
//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 ){
|
||||
$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->save();
|
||||
$tmp = function ($issue) use ($text) {
|
||||
// add a tag to the body if to doesn't exist
|
||||
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->save();
|
||||
};
|
||||
|
||||
//process ALL issues
|
||||
|
@ -1,40 +1,50 @@
|
||||
#!/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");
|
||||
$nolabelLabel = $repo->getLabelByName('no-label');
|
||||
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");
|
||||
$nomilestoneLabel = $repo->getLabelByName('no-milestone');
|
||||
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) ){
|
||||
$issue->addLabel( $nolabelLabel );
|
||||
}elseif( $labelCount>0 && $issue->hasLabel($nolabelLabel) ){
|
||||
$issue->removeLabel( $nolabelLabel );
|
||||
}
|
||||
//do the no-milestone thing
|
||||
if( !$issue->milestone && !$issue->hasLabel($nomilestoneLabel) ){
|
||||
$issue->addLabel( $nomilestoneLabel );
|
||||
}elseif( $issue->milestone && $issue->hasLabel($nomilestoneLabel) ){
|
||||
$issue->removeLabel( $nomilestoneLabel );
|
||||
}
|
||||
$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 (0 == $labelCount && !$issue->hasLabel($nolabelLabel)) {
|
||||
$issue->addLabel($nolabelLabel);
|
||||
} elseif ($labelCount > 0 && $issue->hasLabel($nolabelLabel)) {
|
||||
$issue->removeLabel($nolabelLabel);
|
||||
}
|
||||
//do the no-milestone thing
|
||||
if (!$issue->milestone && !$issue->hasLabel($nomilestoneLabel)) {
|
||||
$issue->addLabel($nomilestoneLabel);
|
||||
} elseif ($issue->milestone && $issue->hasLabel($nomilestoneLabel)) {
|
||||
$issue->removeLabel($nomilestoneLabel);
|
||||
}
|
||||
};
|
||||
|
||||
//loop through all issues and call the callback
|
||||
|
@ -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){
|
||||
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]);
|
||||
|
||||
$client = new Client($config['url'], $config['user'], $config['pass'], $debug);
|
||||
$repo = $client->getRepo($argv[1], $argv[2]);
|
||||
|
14
src/test.php
14
src/test.php
@ -2,22 +2,22 @@
|
||||
<?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')){
|
||||
$label=$repo->createLabel(['name'=>'Test','color'=>'#336699']);
|
||||
if (!$label = $repo->getLabelByName('Test')) {
|
||||
$label = $repo->createLabel(['name' => 'Test', 'color' => '#336699']);
|
||||
}
|
||||
|
||||
//create a test issue
|
||||
$issue=$repo->createIssue([
|
||||
'title'=>'Test',
|
||||
'body'=>'Just testing'
|
||||
$issue = $repo->createIssue([
|
||||
'title' => 'Test',
|
||||
'body' => 'Just testing',
|
||||
]);
|
||||
$issue->addLabel($label);
|
||||
$issue->addComment('Test comment');
|
||||
$issue->save();
|
||||
|
||||
//change the issue body
|
||||
$issue->body.=' (Edited!)';
|
||||
$issue->body .= ' (Edited!)';
|
||||
$issue->save();
|
||||
|
@ -1,58 +1,59 @@
|
||||
#!/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
|
||||
foreach($repo->getIssues() as $issue){
|
||||
$issueNumbers[$issue->id]=$issue->number;
|
||||
foreach ($repo->getIssues() as $issue) {
|
||||
$issueNumbers[$issue->id] = $issue->number;
|
||||
}
|
||||
foreach($repo->getPulls() as $pull){
|
||||
$issue=$repo->getIssue($pull->number);
|
||||
$issueNumbers[$issue->id]=$issue->number;
|
||||
foreach ($repo->getPulls() as $pull) {
|
||||
$issue = $repo->getIssue($pull->number);
|
||||
$issueNumbers[$issue->id] = $issue->number;
|
||||
}
|
||||
foreach($repo->getIssues(['state'=>'closed']) as $issue){
|
||||
$issueNumbers[$issue->id]=$issue->number;
|
||||
foreach ($repo->getIssues(['state' => 'closed']) as $issue) {
|
||||
$issueNumbers[$issue->id] = $issue->number;
|
||||
}
|
||||
foreach($repo->getPulls(['state'=>'closed']) as $pull){
|
||||
$issue=$repo->getIssue($pull->number);
|
||||
$issueNumbers[$issue->id]=$issue->number;
|
||||
foreach ($repo->getPulls(['state' => 'closed']) as $pull) {
|
||||
$issue = $repo->getIssue($pull->number);
|
||||
$issueNumbers[$issue->id] = $issue->number;
|
||||
}
|
||||
$name='jhodges';
|
||||
$date='2019-10';
|
||||
$name = 'jhodges';
|
||||
$date = '2019-10';
|
||||
|
||||
$sums=[];
|
||||
foreach($repo->getTimesByUsername($name) as $time){
|
||||
if($date==date('Y-m',strtotime($time->created))){
|
||||
$number=$issueNumbers[$time->issue_id];
|
||||
if(!isset($sums[$number])){
|
||||
$issue=$repo->getIssue($number);
|
||||
$sums[$number]=[
|
||||
'id'=>$number,
|
||||
'name'=>$issue->title,
|
||||
'time'=>0
|
||||
];
|
||||
$sums = [];
|
||||
foreach ($repo->getTimesByUsername($name) as $time) {
|
||||
if ($date == date('Y-m', strtotime($time->created))) {
|
||||
$number = $issueNumbers[$time->issue_id];
|
||||
if (!isset($sums[$number])) {
|
||||
$issue = $repo->getIssue($number);
|
||||
$sums[$number] = [
|
||||
'id' => $number,
|
||||
'name' => $issue->title,
|
||||
'time' => 0,
|
||||
];
|
||||
}
|
||||
$sums[$number]['time'] += $time->time;
|
||||
}
|
||||
$sums[$number]['time']+=$time->time;
|
||||
}
|
||||
}
|
||||
|
||||
function format_time($t){
|
||||
return sprintf('%02d:%02d:%02d', floor($t/3600), ($t/60)%60, $t%60);
|
||||
function format_time($t)
|
||||
{
|
||||
return sprintf('%02d:%02d:%02d', floor($t / 3600), ($t / 60) % 60, $t % 60);
|
||||
}
|
||||
|
||||
$f=fopen('report.csv','w');
|
||||
fputcsv($f,['id','title','time']);
|
||||
foreach($sums as $id=>$data){
|
||||
$data['time']=format_time($data['time']);
|
||||
fputcsv($f,$data);
|
||||
$f = fopen('report.csv', 'w');
|
||||
fputcsv($f, ['id', 'title', 'time']);
|
||||
foreach ($sums as $id => $data) {
|
||||
$data['time'] = format_time($data['time']);
|
||||
fputcsv($f, $data);
|
||||
}
|
||||
fclose($f);
|
||||
echo "Saved as report.csv\n";
|
||||
|
Loading…
Reference in New Issue
Block a user