From d420b12bf8775f0368f2876c027f6285d89698a0 Mon Sep 17 00:00:00 2001 From: James Date: Sat, 7 Sep 2019 09:15:44 +0100 Subject: [PATCH] convert to using forIssues --- src/delete_me.php | 11 ++++++----- src/delete_nags.php | 22 ++++++++++++---------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/delete_me.php b/src/delete_me.php index e488be4..30353f7 100755 --- a/src/delete_me.php +++ b/src/delete_me.php @@ -11,17 +11,18 @@ // we will then have $client and $repo available require('setup.php'); -//callback function to process the issues -$tmp=function($issue) use ($repo){ +// 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(); } }; - -//do the search and process the results -$repo->forIssues($tmp,['q'=>'delete me']); diff --git a/src/delete_nags.php b/src/delete_nags.php index b31fe62..de0b2ca 100755 --- a/src/delete_nags.php +++ b/src/delete_nags.php @@ -1,22 +1,24 @@ #!/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); } } -}; - -//do the search and process the results -$repo->forIssues($tmp,['q'=>'NAG!']); +}