From d917a7c27cbeea5a8b3a26d20e19e6d55da76683 Mon Sep 17 00:00:00 2001 From: James Date: Sat, 28 Sep 2019 19:31:57 +0100 Subject: [PATCH] switch lib and more dev --- composer.json | 6 +++--- composer.lock | 50 +++++++++++++++++++++---------------------- src/close_all.php | 16 -------------- src/delete_labels.php | 27 ----------------------- src/delete_me.php | 28 ------------------------ src/delete_nags.php | 24 --------------------- src/edit.php | 31 --------------------------- src/rrule.php | 48 +++++++++++++++++++++++++++++++++++++++++ 8 files changed, 75 insertions(+), 155 deletions(-) delete mode 100755 src/close_all.php delete mode 100755 src/delete_labels.php delete mode 100755 src/delete_me.php delete mode 100755 src/delete_nags.php delete mode 100755 src/edit.php create mode 100755 src/rrule.php diff --git a/composer.json b/composer.json index 45f15a6..7cc7132 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { - "name": "jhodges/giteabot-examples", - "description": "Some examples for the giteabot php api", + "name": "jhodges/giteabot-repeat", + "description": "Support recurring issue on Gitea", "authors": [ { "name": "James", @@ -9,7 +9,7 @@ ], "require": { "jhodges/giteabot": "~1.2.0", - "tplaner/when": "^2.1" + "rlanvin/php-rrule": "^2.1" }, "repositories": { "repo-name": { diff --git a/composer.lock b/composer.lock index 3482e29..e5903f2 100644 --- a/composer.lock +++ b/composer.lock @@ -4,15 +4,16 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "4f61690b1844d67af5e8aa461d9936b6", - "packages": [ + "content-hash": "4c8a75e0d85a808b7861f77a853742b9", + "packages": [], + "packages-dev": [ { "name": "jhodges/giteabot", - "version": "v1.2.1", + "version": "v1.2.2", "source": { "type": "git", "url": "https://git.jhodges.co.uk/jhodges/GiteaBot", - "reference": "a2c44392b2b4eede6be4b132e55e3479232fda93" + "reference": "aef0c2166ee9c3ac4f82c7c433b296f21d9865c7" }, "type": "library", "autoload": { @@ -30,56 +31,53 @@ } ], "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", - "version": "2.1.0", + "name": "rlanvin/php-rrule", + "version": "v2.1.0", "source": { "type": "git", - "url": "https://github.com/tplaner/When.git", - "reference": "91643472f8c8f23cab23bd38c1f43620475b01a0" + "url": "https://github.com/rlanvin/php-rrule.git", + "reference": "c71d0f9251ba967b211ddab820c7012df6962b19" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/tplaner/When/zipball/91643472f8c8f23cab23bd38c1f43620475b01a0", - "reference": "91643472f8c8f23cab23bd38c1f43620475b01a0", + "url": "https://api.github.com/repos/rlanvin/php-rrule/zipball/c71d0f9251ba967b211ddab820c7012df6962b19", + "reference": "c71d0f9251ba967b211ddab820c7012df6962b19", "shasum": "" }, "require": { - "php": ">=5.3.0" + "php": ">=5.6.0" }, "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", "autoload": { "psr-4": { - "When\\": "src/" + "RRule\\": "src/" } }, "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], - "authors": [ - { - "name": "Tom Planer", - "email": "tplaner@gmail.com" - } - ], - "description": "Date/Calendar recursion library.", - "homepage": "https://github.com/tplaner/When", + "description": "Lightweight and fast recurrence rules for PHP (RFC 5545)", + "homepage": "https://github.com/rlanvin/php-rrule", "keywords": [ "date", - "datetime", + "ical", "recurrence", - "time" + "recurring", + "rrule" ], - "time": "2017-06-02T00:08:33+00:00" + "time": "2019-01-15T05:31:37+00:00" } ], - "packages-dev": [], "aliases": [], "minimum-stability": "stable", "stability-flags": [], diff --git a/src/close_all.php b/src/close_all.php deleted file mode 100755 index 9f22e76..0000000 --- a/src/close_all.php +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/php -getIssues() as $issue){ - $issue->state='closed'; - $issue->save(); -} diff --git a/src/delete_labels.php b/src/delete_labels.php deleted file mode 100755 index 3939b7e..0000000 --- a/src/delete_labels.php +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/php -getLabelByName($name); - if($label){ //it exists - //delete it - $repo->deleteLabel($label); - } -} diff --git a/src/delete_me.php b/src/delete_me.php deleted file mode 100755 index 38d6495..0000000 --- a/src/delete_me.php +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/php -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(); - } -}; diff --git a/src/delete_nags.php b/src/delete_nags.php deleted file mode 100755 index 0f15da6..0000000 --- a/src/delete_nags.php +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/php -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); - } - } -} diff --git a/src/edit.php b/src/edit.php deleted file mode 100755 index 67b802c..0000000 --- a/src/edit.php +++ /dev/null @@ -1,31 +0,0 @@ -#!/usr/bin/php -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,'')===false ){ - $issue->body.='
'; - } - //replace the tag contents with the result from our $text function - $issue->body=preg_replace("#.*?#s",''.$text($issue).'',$issue->body); - $issue->save(); -}; - -//process ALL issues -$repo->forIssues($tmp); diff --git a/src/rrule.php b/src/rrule.php new file mode 100755 index 0000000..a644bdf --- /dev/null +++ b/src/rrule.php @@ -0,0 +1,48 @@ +#!/usr/bin/php +body,'')===false ){ + $issue->body.="\n
"; + } + //replace the tag contents with the result from our $text function + $issue->body=preg_replace("#.*?#s",'
'.$text.'',$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()."
\n NEXT1:".$rrule[0]->format('r')."
\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(); + } +}