switch lib and more dev
This commit is contained in:
parent
4bb6a486bf
commit
d917a7c27c
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "jhodges/giteabot-examples",
|
"name": "jhodges/giteabot-repeat",
|
||||||
"description": "Some examples for the giteabot php api",
|
"description": "Support recurring issue on Gitea",
|
||||||
"authors": [
|
"authors": [
|
||||||
{
|
{
|
||||||
"name": "James",
|
"name": "James",
|
||||||
@ -9,7 +9,7 @@
|
|||||||
],
|
],
|
||||||
"require": {
|
"require": {
|
||||||
"jhodges/giteabot": "~1.2.0",
|
"jhodges/giteabot": "~1.2.0",
|
||||||
"tplaner/when": "^2.1"
|
"rlanvin/php-rrule": "^2.1"
|
||||||
},
|
},
|
||||||
"repositories": {
|
"repositories": {
|
||||||
"repo-name": {
|
"repo-name": {
|
||||||
|
50
composer.lock
generated
50
composer.lock
generated
@ -4,15 +4,16 @@
|
|||||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||||
"This file is @generated automatically"
|
"This file is @generated automatically"
|
||||||
],
|
],
|
||||||
"content-hash": "4f61690b1844d67af5e8aa461d9936b6",
|
"content-hash": "4c8a75e0d85a808b7861f77a853742b9",
|
||||||
"packages": [
|
"packages": [],
|
||||||
|
"packages-dev": [
|
||||||
{
|
{
|
||||||
"name": "jhodges/giteabot",
|
"name": "jhodges/giteabot",
|
||||||
"version": "v1.2.1",
|
"version": "v1.2.2",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://git.jhodges.co.uk/jhodges/GiteaBot",
|
"url": "https://git.jhodges.co.uk/jhodges/GiteaBot",
|
||||||
"reference": "a2c44392b2b4eede6be4b132e55e3479232fda93"
|
"reference": "aef0c2166ee9c3ac4f82c7c433b296f21d9865c7"
|
||||||
},
|
},
|
||||||
"type": "library",
|
"type": "library",
|
||||||
"autoload": {
|
"autoload": {
|
||||||
@ -30,56 +31,53 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"description": "Simple PHP library to interface with Gitea API",
|
"description": "Simple PHP library to interface with Gitea API",
|
||||||
"time": "2019-09-07T08:43:48+00:00"
|
"time": "2019-09-23T11:14:59+00:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "tplaner/when",
|
"name": "rlanvin/php-rrule",
|
||||||
"version": "2.1.0",
|
"version": "v2.1.0",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/tplaner/When.git",
|
"url": "https://github.com/rlanvin/php-rrule.git",
|
||||||
"reference": "91643472f8c8f23cab23bd38c1f43620475b01a0"
|
"reference": "c71d0f9251ba967b211ddab820c7012df6962b19"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/tplaner/When/zipball/91643472f8c8f23cab23bd38c1f43620475b01a0",
|
"url": "https://api.github.com/repos/rlanvin/php-rrule/zipball/c71d0f9251ba967b211ddab820c7012df6962b19",
|
||||||
"reference": "91643472f8c8f23cab23bd38c1f43620475b01a0",
|
"reference": "c71d0f9251ba967b211ddab820c7012df6962b19",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
"php": ">=5.3.0"
|
"php": ">=5.6.0"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"phpunit/phpunit": "~4.0"
|
"phpunit/phpunit": "^4.8|^5.5|^6.5"
|
||||||
|
},
|
||||||
|
"suggest": {
|
||||||
|
"ext-intl": "Intl extension is needed for humanReadable()"
|
||||||
},
|
},
|
||||||
"type": "library",
|
"type": "library",
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
"When\\": "src/"
|
"RRule\\": "src/"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"notification-url": "https://packagist.org/downloads/",
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
"license": [
|
"license": [
|
||||||
"MIT"
|
"MIT"
|
||||||
],
|
],
|
||||||
"authors": [
|
"description": "Lightweight and fast recurrence rules for PHP (RFC 5545)",
|
||||||
{
|
"homepage": "https://github.com/rlanvin/php-rrule",
|
||||||
"name": "Tom Planer",
|
|
||||||
"email": "tplaner@gmail.com"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"description": "Date/Calendar recursion library.",
|
|
||||||
"homepage": "https://github.com/tplaner/When",
|
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"date",
|
"date",
|
||||||
"datetime",
|
"ical",
|
||||||
"recurrence",
|
"recurrence",
|
||||||
"time"
|
"recurring",
|
||||||
|
"rrule"
|
||||||
],
|
],
|
||||||
"time": "2017-06-02T00:08:33+00:00"
|
"time": "2019-01-15T05:31:37+00:00"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"packages-dev": [],
|
|
||||||
"aliases": [],
|
"aliases": [],
|
||||||
"minimum-stability": "stable",
|
"minimum-stability": "stable",
|
||||||
"stability-flags": [],
|
"stability-flags": [],
|
||||||
|
@ -1,16 +0,0 @@
|
|||||||
#!/usr/bin/php
|
|
||||||
<?php
|
|
||||||
/******************
|
|
||||||
* close ALL issues
|
|
||||||
******************/
|
|
||||||
|
|
||||||
// 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');
|
|
||||||
|
|
||||||
// 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();
|
|
||||||
}
|
|
@ -1,27 +0,0 @@
|
|||||||
#!/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');
|
|
||||||
|
|
||||||
//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'
|
|
||||||
];
|
|
||||||
|
|
||||||
//loop through the names
|
|
||||||
foreach($names as $name){
|
|
||||||
//see if label exists?
|
|
||||||
$label=$repo->getLabelByName($name);
|
|
||||||
if($label){ //it exists
|
|
||||||
//delete it
|
|
||||||
$repo->deleteLabel($label);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,28 +0,0 @@
|
|||||||
#!/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');
|
|
||||||
|
|
||||||
// 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);
|
|
||||||
}
|
|
||||||
//change status and title.
|
|
||||||
$issue->state='closed';
|
|
||||||
$issue->title='deleted';
|
|
||||||
$issue->save();
|
|
||||||
}
|
|
||||||
};
|
|
@ -1,24 +0,0 @@
|
|||||||
#!/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');
|
|
||||||
|
|
||||||
// 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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
31
src/edit.php
31
src/edit.php
@ -1,31 +0,0 @@
|
|||||||
#!/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');
|
|
||||||
|
|
||||||
//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";
|
|
||||||
};
|
|
||||||
|
|
||||||
//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();
|
|
||||||
};
|
|
||||||
|
|
||||||
//process ALL issues
|
|
||||||
$repo->forIssues($tmp);
|
|
48
src/rrule.php
Executable file
48
src/rrule.php
Executable file
@ -0,0 +1,48 @@
|
|||||||
|
#!/usr/bin/php
|
||||||
|
<?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');
|
||||||
|
|
||||||
|
use RRule\RRule;
|
||||||
|
|
||||||
|
//callback function to add/replace the tag with our text
|
||||||
|
function updateIssueBody($issue,$text){
|
||||||
|
// add a tag to the body if to doesn't exist
|
||||||
|
if( strpos($issue->body,'<!--BOT-->')===false ){
|
||||||
|
$issue->body.="\n<!--BOT--><hr/><!--ENDBOT-->";
|
||||||
|
}
|
||||||
|
//replace the tag contents with the result from our $text function
|
||||||
|
$issue->body=preg_replace("#<!--BOT-->.*?<!--ENDBOT-->#s",'<!--BOT--><hr/>'.$text.'<!--ENDBOT-->',$issue->body);
|
||||||
|
};
|
||||||
|
|
||||||
|
foreach($repo->getIssues(['q'=>'RRULE:']) as $issue){
|
||||||
|
//echo "GOT: {$issue->number}\n";
|
||||||
|
if(preg_match('/RRULE:\s?(.*)/',$issue->body,$matches)){
|
||||||
|
$rruletxt=$matches[1];
|
||||||
|
//echo "RRULEtxt: ".$rruletxt."\n";
|
||||||
|
try{
|
||||||
|
$rrule = new RRule($rruletxt);
|
||||||
|
/*foreach ( $rrule as $occurrence ) {
|
||||||
|
echo $occurrence->format('D d M Y'),"\n ";
|
||||||
|
}*/
|
||||||
|
$result=$rrule->humanReadable()."<br/>\n NEXT1:".$rrule[0]->format('r')."<br/>\n NEXT2:".$rrule[1]->format('r');
|
||||||
|
updateIssueBody($issue,$result);
|
||||||
|
$issue->save();
|
||||||
|
//echo $rrule[0]->format('Y-m-d')." == ".date('Y-m-d')."\n";
|
||||||
|
}catch(Exception $e){
|
||||||
|
$result="\n```plain\n".$e->getMessage()." ($rruletxt)\n```\n";
|
||||||
|
updateIssueBody($issue,$result);
|
||||||
|
$issue->save();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if($rrule[0]->format('Y-m-d')==date('Y-m-d')){
|
||||||
|
$issue->addComment("Today (NEXT:".$rrule[1]->format('r').")");
|
||||||
|
}
|
||||||
|
|
||||||
|
updateIssueBody($issue,$result);
|
||||||
|
// not working https://github.com/go-gitea/gitea/issues/8179
|
||||||
|
//$issue->due_date=$rrule[0]->format('c');
|
||||||
|
$issue->save();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user