add some delete examples

This commit is contained in:
James 2019-09-05 17:33:13 +01:00
parent 24d5c44f3c
commit 32c31161ae
3 changed files with 76 additions and 0 deletions

27
src/delete_labels.php Executable file
View File

@ -0,0 +1,27 @@
#!/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);
}
}

27
src/delete_me.php Executable file
View File

@ -0,0 +1,27 @@
#!/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');
//callback function to process the issues
$tmp=function($issue) use ($repo){
if($issue->title=='delete me'){
foreach($issue->labels as $label){
$issue->removeLabel($label);
}
$issue->state='closed';
$issue->title='deleted';
$issue->save();
}
};
//do the search and process the results
$repo->forIssues($tmp,['q'=>'delete me']);

22
src/delete_nags.php Executable file
View File

@ -0,0 +1,22 @@
#!/bin/php
<?php
/*****************************************************
* This will process all issues that match "NAG!":
* 1. 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');
//callback function to process the issues
$tmp=function($issue) use ($repo){
foreach($issue->getComments() as $comment){
if($comment->body=='NAG!'){
$repo->deleteComment($comment);
}
}
};
//do the search and process the results
$repo->forIssues($tmp,['q'=>'NAG!']);